# HG changeset patch # User Matt Mackall # Date 1323984431 21600 # Node ID d976b1ef67602c0e2d81a30595d98e13eb4e7da2 # Parent 4f5a78fa4917bbeaecdab35eb6b19f49243d70a2 util: don't mess with builtins to emulate buffer() diff -r 4f5a78fa4917 -r d976b1ef6760 mercurial/manifest.py --- a/mercurial/manifest.py Thu Dec 15 14:59:22 2011 -0600 +++ b/mercurial/manifest.py Thu Dec 15 15:27:11 2011 -0600 @@ -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 @@ 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 @@ # 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 -r 4f5a78fa4917 -r d976b1ef6760 mercurial/mdiff.py --- a/mercurial/mdiff.py Thu Dec 15 14:59:22 2011 -0600 +++ b/mercurial/mdiff.py Thu Dec 15 15:27:11 2011 -0600 @@ -318,7 +318,7 @@ 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 -r 4f5a78fa4917 -r d976b1ef6760 mercurial/util.py --- a/mercurial/util.py Thu Dec 15 14:59:22 2011 -0600 +++ b/mercurial/util.py Thu Dec 15 15:27:11 2011 -0600 @@ -104,18 +104,15 @@ _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'