Skip to content

diff: write a one-line add or delete range as a single number - #308

Open
jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:single-line-add-delete
Open

jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:single-line-add-delete

Conversation

@jayhemnani9910

Copy link
Copy Markdown

In the normal format a single added or deleted line still comes out as a range:

$ printf 'a\n' > x; printf 'a\nb\n' > y
$ diffutils diff x y
1a2,2
> b
$ diffutils diff y x
2,2d1
< b
$ /usr/bin/diff x y    # GNU diff 3.12
1a2
> b

GNU diff writes 1a2 and 2d1. -e has the same thing: 2,2d instead of 2d. #11 (for #10) fixed this for changed lines (1c1); added and deleted lines were left out.

This adds the one-line cases next to the existing ones in normal_diff.rs ((0, 1) and (1, 0)) and ed_diff.rs ((1, 0)).

Tests: test_single_line_added_or_deleted (normal) and test_single_line_deleted (ed) check the exact output. Both fail on main. cargo test: all pass (285 on main, 289 here; the two new tests run in both the lib and the bin target), including the permutation tests that feed the output to patch and ed. cargo fmt --check is clean, and cargo clippy --all-targets gives the same warnings as on main. I also compared the default and -e output with GNU diff 3.12 over 22 file pairs (single-line and multi-line adds and deletes, blank lines, missing newlines, empty files): the default format matches for all of them now except binary files. -e still writes its hunks top-down with already-shifted line numbers where GNU goes bottom-up; both scripts give the same file, so I left that alone.

The normal format printed a single added or deleted line as a range,
"1a2,2" and "2,2d1", where GNU diff and POSIX write "1a2" and "2d1",
and -e printed "2,2d" for "2d". Changed lines already had this
(see uutils#10); do the same for added and deleted ones.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 05:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Comment thread src/normal_diff.rs
let actual_count = result.actual.len();
match (expected_count, actual_count) {
(0, 0) => unreachable!(),
(0, 1) => writeln!(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please run the upstream test suite on it?
TESTS=basic ./tests/run-upstream-testsuite.sh
the whole suite would be even better, it would tell us if it makes more tests pass

@jayhemnani9910

Copy link
Copy Markdown
Author

Ran the whole upstream suite on main (0019867) and on this branch: same on both, 7 pass, 22 fail, 4 skip, and no test changes its result. basic fails on both because of its -999999999999999999999999999999 option case, before it gets to the range output.

@jayhemnani9910

Copy link
Copy Markdown
Author

Ran the full upstream suite (release builds) on main and on this branch: 7 passed, 22 failed, 4 skipped on both, and every test has the same result. basic fails on both at diff -9999999999999999999999999999 a b (unrecognized option), before it reaches anything this changes.

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.

3 participants