# HG changeset patch # User Matt Mackall # Date 2011-12-15 21:27:11 # Node ID d976b1ef67602c0e2d81a30595d98e13eb4e7da2 # Parent 4f5a78fa4917bbeaecdab35eb6b19f49243d70a2 util: don't mess with builtins to emulate buffer() diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. from i18n import _ -import mdiff, parsers, error, revlog +import mdiff, parsers, error, revlog, util import array, struct class manifestdict(dict): @@ -164,7 +164,7 @@ class manifest(revlog.revlog): dline = [""] start = 0 # zero copy representation of addlist as a buffer - addbuf = buffer(addlist) + addbuf = util.buffer(addlist) # start with a readonly loop that finds the offset of # each line and creates the deltas @@ -196,7 +196,7 @@ class manifest(revlog.revlog): # apply the delta to the addlist, and get a delta for addrevision cachedelta = (self.rev(p1), addlistdelta(addlist, delta)) arraytext = addlist - text = buffer(arraytext) + text = util.buffer(arraytext) n = self.addrevision(text, transaction, link, p1, p2, cachedelta) self._mancache = (n, map, arraytext) diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -318,7 +318,7 @@ def patchtext(bin): def patch(a, bin): if len(a) == 0: # skip over trivial delta header - return buffer(bin, 12) + return util.buffer(bin, 12) return mpatch.patches(a, [bin]) # similar to difflib.SequenceMatcher.get_matching_blocks diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -104,18 +104,15 @@ def _fastsha1(s=''): _fastsha1 = sha1 = _sha1 return _sha1(s) -import __builtin__ - -if sys.version_info[0] < 3: - def fakebuffer(sliceable, offset=0): - return sliceable[offset:] -else: - def fakebuffer(sliceable, offset=0): - return memoryview(sliceable)[offset:] try: - buffer + buffer = buffer except NameError: - __builtin__.buffer = fakebuffer + if sys.version_info[0] < 3: + def buffer(sliceable, offset=0): + return sliceable[offset:] + else: + def buffer(sliceable, offset=0): + return memoryview(sliceable)[offset:] import subprocess closefds = os.name == 'posix'