mpatch: move collect() to module level
authorAugie Fackler <augie@google.com>
Sat, 19 Mar 2016 16:45:52 -0400
changeset 28589 c4c7be9f0554
parent 28588 6546afde350e
child 28590 b0b9f6b0a777
mpatch: move collect() to module level This helps the code read a little more clearly.
mercurial/pure/mpatch.py
--- a/mercurial/pure/mpatch.py	Sat Mar 19 16:43:16 2016 -0400
+++ b/mercurial/pure/mpatch.py	Sat Mar 19 16:45:52 2016 -0400
@@ -42,6 +42,13 @@
     m.seek(dest)
     m.write(buf)
 
+def _collect(m, buf, list):
+    start = buf
+    for l, p in reversed(list):
+        _move(m, buf, p, l)
+        buf += l
+    return (buf - start, start)
+
 def patches(a, bins):
     if not bins:
         return a
@@ -66,18 +73,11 @@
     m.seek(pos)
     for p in bins: m.write(p)
 
-    def collect(buf, list):
-        start = buf
-        for l, p in reversed(list):
-            _move(m, buf, p, l)
-            buf += l
-        return (buf - start, start)
-
     for plen in plens:
         # if our list gets too long, execute it
         if len(frags) > 128:
             b2, b1 = b1, b2
-            frags = [collect(b1, frags)]
+            frags = [_collect(m, b1, frags)]
 
         new = []
         end = pos + plen
@@ -92,7 +92,7 @@
             last = p2
         frags.extend(reversed(new))     # what was left at the end
 
-    t = collect(b2, frags)
+    t = _collect(m, b2, frags)
 
     m.seek(t[1])
     return m.read(t[0])