[PATCH 1 of 3 pure] mpatch: move pull() method to top level

Augie Fackler raf at durin42.com
Sat Mar 19 17:36:39 EDT 2016


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1458419850 14400
#      Sat Mar 19 16:37:30 2016 -0400
# Node ID 28764daf77e94e0dd10a1ade7a7d29b2473bcdf0
# Parent  82cee85d5274f5ce63a74c9cb157ab2592bab332
mpatch: move pull() method to top level

There was no need for this to be nested.

diff --git a/mercurial/pure/mpatch.py b/mercurial/pure/mpatch.py
--- a/mercurial/pure/mpatch.py
+++ b/mercurial/pure/mpatch.py
@@ -22,6 +22,16 @@ StringIO = cStringIO.StringIO
 # mmap and simply use memmove. This avoids creating a bunch of large
 # temporary string buffers.
 
+def _pull(dst, src, l): # pull l bytes from src
+    while l:
+        f = src.pop()
+        if f[0] > l: # do we need to split?
+            src.append((f[0] - l, f[1] + l))
+            dst.append((l, f[1]))
+            return
+        dst.append(f)
+        l -= f[0]
+
 def patches(a, bins):
     if not bins:
         return a
@@ -55,16 +65,6 @@ def patches(a, bins):
     m.seek(pos)
     for p in bins: m.write(p)
 
-    def pull(dst, src, l): # pull l bytes from src
-        while l:
-            f = src.pop()
-            if f[0] > l: # do we need to split?
-                src.append((f[0] - l, f[1] + l))
-                dst.append((l, f[1]))
-                return
-            dst.append(f)
-            l -= f[0]
-
     def collect(buf, list):
         start = buf
         for l, p in reversed(list):
@@ -84,8 +84,8 @@ def patches(a, bins):
         while pos < end:
             m.seek(pos)
             p1, p2, l = struct.unpack(">lll", m.read(12))
-            pull(new, frags, p1 - last) # what didn't change
-            pull([], frags, p2 - p1)    # what got deleted
+            _pull(new, frags, p1 - last) # what didn't change
+            _pull([], frags, p2 - p1)    # what got deleted
             new.append((l, pos + 12))   # what got added
             pos += l + 12
             last = p2


More information about the Mercurial-devel mailing list