Skip to content

plumbing/format/diff: use git's funcname heuristic for hunk context#2238

Draft
SillyZir wants to merge 1 commit into
go-git:mainfrom
SillyZir:auto-fix/2193
Draft

plumbing/format/diff: use git's funcname heuristic for hunk context#2238
SillyZir wants to merge 1 commit into
go-git:mainfrom
SillyZir:auto-fix/2193

Conversation

@SillyZir

@SillyZir SillyZir commented Jul 2, 2026

Copy link
Copy Markdown

Fixes #2193.

go-git's unified diff used the line immediately before a change as the hunk header context (@@ ... @@ {), whereas git shows the enclosing function or section line (@@ ... @@ int main(int argc, char *argv[])).

This searches backward for a line matching git's default funcname heuristic (first character a letter, _, or $) and carries the last match across hunks, matching git's output.

Affected package tests pass locally.

The unified diff encoder used the line immediately preceding a change as
the hunk header context, producing "@@ ... @@ {" where git shows the
enclosing function line, e.g. "@@ ... @@ int main(int argc, char *argv[])".
Search backwards for a line matching git's default funcname heuristic
(first character a letter, '_' or '$') and carry the last match across
hunks, matching git's output.

Signed-off-by: SillyZir <269283839+SillyZir@users.noreply.github.com>
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.

ctxPrefix of hunk is wrong

1 participant