Show unchanged lines that fall inside an inline hunk#980
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
When two novel lines in a hunk are close enough to merge into a single hunk, the unchanged lines between them were dropped from inline display output. Side-by-side rendering uses matched_lines_indexes_for_hunk to walk the full hunk range, so it already includes these lines. Inline was iterating hunk.lines directly, which only contains positions with novel content. This is most visible on .gitconfig files where a section heading like [url "ssh://git@github.com"] sits between two pushInsteadOf edits and silently disappears from the diff (issue Wilfred#978). Add a fill_in_hunk_gaps helper that walks hunk.lines and emits the intervening line numbers for each side, then update the LHS and RHS print loops to use the hunk's novel_lhs / novel_rhs sets so that gap lines render as context rather than as added or removed. Signed-off-by: Chris <chris@hacknow.com>
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.
Closes #978.
Bug
When two novel lines in a hunk are close enough that the merge step in
display::hunks::merge_adjacentcombines them into one hunk, the unchanged lines between them are silently dropped from inline (--display=inline) output. Side-by-side and JSON output don't have this problem because both usematched_lines_indexes_for_hunkto walk the full hunk range, so they already include the in-between unchanged lines. Inline was iteratinghunk.linesdirectly, and that field only contains positions with novel content.In the report this surfaces as a missing section heading on a
.gitconfig:The line
[url "ssh://git@github.com"]between two changedpushInsteadOf =lines does not appear.Repro
before.gitconfig:after.gitconfig(same, but bothpushInsteadOflines are commented out):Before this PR
Lines 6 (blank) and 7 (
[url "ssh://git@github.com"]) are missing on both sides.After this PR
Fix
Add a small
fill_in_hunk_gapshelper insrc/display/inline.rsthat walkshunk.linesand emits the intervening line numbers for each side, then update the LHS and RHS print loops to consulthunk.novel_lhs/hunk.novel_rhsso the new gap entries render with dimmed (context) line numbers instead of bold red / green ones.I considered switching inline to use
all_matched_lines_filled+matched_lines_indexes_for_hunkthe same way side-by-side does, but that would also require restructuring how the before / after context loops are integrated. This narrower change keeps the existing structure and only fixes the dropped-context-inside-hunk case.Testing
fill_in_hunk_gapscovering the empty input, no-gap, LHS-only-changes-with-an-unchanged-tail, and unequal-side-gaps shapes.cargo test --release(148 tests) passes..gitconfigrepro above and against syntactic (Rust) inputs to confirm the multi-hunk path still splits correctly when changes are far apart.