changeset 28588:6546afde350e

mpatch: un-nest the move() method This helps the code read a little more clearly.
author Augie Fackler <augie@google.com>
date Sat, 19 Mar 2016 16:43:16 -0400
parents 76d7cab13f04
children c4c7be9f0554
files mercurial/pure/mpatch.py
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pure/mpatch.py	Sat Mar 19 16:37:30 2016 -0400
+++ b/mercurial/pure/mpatch.py	Sat Mar 19 16:43:16 2016 -0400
@@ -32,6 +32,16 @@
         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 @@
         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 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)