Skip to content

diff: emit deletions before insertions in unified diff on missing newline - #425

Closed
yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:fix/unified-missing-newline-deletions-first
Closed

yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:fix/unified-missing-newline-deletions-first

Conversation

@yunusarda-sudo

Copy link
Copy Markdown

When the last line of both files has the same text but only one of them ends with a newline, -u must show it as a deletion plus an insertion.

Previously, the deletion (-) line was appended at the point where the line was matched in Result::Both, which caused it to appear in the middle of preceding + insertions in the hunk.

Changes

  • Implemented Mismatch::expected_insert_pos(&self) to locate the start of insertions in the current change block, ensuring all deletion lines (-) and their optional trailing \ No newline are inserted before additions (+).
  • Applied this ordering logic to Result::Both (when one file is missing a trailing newline) as well as Result::Left.
  • Added test unified_missing_newline_deletions_first in tests/by-util/test_diff.rs covering both newline-difference directions.

Fixes #405

…line

When the last line differs only by its newline, ensure that the deletion
line (-) is placed before the insertion lines (+) in the unified diff hunk,
matching GNU diff.

Fixes uutils#405
@shadowmkj

Copy link
Copy Markdown
Contributor

Isn't this a duplicate of #420? That PR already has a review from @sylvestre (asking to reuse at_and_ts!)

@yunusarda-sudo

Copy link
Copy Markdown
Author

Closing in favor of #420 (addressed review feedback there).

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.

diff - -u prints a - line after + lines when the last line differs only by its newline

2 participants