Patchwork [3,of,3,pure] mpatch: move collect() to module level

login
register
mail settings
Submitter Augie Fackler
Date March 19, 2016, 9:36 p.m.
Message ID <c0ae8d3cd37ac6e39612.1458423401@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/13965/
State Accepted
Headers show

Comments

Augie Fackler - March 19, 2016, 9:36 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1458420352 14400
#      Sat Mar 19 16:45:52 2016 -0400
# Node ID c0ae8d3cd37ac6e3961251e9814c80be4e37f053
# Parent  fb1ba6955cab21bce399133847c52514e3fc36b2
mpatch: move collect() to module level

This helps the code read a little more clearly.
Pierre-Yves David - March 19, 2016, 9:51 p.m.
On 03/19/2016 02:36 PM, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1458420352 14400
> #      Sat Mar 19 16:45:52 2016 -0400
> # Node ID c0ae8d3cd37ac6e3961251e9814c80be4e37f053
> # Parent  fb1ba6955cab21bce399133847c52514e3fc36b2
> mpatch: move collect() to module level

pushed to the clowncopter, thanks.

Patch

diff --git a/mercurial/pure/mpatch.py b/mercurial/pure/mpatch.py
--- a/mercurial/pure/mpatch.py
+++ b/mercurial/pure/mpatch.py
@@ -42,6 +42,13 @@  def _move(m, dest, src, count):
     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 @@  def patches(a, bins):
     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 @@  def patches(a, bins):
             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])