Mercurial > hg
comparison mercurial/pure/bdiff.py @ 45863:68aedad4c11c
pure: guard against empty blocks
If blocks is empty, we append `None` to the returned list, which is
incorrect.
This subtle issue was caught by pytype, which correctly identified
the return value as List[Optional[Tuple]] because of this possibility.
Differential Revision: https://phab.mercurial-scm.org/D9279
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 07 Nov 2020 16:45:58 -0800 |
parents | 687b865b95ad |
children | d4ba4d51f85f |
comparison
equal
deleted
inserted
replaced
45862:5c736ba5dc27 | 45863:68aedad4c11c |
---|---|
49 b1end + shift < b2end and a[a1end + shift] == b[b1end + shift] | 49 b1end + shift < b2end and a[a1end + shift] == b[b1end + shift] |
50 ): | 50 ): |
51 shift += 1 | 51 shift += 1 |
52 r.append((a1, b1, l1 + shift)) | 52 r.append((a1, b1, l1 + shift)) |
53 prev = a2 + shift, b2 + shift, l2 - shift | 53 prev = a2 + shift, b2 + shift, l2 - shift |
54 r.append(prev) | 54 |
55 if prev is not None: | |
56 r.append(prev) | |
57 | |
55 return r | 58 return r |
56 | 59 |
57 | 60 |
58 def bdiff(a, b): | 61 def bdiff(a, b): |
59 a = bytes(a).splitlines(True) | 62 a = bytes(a).splitlines(True) |