From adea35e12a225d790de628107c1abe225cde60c9 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 20 Oct 2026 05:46:09 +0200 Subject: [PATCH] fix: a recale keeps the repository word of a ref A source_ref written as `stella src/a.c:120` names the repository its lines are in. The path is read without the word, and --rebase-refs wrote the new span back without it, losing the attribution. --- scripts/profile_sync.py | 6 ++++++ tests/test_profile_sync.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index 60db294e..b857f8fe 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -1996,6 +1996,12 @@ def _rendered_part(part: PartResult) -> str: if not raw: return span located = _trim_prose(_ANNOTATION_RE.sub("", raw).strip()) + # `stella src/emucore/Cart.cxx:120` names the repository the lines are + # in. The path was read without that word, and a recale wrote it back + # without it: the attribution went with the old line numbers. + word, _, rest = located.partition(" ") + if rest.startswith(f"{part.part.path}:") and word and "/" not in word: + span = f"{word} {span}" if located and located in raw: return raw.replace(located, span, 1) return span diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index bb1d82a8..79eaf67d 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -4268,5 +4268,25 @@ class AnOffForgeProfileWatchesItsReleasePage(unittest.TestCase): self.assertEqual(profile_sync.page_version(profile, "cache", False), "4.50") +class ARecaleKeepsTheRepositoryWord(unittest.TestCase): + """`stella src/a.c:120` says the lines are in the stella repository. The + path is read without the word, and a recale wrote it back without it.""" + + def test_the_word_stays_in_front_of_the_new_span(self): + from sourceref import split_source_ref + + for raw, expected in ( + ("stella src/a.c:120-130", "stella src/a.c:140-150"), + ("stella src/a.c:120 (the table)", "stella src/a.c:140-150 (the table)"), + ("src/a.c:120", "src/a.c:140-150"), + ): + with self.subTest(raw=raw): + p = split_source_ref(raw)[0] + part = profile_sync.RefPart( + profile_sync.strip_repo_word(p.path, {"stella"}), p.start, p.end, p.raw) + result = profile_sync.PartResult(part, "SHIFTED", None, 140, 150, [], "") + self.assertEqual(profile_sync._rendered_part(result), expected) + + if __name__ == "__main__": unittest.main()