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

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

Comments

Augie Fackler - March 19, 2016, 9:36 p.m.
# HG changeset patch
# User Augie Fackler <augie@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.

Patch

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)