Mercurial > public > mercurial-scm > hg-stable
diff mercurial/pure/bdiff.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 | 8b7973d40a01 |
children | 687b865b95ad |
line wrap: on
line diff
--- a/mercurial/pure/bdiff.py Sat Oct 05 10:29:34 2019 -0400 +++ b/mercurial/pure/bdiff.py Sun Oct 06 09:45:02 2019 -0400 @@ -11,6 +11,7 @@ import re import struct + def splitnewlines(text): '''like str.splitlines, but only split on newlines.''' lines = [l + '\n' for l in text.split('\n')] @@ -21,6 +22,7 @@ lines[-1] = lines[-1][:-1] return lines + def _normalizeblocks(a, b, blocks): prev = None r = [] @@ -38,18 +40,21 @@ a2end = a2 + l2 b2end = b2 + l2 if a1end == a2: - while (a1end + shift < a2end and - a[a1end + shift] == b[b1end + shift]): + while ( + a1end + shift < a2end and a[a1end + shift] == b[b1end + shift] + ): shift += 1 elif b1end == b2: - while (b1end + shift < b2end and - a[a1end + shift] == b[b1end + shift]): + while ( + b1end + shift < b2end and a[a1end + shift] == b[b1end + shift] + ): shift += 1 r.append((a1, b1, l1 + shift)) prev = a2 + shift, b2 + shift, l2 - shift r.append(prev) return r + def bdiff(a, b): a = bytes(a).splitlines(True) b = bytes(b).splitlines(True) @@ -76,6 +81,7 @@ return "".join(bin) + def blocks(a, b): an = splitnewlines(a) bn = splitnewlines(b) @@ -83,6 +89,7 @@ d = _normalizeblocks(an, bn, d) return [(i, i + n, j, j + n) for (i, j, n) in d] + def fixws(text, allws): if allws: text = re.sub('[ \t\r]+', '', text)