Skip to content

fix(patch)!: stop parsing at garbage after hunk satisfied#7

Merged
weihanglo merged 3 commits intogit-format-patchfrom
parse
Jan 19, 2026
Merged

fix(patch)!: stop parsing at garbage after hunk satisfied#7
weihanglo merged 3 commits intogit-format-patchfrom
parse

Conversation

@weihanglo
Copy link
Copy Markdown
Owner

Hunk is satisfied when line counts from header are satisfied.

  • hunk_lines() now tracks old/new line counts during parsing
  • Stops at non-hunk line when counts satisfied
  • Errors if non-hunk line before counts satisfied

While this is kinda a breaking change in behavior,
it matches GNU patch behavior.

Hunk is satisfied when line counts from header are satisfied.

- `hunk_lines()` now tracks old/new line counts during parsing
- Stops at non-hunk line when counts satisfied
- Errors if non-hunk line before counts satisfied

While this is kinda a breaking change in behavior,
it matches GNU patch behavior.
@weihanglo weihanglo merged commit c46279e into git-format-patch Jan 19, 2026
10 checks passed
@weihanglo weihanglo deleted the parse branch January 19, 2026 20:36
weihanglo added a commit that referenced this pull request Jan 25, 2026
This was a regression introduced by commit 79c086b (#7),
which added garbage handling for complete hunks
but missed the `no_newline_context` branch.

When a hunk ends with `\ No newline at end of file` on a context line
and is followed by trailing content (e.g., `diff --git` headers from
UniDiff splitting), the parser fails with "expected end of hunk".

Pattern first appeared in rust-lang/cargo@b119b891d.
weihanglo added a commit that referenced this pull request Jan 25, 2026
This was a regression introduced by commit 79c086b (#7),
which added garbage handling for complete hunks
but missed the `no_newline_context` branch.

When a hunk ends with `\ No newline at end of file` on a context line
and is followed by trailing content (e.g., `diff --git` headers from
UniDiff splitting), the parser now correctly recognizes the hunk as
complete instead of erroring with "expected end of hunk".

This fixes parsing of `git diff` output in UniDiff mode where patches
are split by `---/+++` boundaries, causing subsequent git headers to
be appended to the previous patch.

Pattern first appeared in rust-lang/cargo@b119b891d.
weihanglo added a commit that referenced this pull request Apr 9, 2026
This was a regression introduced by commit 79c086b (#7),
which added garbage handling for complete hunks
but missed the `no_newline_context` branch.

When a hunk ends with `\ No newline at end of file` on a context line
and is followed by trailing content (e.g., `diff --git` headers from
UniDiff splitting), the parser fails with "expected end of hunk".

Pattern first appeared in rust-lang/cargo@b119b891d.
weihanglo added a commit that referenced this pull request Apr 9, 2026
This was a regression introduced by commit 79c086b (#7),
which added garbage handling for complete hunks
but missed the `no_newline_context` branch.

When a hunk ends with `\ No newline at end of file` on a context line
and is followed by trailing content (e.g., `diff --git` headers from
UniDiff splitting), the parser now correctly recognizes the hunk as
complete instead of erroring with "expected end of hunk".

This fixes parsing of `git diff` output in UniDiff mode where patches
are split by `---/+++` boundaries, causing subsequent git headers to
be appended to the previous patch.

Pattern first appeared in rust-lang/cargo@b119b891d.
weihanglo added a commit that referenced this pull request Apr 9, 2026
This was a regression introduced by commit 79c086b (#7),
which added garbage handling for complete hunks
but missed the `no_newline_context` branch.

When a hunk ends with `\ No newline at end of file` on a context line
and is followed by trailing content (e.g., `diff --git` headers from
UniDiff splitting), the parser fails with "expected end of hunk".

Pattern first appeared in rust-lang/cargo@b119b891d.
weihanglo added a commit that referenced this pull request Apr 9, 2026
This was a regression introduced by commit 79c086b (#7),
which added garbage handling for complete hunks
but missed the `no_newline_context` branch.

When a hunk ends with `\ No newline at end of file` on a context line
and is followed by trailing content (e.g., `diff --git` headers from
UniDiff splitting), the parser now correctly recognizes the hunk as
complete instead of erroring with "expected end of hunk".

This fixes parsing of `git diff` output in UniDiff mode where patches
are split by `---/+++` boundaries, causing subsequent git headers to
be appended to the previous patch.

Pattern first appeared in rust-lang/cargo@b119b891d.
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