[PATCH] changelog revlog setup: IronPython compatibility fixes.

Matt Mackall mpm at selenic.com
Wed May 4 23:08:18 CDT 2011


On Wed, 2011-05-04 at 19:14 -0500, Zachary Gramana wrote:
> # 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). 

The whitespace in your patch is hopeless mangled, please try the email
extension.

> 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 

This needs to be made IronPython-specific somehow. You're probably best
off forcing fakebuffer in util.py.

> 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).") 

The default bundle format is bz2, so this will be a problem for bundle
users.

> -import os, subprocess, time 
> +import subprocess, time 
> import shutil 
> import tempfile 
> from distutils import log 
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list