mdiff: convert a few block definitions from lists to tuples
These were flagged by adding type hints. Some places were using a tuple of 4
ints to define a block, and others were using a list of 4. A tuple is better
for typing, because we can define the length and the type of each entry. One of
the places had to redefine the tuple, since writing to a tuple at an index isn't
supported.
This change spills out into the tests, and archeology says it was added to the
repo in this state. There was no reason given for the divergence, and I suspect
it wasn't intentional.
It looks like `splitblock()` is completely unused in the codebase.
--- a/mercurial/mdiff.py Sun Sep 29 02:03:20 2024 -0400
+++ b/mercurial/mdiff.py Mon Sep 30 23:50:40 2024 -0400
@@ -140,7 +140,7 @@
while i1 < e1 and lines1[i1] == 1 and lines2[i2] == 1:
i1 += 1
i2 += 1
- yield [base1 + s1, base1 + i1, base2 + s2, base2 + i2], btype
+ yield (base1 + s1, base1 + i1, base2 + s2, base2 + i2), btype
s1 = i1
s2 = i2
@@ -244,8 +244,8 @@
if i > 0:
s = diff[i - 1]
else:
- s = [0, 0, 0, 0]
- s = [s[1], s1[0], s[3], s1[2]]
+ s = (0, 0, 0, 0)
+ s = (s[1], s1[0], s[3], s1[2])
# bdiff sometimes gives huge matches past eof, this check eats them,
# and deals with the special first match case described above
@@ -475,12 +475,11 @@
yield x
if prev:
# we've joined the previous hunk, record the new ending points.
- hunk[1] = a2
- hunk[3] = b2
+ hunk = (hunk[0], a2, hunk[2], b2, hunk[4])
delta = hunk[4]
else:
# create a new hunk
- hunk = [astart, a2, bstart, b2, delta]
+ hunk = (astart, a2, bstart, b2, delta)
delta[len(delta) :] = [b' ' + x for x in l1[astart:a1]]
delta[len(delta) :] = [b'-' + x for x in old]
--- a/tests/test-linerange.py Sun Sep 29 02:03:20 2024 -0400
+++ b/tests/test-linerange.py Mon Sep 30 23:50:40 2024 -0400
@@ -51,9 +51,9 @@
def setUp(self):
self.blocks = list(mdiff.allblocks(text1, text2))
assert self.blocks == [
- ([0, 3, 0, 2], b'!'),
+ ((0, 3, 0, 2), b'!'),
((3, 7, 2, 6), b'='),
- ([7, 12, 6, 12], b'!'),
+ ((7, 12, 6, 12), b'!'),
((12, 12, 12, 12), b'='),
], self.blocks