Mercurial > public > mercurial-scm > hg
diff mercurial/pure/mpatch.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 644a02f6b34f |
children | 687b865b95ad |
line wrap: on
line diff
--- a/mercurial/pure/mpatch.py Sat Oct 05 10:29:34 2019 -0400 +++ b/mercurial/pure/mpatch.py Sun Oct 06 09:45:02 2019 -0400 @@ -10,12 +10,15 @@ import struct from .. import pycompat + stringio = pycompat.bytesio + class mpatchError(Exception): """error raised when a delta cannot be decoded """ + # This attempts to apply a series of patches in time proportional to # the total size of the patches, rather than patches * len(text). This # means rather than shuffling strings around, we shuffle around @@ -26,16 +29,18 @@ # mmap and simply use memmove. This avoids creating a bunch of large # temporary string buffers. -def _pull(dst, src, l): # pull l bytes from src + +def _pull(dst, src, l): # pull l bytes from src while l: f = src.pop() - if f[0] > l: # do we need to split? + if f[0] > l: # do we need to split? src.append((f[0] - l, f[1] + l)) dst.append((l, f[1])) return dst.append(f) l -= f[0] + def _move(m, dest, src, count): """move count bytes from src to dest @@ -46,6 +51,7 @@ m.seek(dest) m.write(buf) + def _collect(m, buf, list): start = buf for l, p in reversed(list): @@ -53,6 +59,7 @@ buf += l return (buf - start, start) + def patches(a, bins): if not bins: return a @@ -60,7 +67,7 @@ plens = [len(x) for x in bins] pl = sum(plens) bl = len(a) + pl - tl = bl + bl + pl # enough for the patches and two working texts + tl = bl + bl + pl # enough for the patches and two working texts b1, b2 = 0, bl if not tl: @@ -93,25 +100,26 @@ p1, p2, l = struct.unpack(">lll", m.read(12)) except struct.error: raise mpatchError("patch cannot be decoded") - _pull(new, frags, p1 - last) # what didn't change - _pull([], frags, p2 - p1) # what got deleted - new.append((l, pos + 12)) # what got added + _pull(new, frags, p1 - last) # what didn't change + _pull([], frags, p2 - p1) # what got deleted + new.append((l, pos + 12)) # what got added pos += l + 12 last = p2 - frags.extend(reversed(new)) # what was left at the end + frags.extend(reversed(new)) # what was left at the end t = _collect(m, b2, frags) m.seek(t[1]) return m.read(t[0]) + def patchedsize(orig, delta): outlen, last, bin = 0, 0, 0 binend = len(delta) data = 12 while data <= binend: - decode = delta[bin:bin + 12] + decode = delta[bin : bin + 12] start, end, length = struct.unpack(">lll", decode) if start > end: break