Skip to content

Fix diff line numbers after no-newline markers and in combined diffs - #1463

Open
pdgendt wants to merge 2 commits into
jonas:masterfrom
pdgendt:fix-no-newline-lineno
Open

pdgendt wants to merge 2 commits into
jonas:masterfrom
pdgendt:fix-no-newline-lineno

Conversation

@pdgendt

@pdgendt pdgendt commented Oct 26, 2026

Copy link
Copy Markdown

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 file was counted as a line of both the old and the new file. Every line after it was off by one, e.g. git show of a commit that appends lines to a file without a trailing newline.

Assisted-by: Claude:claude-opus-5-5

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant