mpatch: move pull() method to top level
authorAugie Fackler <augie@google.com>
Sat, 19 Mar 2016 16:37:30 -0400
changeset 28587 76d7cab13f04
parent 28586 82cee85d5274
child 28588 6546afde350e
mpatch: move pull() method to top level There was no need for this to be nested.
mercurial/pure/mpatch.py
--- a/mercurial/pure/mpatch.py	Thu Mar 17 18:27:48 2016 +0000
+++ b/mercurial/pure/mpatch.py	Sat Mar 19 16:37:30 2016 -0400
@@ -22,6 +22,16 @@
 # 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 @@
     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 @@
         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