Mercurial > public > mercurial-scm > hg
comparison mercurial/mdiff.py @ 51931:77e2994bd617
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.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 30 Sep 2024 23:50:40 -0400 |
parents | 09f3a6790e56 |
children | c6899b334d56 |
comparison
equal
deleted
inserted
replaced
51930:09f3a6790e56 | 51931:77e2994bd617 |
---|---|
138 else: | 138 else: |
139 # Consume the matching lines | 139 # Consume the matching lines |
140 while i1 < e1 and lines1[i1] == 1 and lines2[i2] == 1: | 140 while i1 < e1 and lines1[i1] == 1 and lines2[i2] == 1: |
141 i1 += 1 | 141 i1 += 1 |
142 i2 += 1 | 142 i2 += 1 |
143 yield [base1 + s1, base1 + i1, base2 + s2, base2 + i2], btype | 143 yield (base1 + s1, base1 + i1, base2 + s2, base2 + i2), btype |
144 s1 = i1 | 144 s1 = i1 |
145 s2 = i2 | 145 s2 = i2 |
146 | 146 |
147 | 147 |
148 def hunkinrange(hunk, linerange): | 148 def hunkinrange(hunk, linerange): |
242 # in the file. If it starts later, old and new below will both be | 242 # in the file. If it starts later, old and new below will both be |
243 # empty and we'll continue to the next match. | 243 # empty and we'll continue to the next match. |
244 if i > 0: | 244 if i > 0: |
245 s = diff[i - 1] | 245 s = diff[i - 1] |
246 else: | 246 else: |
247 s = [0, 0, 0, 0] | 247 s = (0, 0, 0, 0) |
248 s = [s[1], s1[0], s[3], s1[2]] | 248 s = (s[1], s1[0], s[3], s1[2]) |
249 | 249 |
250 # bdiff sometimes gives huge matches past eof, this check eats them, | 250 # bdiff sometimes gives huge matches past eof, this check eats them, |
251 # and deals with the special first match case described above | 251 # and deals with the special first match case described above |
252 if s[0] != s[1] or s[2] != s[3]: | 252 if s[0] != s[1] or s[2] != s[3]: |
253 type = b'!' | 253 type = b'!' |
473 yield True | 473 yield True |
474 for x in yieldhunk(hunk): | 474 for x in yieldhunk(hunk): |
475 yield x | 475 yield x |
476 if prev: | 476 if prev: |
477 # we've joined the previous hunk, record the new ending points. | 477 # we've joined the previous hunk, record the new ending points. |
478 hunk[1] = a2 | 478 hunk = (hunk[0], a2, hunk[2], b2, hunk[4]) |
479 hunk[3] = b2 | |
480 delta = hunk[4] | 479 delta = hunk[4] |
481 else: | 480 else: |
482 # create a new hunk | 481 # create a new hunk |
483 hunk = [astart, a2, bstart, b2, delta] | 482 hunk = (astart, a2, bstart, b2, delta) |
484 | 483 |
485 delta[len(delta) :] = [b' ' + x for x in l1[astart:a1]] | 484 delta[len(delta) :] = [b' ' + x for x in l1[astart:a1]] |
486 delta[len(delta) :] = [b'-' + x for x in old] | 485 delta[len(delta) :] = [b'-' + x for x in old] |
487 delta[len(delta) :] = [b'+' + x for x in new] | 486 delta[len(delta) :] = [b'+' + x for x in new] |
488 | 487 |