[PATCH] revlog, setup: Adds IronPython compatibility changes
Zachary Gramana
zgramana at pottsconsultinggroup.com
Thu May 5 10:50:37 CDT 2011
# HG changeset patch
# User Zachary Gramana <zgramana at pottsconsultinggroup.com>
# Date 1304609612 14400
# Node ID d096e2af7865730d8f93d123481991c777e6fd64
# Parent bedad898a28a3e6a25afff650a68e47c347ec1db
revlog, setup: Adds IronPython compatibility changes
diff -r bedad898a28a -r d096e2af7865 mercurial/revlog.py
--- a/mercurial/revlog.py Thu May 05 11:33:02 2011 -0400
+++ b/mercurial/revlog.py Thu May 05 11:33:32 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 bedad898a28a -r d096e2af7865 setup.py
--- a/setup.py Thu May 05 11:33:02 2011 -0400
+++ b/setup.py Thu May 05 11:33:32 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
More information about the Mercurial-devel
mailing list