Skip to content

diff: add -L/--label - #314

Open
jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:diff-label
Open

jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:diff-label

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

diff -L LABEL / --label=LABEL is rejected (unrecognized option, exit 2). It names the inputs in the ---/+++ and ***/--- headers instead of the file name and time; git's external diff drivers, make check scripts and patch generators that diff temp files rely on it:

$ diff -u --label a/conf --label b/conf /tmp/x1 /tmp/x2
GNU:  --- a/conf
      +++ b/conf
      @@ -1,2 +1,2 @@ ...
main: unrecognized option '--label'   (exit 2)

-L X, -LX, --label X and --label=X are accepted anywhere among the arguments. The first labels the from-file and the second the to-file; a third is an error (too many file label options, exit 2), as in GNU. A labelled header has no timestamp. -q and -s use the labels in Files A and B differ / are identical. Normal, ed and side-by-side output have no header, so they are unchanged.

Tests: a parse_params test (two labels, and three as an error) and an integration test for -u, -c, -q and a third label; the integration test fails on main. cargo test: 133 unit and 24 integration tests pass (132 and 23 on main), cargo clippy -- -D warnings and fmt clean. Against GNU diff 3.12, 15 label cases give the same output and exit code; only the error text lacks GNU's diff: prefix, like the crate's other errors. The upstream GNU suite gives the same per-test results as main (8 pass, 21 fail, 4 skip).

Copilot AI balanced review requested due to automatic review settings October 24, 2026 07:20

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 insufficient remaining quota.

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/diff.rs Outdated
.to_label
.as_ref()
.unwrap_or(&params.to)
.to_string_lossy(),

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.

same label-or-path expression 4 times here and at line 107, could be a small helper on Params, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 8c613e4: Params::names() returns the label or path for both files, and the two messages in diff.rs use it. The context and unified headers keep header_name, since they also print the modification time when there is no label.

Comment thread src/params.rs Outdated
.strip_prefix("--label=")
.or_else(|| p.strip_prefix("-L"))
.map(OsString::from),
None => None,

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.

-L<non-utf8> ends up as "unrecognized option" while -L <non-utf8> works, could you please handle it with the bytes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 8c613e4: -L<label> and --label=<label> are now matched on the argument's bytes, so -L$'\xffold' is read as a label like -L $'\xffold'. Added labels_non_utf8, which fails without the change.

The header still prints a non-UTF-8 label through to_string_lossy, the same as file names today, where GNU writes the raw bytes. I left that for a separate change.

@sylvestre

Copy link
Copy Markdown
Collaborator

sorry, needs to be rebased

-L<label> and --label=<label> are matched on the argument's bytes, so a
non-UTF-8 label attached to the option is read like a separate one.
The label-or-path choice for both files moves into Params::names.
Copilot AI balanced review requested due to automatic review settings October 24, 2026 14:20

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 insufficient remaining quota.

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.

@jayhemnani9910

Copy link
Copy Markdown
Contributor Author

Rebased on main and moved the test to tests/by-util/test_diff.rs. cargo test passes, and cargo clippy -- -D warnings and cargo fmt --check are clean.

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