fix: correct "to" line number in unified diff hunk headers#10
Open
Yanhu007 wants to merge 1 commit intohexops:mainfrom
Open
fix: correct "to" line number in unified diff hunk headers#10Yanhu007 wants to merge 1 commit intohexops:mainfrom
Yanhu007 wants to merge 1 commit intohexops:mainfrom
Conversation
When multiple edits within the same hunk were separated by equal lines, the equal lines added via addEqualLines in the "within range" case were not being counted in toLine. This caused subsequent hunk headers to report incorrect "to" line numbers. For example, a diff with two hunks where the first hunk had equal lines between its edits would produce: @@ -12,5 +10,5 @@ instead of the correct: @@ -12,5 +12,5 @@ Fix by accumulating the return value of addEqualLines into toLine for within-range equal lines, matching git diff behavior. Fixes hexops#6
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 #6
Problem
When a unified diff has multiple hunks and the first hunk contains equal (context) lines between its edits, subsequent hunk headers report incorrect "to" line numbers.
Before (incorrect):
@@ -12,5 +10,5 @@After (correct, matches
git diff):@@ -12,5 +12,5 @@Root Cause
In
ToUnified, when edits within the same hunk are separated by equal lines (the "within range" case at line 100),addEqualLinesadds context lines to the hunk but its return value was discarded. This meanttoLinedid not account for these intra-hunk equal lines, causing the "to" line offset to drift for subsequent hunks.Fix
One-line change: accumulate the return value of
addEqualLinesintotoLinefor within-range equal lines:All existing tests pass.