Don't show a trailing blank line at the end of single-column diffs - #996
Open
StressTestor wants to merge 1 commit into
Open
Don't show a trailing blank line at the end of single-column diffs#996StressTestor wants to merge 1 commit into
StressTestor wants to merge 1 commit into
Conversation
When a whole file is displayed in a single column (e.g. a file addition or removal), a file ending in a newline rendered an extra empty line after its last line. split_on_newlines yields a trailing empty element for the terminating newline, and the single-column path didn't drop it, unlike the two-column path. Extract that check into a helper and apply it to both paths. Also regenerates the many_newlines entry in the compare.expected regression baseline, which is a single-column (file addition) case. Fixes Wilfred#966.
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.
what
diffing a file that ends in a newline against
/dev/null(a file addition or removal) shows an extra blank line after the last line:this is #966.
why
split_on_newlinesreturns a trailing empty element when the source ends in a newline (documented and intentional). the two-column display already drops that trailing element, but the single-column path (used when one side is empty, e.g. a file addition or removal) rendered it as a real line.fix
pull the existing trailing-empty check into a small
has_trailing_blank_linehelper and apply it in the single-column branches too. the two-column path keeps the same behaviour (it reuses its existing line vec, no extra allocation). a genuine trailing blank line, e.g. a file ending in two newlines, is preserved; only the empty element from the terminating newline is dropped.tests
no_phantom_trailing_lineintests/cli.rs: diffs a 3-line file against/dev/nulland asserts there is no line 4. fails before the fix, passes after.many_newlinesentry insample_files/compare.expected, which is a single-column (file addition) case whose output this corrects.Fixes #966.