Skip to content

diff: accept -W N, -WN, --width N and --tabsize N option forms - #424

Merged
sylvestre merged 4 commits into
uutils:mainfrom
yunusarda-sudo:feat/width-tabsize-argument-forms
Nov 24, 2026
Merged

sylvestre merged 4 commits into
uutils:mainfrom
yunusarda-sudo:feat/width-tabsize-argument-forms

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

Accept separate argument forms (-W N, --width N, --tabsize N) and attached short option (-WN) in addition to attached long option formats (--width=N, --tabsize=N), matching GNU diff.

Changes

  • Replaced regex matching of --width=N and --tabsize=N with option_argument and argument_value.
  • Guarded option_argument so empty short / long prefixes do not inadvertently match.
  • Added unit tests in src/params.rs for all argument forms and error cases.
  • Added integration tests in tests/by-util/test_diff.rs covering option forms and missing/invalid arguments.

Fixes #396

Accept separate arguments (-W N, --width N, --tabsize N) and attached
short option (-WN) in addition to attached long options (--width=N,
--tabsize=N).

Fixes uutils#396
@codspeed

codspeed Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 33.75%

2 warnings

⚠️ 24 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 1 improved benchmark
✅ 25 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ diff_parser 5.7 ms 4.3 ms +33.75%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing yunusarda-sudo:feat/width-tabsize-argument-forms (46c03ab) with main (470161e)

Open in CodSpeed

Comment thread src/params.rs Outdated
/// `long` is given, if `param` is that option.
fn option_argument<'a>(param: &'a OsStr, short: &str, long: &str) -> Option<OptionArgument<'a>> {
if param == short || param == long {
if (!short.is_empty() && param == short) || (!long.is_empty() && param == long) {

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 be simpler with short: Option<&str> instead of the empty-string checks, 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 commit e680053: changed short to Option<&str>.

Comment thread tests/by-util/test_diff.rs Outdated
.args(&["w1", "w2"])
.succeeds()
.stderr_is("")
.stdout_contains("x ")

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.

please check the exact output with stdout_is, "x " is a weak check

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 commit e680053: changed to exact stdout_is assertion.

.args(&["w1", "w2"])
.succeeds()
.stderr_is("")
.stdout_is("x <\n >\ty\n");

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.

GNU prints x | y here (see #396), so this pins our side_diff divergence
could you please add a comment or open an issue for it?

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.

Added in commit 808c559: added a comment documenting the divergence from GNU diff side-by-side format referencing #396.

@dex0o0

dex0o0 commented Nov 22, 2026

Copy link
Copy Markdown

Hi!

I noticed that this PR addresses almost the same changes as my PR #400.

My PR already includes the requested changes for --tabsize and uses the same option_argument / argument_value helpers.

Would you prefer to continue with this PR, or should I keep working on #400 and close one of them to avoid duplicate work?

I'm happy to follow whichever approach is easier for maintainers.

@yunusarda-sudo

Copy link
Copy Markdown
Contributor Author

Hi @dex0o0 — thanks for flagging the overlap, and sorry I missed #400 when I opened this.

You're right that both PRs fix #396 the same way: they drop the --width= / --tabsize= regexes and reuse option_argument / argument_value for -W N, -WN, --width N, and --tabsize N.

You opened first (Nov 15 vs Nov 19), already addressed Sylvestre's request to include --tabsize, and later split the unrelated side-by-side work into #403. I'd be happy for #400 to continue, and for this PR to be closed once that's ready.

The one thing #424 still has on top is a slightly broader test surface from review here: all four width spellings, exact missing/invalid-argument messages (exit 2), and a short comment pinning the current side_diff output against GNU's x | y format (see #396). Please feel free to take those from this branch if they're useful.

Happy to follow whatever the maintainers prefer.

@dex0o0

dex0o0 commented Nov 22, 2026

Copy link
Copy Markdown

@yunusarda-sudo
Thanks for your understanding! Honestly, I didn't have any problem with the overlap. Since this was my first contribution to the project, I may have handled some things a little unprofessionally, and I'm still learning how to navigate the contribution process.

I really appreciate the work you've put into your PR.

I think it's best to leave the decision to the maintainers and follow whatever they consider the best approach.

Thanks again for being so understanding!

@sylvestre
sylvestre merged commit 6f24ee8 into uutils:main Nov 24, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

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 - -W N and --width N are rejected, only --width=N works

3 participants