Repository navigation
diff: stop the trailing context at -U/-C lines when both files lack a final newline - #370
Merged
sylvestre merged 1 commit intoNov 10, 2026
Conversation
… final newline When the last lines of both files are equal and unterminated, the lines waiting in the context queue were added to the hunk before them, so it got more trailing context than asked for. Only add the last line when it is still within the trailing context, in both unified and context output. Fixes uutils#364
sylvestre
reviewed
Nov 10, 2026
| // the last line is still shown when it is within the trailing context | ||
| let mut cmd = cargo_bin_cmd!("diffutils"); | ||
| cmd.arg("diff") | ||
| .arg("-U5") |
Collaborator
There was a problem hiding this comment.
could you please also cover -C5 / -C6? only the unified side is tested at the boundary
and it could be a loop like the one above, no?
Collaborator
|
Thanks for your PR |
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.
When both files end with the same unterminated line, the branch for that line flushed the context queue into the last hunk. Those queued lines are already past the trailing context, and since it's the last line there's no next hunk for them to lead into, so they should just be dropped. Now only the last line itself is added, and only when it's still within the trailing context. Same fix in unified_diff.rs and context_diff.rs.
Added a test for -u and -c from the issue, plus -U5/-U6 to check the last line still shows (with "\ No newline at end of file") when it's within the context. Output now matches GNU diff for these cases.
Fixes #364