[PATCH] changelog revlog setup: IronPython compatibility fixes.

Zachary Gramana zgramana at pottsconsultinggroup.com
Wed May 4 19:14:27 CDT 2011


# HG changeset patch 
# User Zachary J. Gramana <zgramana at pottsconsultinggroup.com> 
# Date 1304553831 14400 
# Node ID a96a0b69cba96a58d9e1de5bd8edf1369b07675d 
# Parent 333def42e785fddda47dd097c0648abb105e399a 
changelog revlog setup: IronPython compatibility fixes. 

Adds additional compatibility for with building a pure version on IronPython. 
Also fixes a remaining leaked file handle which prevented successful cloning 
on IronPython (and possibly PyPy/Jython as well). 

diff -r 333def42e785 -r a96a0b69cba9 mercurial/changelog.py 
--- a/mercurial/changelog.py Wed May 04 08:21:50 2011 -0500 
+++ b/mercurial/changelog.py Wed May 04 20:03:51 2011 -0400 
@@ -118,7 +118,9 @@ 
self.opener = self._realopener 
# move redirected index data back into place 
if self._divert: 
- n = self.opener(self.indexfile + ".a").name 
+ nfile = self.opener(self.indexfile + ".a") 
+ n = nfile.name 
+ nfile.close() 
util.rename(n, n[:-2]) 
elif self._delaybuf: 
fp = self.opener(self.indexfile, 'a') 
diff -r 333def42e785 -r a96a0b69cba9 mercurial/revlog.py 
--- a/mercurial/revlog.py Wed May 04 08:21:50 2011 -0500 
+++ b/mercurial/revlog.py Wed May 04 20:03:51 2011 -0400 
@@ -54,6 +54,18 @@ 
def offset_type(offset, type): 
return long(long(offset) << 16 | type) 

+def ensurestr(text): 
+ """take either a buffer of a string, and return a string. 
+ 
+ IronPython treats all strings as unicode strings. Large 
+ strings are passed as buffers. Currently, _sha.update and 
+ zlib.compress don't like buffers, so we ensure they get strings. 
+ """ 
+ if type(text) == buffer: 
+ return str(text) 
+ else: 
+ return text 
+ 
nullhash = _sha(nullid) 

def hash(text, p1, p2): 
@@ -73,8 +85,8 @@ 
l = [p1, p2] 
l.sort() 
s = _sha(l[0]) 
- s.update(l[1]) 
- s.update(text) 
+ s.update(ensurestr(l[1])) 
+ s.update(ensurestr(text)) 
return s.digest() 

def compress(text): 
@@ -99,7 +111,7 @@ 
if sum(map(len, p)) < l: 
bin = "".join(p) 
else: 
- bin = _compress(text) 
+ bin = _compress(ensurestr(text)) 
if bin is None or len(bin) > l: 
if text[0] == '\0': 
return ("", text) 
diff -r 333def42e785 -r a96a0b69cba9 setup.py 
--- a/setup.py Wed May 04 08:21:50 2011 -0500 
+++ b/setup.py Wed May 04 20:03:51 2011 -0400 
@@ -4,7 +4,7 @@ 
# 'python setup.py install', or 
# 'python setup.py --help' for more options 

-import sys 
+import sys, os 
if not hasattr(sys, 'version_info') or sys.version_info < (2, 4, 0, 'final'): 
raise SystemExit("Mercurial requires Python 2.4 or later.") 

@@ -36,13 +36,22 @@ 
raise SystemExit( 
"Couldn't import standard zlib (incomplete Python install).") 

+# The base IronPython distribution (as of 2.7.1) doesn't support bz2 
try: 
- import bz2 
+ isIronPython = os.path.split(sys.executable)[1] == "ipy.exe" 
except: 
- raise SystemExit( 
- "Couldn't import standard bz2 (incomplete Python install).") 
+ pass 
+else: 
+ if isIronPython: 
+ print "(IronPython detected. Skipping bz2 import.)" 
+ else: 
+ try: 
+ import bz2 
+ except: 
+ raise SystemExit( 
+ "Couldn't import standard bz2 (incomplete Python install).") 

-import os, subprocess, time 
+import subprocess, time 
import shutil 
import tempfile 
from distutils import log 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110504/2c2b4361/attachment.htm>


More information about the Mercurial-devel mailing list