From patchwork Sat Mar 19 21:36:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,3,pure] mpatch: un-nest the move() method From: Augie Fackler X-Patchwork-Id: 13964 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Sat, 19 Mar 2016 17:36:40 -0400 # HG changeset patch # User Augie Fackler # 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)