From 4521edca5965b2ce7cdf9b054e9a4758e81e5f95 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:33:11 +0200 Subject: [PATCH] fix: name every pin a bump changes --- scripts/profile_sync.py | 20 +++++++++++++++----- tests/test_profile_sync.py | 22 ++++++++++++++++++++++ wiki/tools.md | 3 ++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index fa610a97..dd9587d2 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -2885,6 +2885,14 @@ def bump_commit( return True +def pins_changed(before: dict, after: dict) -> list[str]: + """The pin fields whose value a write changed.""" + return [ + pin for pin in ("source_commit", "upstream_commit") + if after.get(pin) and after.get(pin) != before.get(pin) + ] + + def cites_primary(report: ProfileReport) -> bool: """Whether a ref resolved in the repository source_commit pins. @@ -3480,10 +3488,7 @@ def _apply_writes( # refs at the old pin and saw them shifted again. target = Path(scratch) / path.name target.write_bytes(path.read_bytes()) - recale, bumped = ( - ("would recale ", "would set source_commit ->") if args.dry_run - else ("", "source_commit ->") - ) + recale, bumped = ("would recale ", "would set ") if args.dry_run else ("", "") applied = [] if args.rebase_refs and not report.skipped: applied = rebase_refs(target, report, args.accept_changed) @@ -3498,7 +3503,12 @@ def _apply_writes( for line in applied: print(f"{name}: {recale}{line}") if moved: - print(f"{name}: {bumped} {report.head[:7]}") + # Each pin the write changes, as written: a bump that only moved + # upstream_commit announced the source_commit it already held. + after = yaml.safe_load(target.read_text(encoding="utf-8")) or {} + before = yaml.safe_load(path.read_text(encoding="utf-8")) or {} + for pin in pins_changed(before, after): + print(f"{name}: {bumped}{pin} -> {str(after[pin])[:7]}") if not args.dry_run and (applied or moved): path.write_bytes(target.read_bytes()) diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index a76ab851..cc9828d7 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -2494,6 +2494,28 @@ class TestWriteDryRun(unittest.TestCase): self.assertIn("would set source_commit -> newhead", output) self.assertEqual(self.path.read_text(), before) + def test_a_bump_that_moves_only_upstream_says_so(self): + """rustation: source_commit already at HEAD, the write added + upstream_commit, and the dry run announced the source_commit it + already held.""" + self.path.write_text( + self.path.read_text().replace( + 'profiled_date: "2026-03-29"', + 'profiled_date: "2026-03-29"\nsource_commit: "newhead"', + ) + ) + part = PartResult( + RefPart("a.c", 10, 12, "a.c:10-12"), "ANCHORED", None, 10, 12, [] + ) + report = ProfileReport( + name="p", repo="o/n", pin="newhead", head="newhead", + entries=[EntryReport("a.bin", "a.c:10-12", "ANCHORED", [part])], + counts={"ANCHORED": 1}, upstream_pin="oldup", upstream_head="uphead", + ) + output = self._run(self._args(bump_commit=True), report) + self.assertIn("would set upstream_commit -> uphead", output) + self.assertNotIn("source_commit ->", output) + def test_writes_still_happen_without_the_flag(self): output = self._run( self._args(rebase_refs=True, dry_run=False), self._shifted() diff --git a/wiki/tools.md b/wiki/tools.md index 729d88b8..a83374a0 100644 --- a/wiki/tools.md +++ b/wiki/tools.md @@ -411,7 +411,8 @@ pass cannot rewrite without guessing: those are repaired first, by hand or with `--realign-prose`. The first prints the plan and changes nothing: `would recale` per ref and -`would set source_commit` per profile. It reaches that plan by running the +`would set source_commit` (and `upstream_commit`, when that one moves too) +per pin the write changes. It reaches that plan by running the real write path over a throwaway copy, so the planned bump reads the text the recale would have left rather than the one on disk; a pin held back by prose that the same pass would have moved is not reported as blocked. Drop