From 5fba72f1a396f02071ffc3ac1263aad631b6d373 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 23 Oct 2026 16:02:29 +0200 Subject: [PATCH] fix: map a file edited line for line as changed --- scripts/profile_sync.py | 9 ++++++++- tests/test_profile_sync.py | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index cfdcc9bb..a830d3f5 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -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)) diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index c51a899e..96f7282d 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -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")