mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-25 13:19:03 -05:00
fix: map a file edited line for line as changed
This commit is contained in:
1 parent
42dfc87e24
commit
5fba72f1a3
2 files changed
+16
-1
No files matched your search
@@ -524,7 +524,14 @@ def _map_changed(pin: list[str], head: list[str], lo: int, hi: int) -> AnchorRes
|
||||
"CHANGED", None, None, [], f"file over {MAX_MATCH_LINES} lines"
|
||||
)
|
||||
opcodes = _opcodes(pin, head)
|
||||
if not any(tag == "equal" for tag, *_ in opcodes):
|
||||
# A file whose every line was edited in place keeps no equal block, yet
|
||||
# its lines still map one to one: fheroes2 version.txt holds one line,
|
||||
# 1.0.11 at the pin and 1.1.17 at HEAD, and read GONE.
|
||||
rewritten_in_place = len(opcodes) == 1 and (
|
||||
opcodes[0][0] == "replace"
|
||||
and opcodes[0][2] - opcodes[0][1] == opcodes[0][4] - opcodes[0][3]
|
||||
)
|
||||
if not rewritten_in_place and not any(tag == "equal" for tag, *_ in opcodes):
|
||||
return AnchorResult("GONE", None, None, [])
|
||||
new_lo = _map_index(opcodes, lo)
|
||||
new_hi = _map_index(opcodes, max(lo, hi - 1))
|
||||
|
||||
@@ -387,6 +387,14 @@ class TestAnchorBlock(unittest.TestCase):
|
||||
self.assertEqual(result.status, "CHANGED")
|
||||
self.assertEqual(result.start, line)
|
||||
|
||||
def test_a_file_rewritten_line_for_line_is_changed_not_gone(self):
|
||||
# fheroes2 version.txt:1 went from 1.0.11 to 1.1.17. With no
|
||||
# unchanged line left the file read GONE and held the whole recale.
|
||||
result = anchor_block(["1.0.11"], ["1.1.17"], 1, 1)
|
||||
self.assertEqual((result.status, result.start, result.end), ("CHANGED", 1, 1))
|
||||
result = anchor_block(["a = 1", "b = 2"], ["a = 3", "b = 4"], 2, 2)
|
||||
self.assertEqual((result.status, result.start), ("CHANGED", 2))
|
||||
|
||||
def test_gone_when_content_vanished(self):
|
||||
result = anchor_block(["a", "unique marker", "b"], ["x"] * 200, 2, 2)
|
||||
self.assertEqual(result.status, "GONE")
|
||||
|
||||
Reference in new issue
Block a user