[PATCH 2 of 3 pure] mpatch: un-nest the move() method

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


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1458420196 14400
#      Sat Mar 19 16:43:16 2016 -0400
# Node ID fb1ba6955cab21bce399133847c52514e3fc36b2
# Parent  28764daf77e94e0dd10a1ade7a7d29b2473bcdf0
mpatch: un-nest the move() method

This helps the code read a little more clearly.

diff --git a/mercurial/pure/mpatch.py b/mercurial/pure/mpatch.py
--- a/mercurial/pure/mpatch.py
+++ b/mercurial/pure/mpatch.py
@@ -32,6 +32,16 @@ def _pull(dst, src, l): # pull l bytes f
         dst.append(f)
         l -= f[0]
 
+def _move(m, dest, src, count):
+    """move count bytes from src to dest
+
+    The file pointer is left at the end of dest.
+    """
+    m.seek(src)
+    buf = m.read(count)
+    m.seek(dest)
+    m.write(buf)
+
 def patches(a, bins):
     if not bins:
         return a
@@ -46,15 +56,6 @@ def patches(a, bins):
         return a
 
     m = StringIO()
-    def move(dest, src, count):
-        """move count bytes from src to dest
-
-        The file pointer is left at the end of dest.
-        """
-        m.seek(src)
-        buf = m.read(count)
-        m.seek(dest)
-        m.write(buf)
 
     # load our original text
     m.write(a)
@@ -68,7 +69,7 @@ def patches(a, bins):
     def collect(buf, list):
         start = buf
         for l, p in reversed(list):
-            move(buf, p, l)
+            _move(m, buf, p, l)
             buf += l
         return (buf - start, start)
 


More information about the Mercurial-devel mailing list