fix: correctly handle renamed files in the commit view (list + diffs)#189
Open
rubensa wants to merge 2 commits into
Open
fix: correctly handle renamed files in the commit view (list + diffs)#189rubensa wants to merge 2 commits into
rubensa wants to merge 2 commits into
Conversation
…list
Files renamed under a renamed directory collapsed onto a single key and
overwrote each other, so only some appeared in the file list (and a plain
add/delete sibling could show duplicated). Add split_rename() to expand the
brace form to the real old/new paths instead of truncating at the '{'.
A renamed file's old name exists only in the parent commit and its new name only in the child, but the diff/view/open handlers used a single path for both revisions. For a rename that meant the right-hand pane (and "View File at this Revision") resolved a path absent from that commit and rendered empty. Track new_path on each FileDiff and use the old path for hash1 and the new path for hash2 in show_diff/show_multi_diff/view_rev, and the new path for open_file/show_file. Non-renamed files are unaffected (new_path === path). Fixes phil294#131.
97a5148 to
cc0b72a
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 #187. Fixes #131.
Supersedes #188 — that PR fixed only the file-list parsing (#187). While
testing it I found that once renamed files finally appear in the list, opening
their diff still breaks (#131), because the two bugs share the same root cause:
renames aren't tracked through to the paths used per revision. This PR fixes
both, so I'll close #188 in favour of it.
This is two commits; they can be reviewed independently.
Commit 1 — parse git's compact
{old => new}rename notation (#187)When a commit renames a directory, git reports the moved files with its
compact rename notation, e.g.
src/{old => new}/file.txt. The file-listparser (
git_numstat_summary_to_changes_arrayinweb/src/components/CommitDiff.vue, fed bygit show --numstat --summary) onlyunderstood the full-path form
old => new.For a numstat row like
src/{old => new}/file.txtit did:So every file renamed under the same directory collapsed onto the same
key (
src/old) and the entries overwrote each other in the accumulator — onlythe last survived. The
--summaryrename branch had the same assumption, so itcouldn't reconcile either. Result: files silently missing from the commit's
file list, and a basename that also appeared as a plain add/delete pair could
show up duplicated.
Fix: a small
split_rename()helper expands git's compact formprefix/{old => new}/suffix(and the degenerate{old => new},dir/{ => new}/f,dir/{old => }/f, and plainold => new) into the realold/new paths, and the entries are keyed on the real old path in both the
numstat branch and the
--summaryrename branch.Commit 2 — use old/new paths for renamed files in commit diffs (#131)
Once #187 makes renamed files appear in the list, clicking one opened an empty
diff (and "View File at this Revision" opened an empty editor). A renamed file's
old name exists only in the parent commit and its new name only in the
child, but the handlers used a single path for both revisions:
So the child side resolved a path that doesn't exist in that commit and rendered
empty.
Fix: track
new_pathon eachFileDiff, and use the old path athash1and the new path athash2inshow_diff/show_multi_diff/view_rev, and the new path foropen_file/show_file. Non-renamedfiles are unaffected because
new_path === pathfor them.Verification
Built and type-checked locally against a fresh checkout:
npm run build(vite + esbuild) — passes.vue-tsc --noEmit— no new errors from either change (the one remainingCommitDiff.vuediagnostic is pre-existing and present on the unmodifiedtree, just line-shifted).
src/old/→src/new/): before only1 of 2 renamed files appeared (both collapsed onto one key); after both
appear with correct old/new paths. The loss scales with the directory — an
N-file rename previously collapsed all N brace entries onto a single key.
the pane was empty; after it resolves parent:
old↔ child:newand bothpanes populate. Modified/created/deleted files produce identical URIs to
before.
Reproduce the original bugs
Open the
rename dircommit:{old => new}brace notation not parsed) #187: at least one renamed file is missing from the file list;with more files in the directory, several go missing and a basename can appear
duplicated.
empty "View File at this Revision".
views open correctly.