Repository navigation
Conversation
In a combined diff, the first column tells how a line relates to the
first parent. Lines marked in the second column only are part of the
first parent when they are additions (" +") and are not when they are
deletions (" -"), but both the line number lookup and the origin
tracing got this wrong: the lookup skipped such additions, while the
tracing counted such deletions on both sides.
Add helpers telling whether a line in a chunk belongs to the old or the
new file, following the first column for combined diffs, and use them
wherever chunk lines are counted, so that the old line number and the
traced line are right on both sides of a merge.
Assisted-by: Claude:claude-opus-5-5
The "\ No newline at end of file" marker was counted as a line of both the old and the new file, so line numbers passed to the editor or used to trace the origin of lines after such a marker were off by one. Exclude the marker from both sides in the helpers deciding which file a chunk line belongs to. Assisted-by: Claude:claude-fable-5-1
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.
This fixes two off-by-one errors in how chunk lines are counted to compute line numbers. The line numbers are used by
%(lineno)/%(lineno_old), the editor, blame (origin tracing) and restoring the view position.Combined diffs. For the first parent, lines marked only in the second column were counted the wrong way round.
+lines are in the first parent but were skipped by the line number lookup.-lines are not, but origin tracing counted them on both sides. Blaming a line of a merge could open the wrong line, and%(lineno_old)was off.No-newline markers.
\ No newline at end of filewas counted as a line of both the old and the new file. Every line after it was off by one, e.g.git showof a commit that appends lines to a file without a trailing newline.Assisted-by: Claude:claude-opus-5-5