--- 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)