copies: keep renames detected against multiple merge parents#9757
Open
hexbinoct wants to merge 1 commit into
Open
copies: keep renames detected against multiple merge parents#9757hexbinoct wants to merge 1 commit into
hexbinoct wants to merge 1 commit into
Conversation
hexbinoct
force-pushed
the
fix/merge-commit-rename-diff
branch
from
July 4, 2026 07:33
7c3f494 to
16545ce
Compare
When diffing a merge commit, copy and rename detection runs once per parent, so a file renamed on a path present in several parents yields the same (source, target) copy record for each of them. `add_records` treated those duplicates as a target with multiple sources and poisoned both lookup maps. That dropped the deletion of the source and showed the target as a plain addition instead of a rename. Skip a record whose (source, target) pair was already recorded so the duplicate no longer looks like a conflict. Genuine conflicts, where a target has two different sources, are still discarded as before. The existing `test_diffedit_merge` was asserting the buggy output, where a copy made in a merge commit showed as a plain addition. Its snapshot now reports the copy, matching what the same edit produces against a single parent. Fixes jj-vcs#9752
hexbinoct
force-pushed
the
fix/merge-commit-rename-diff
branch
from
July 6, 2026 04:23
16545ce to
fa890de
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9752.
jj diff(andjj status) on a merge commit could silently drop a rename or copy. In the issue's reproduction, a file renamed in a merge whose parents all hold the source shows up as a plainA b.txtwith noD a.txt, instead ofR {a.txt => b.txt}.Cause: for a merge commit the diff command detects copies once per parent and feeds each parent's records into
CopyRecords::add_records. When the same rename exists against more than one parent, the identical(source, target)record arrives multiple times.add_recordsinterpreted the repeated target as a target with several different sources and set both the source and target map entries to an out of range index, which is how it marks a path as conflicting. After that,for_target(b.txt)returnsNoneso the target renders as a plain addition, whilehas_source(a.txt)still returns true so the deletion entry is suppressed. The rename is lost from both sides.Fix: skip a record whose
(source, target)pair was already recorded, so a duplicate coming from another parent is no longer mistaken for a conflict. A genuine conflict, where one target has two different sources across parents, is still discarded exactly as before. Since the fix is in the sharedadd_records,jj statuson a merge commit benefits too.Regression test:
test_diff_rename_in_merge_commitbuilds a merge of two branches that both contain the file and then renames it.jj diff -sprintsR {a.txt => b.txt}with the fix andA b.txtwithout it. The fulltest_diff_commandsuite and the jj-lib copy tests pass, and clippy and fmt are clean.Thanks @yuja for pointing at the relevant code in the issue thread.
Update: the existing
test_diffedit_mergewas asserting this same bug from the other direction. It makes a copy inside a merge commit and expected it to render as a plainA file3. With the fix it now showsC {file1 => file3}, which is exactly what the same edit produces against a single parent (verified withjj debug copy-detection). Fulljj-cliandjj-libsuites pass (0 failures).