Skip to content

fix: accept separate diff width arguments - #400

Open
dex0o0 wants to merge 2 commits into
uutils:mainfrom
dex0o0:fix-width-option-arguments
Open

dex0o0 wants to merge 2 commits into
uutils:mainfrom
dex0o0:fix-width-option-arguments

Conversation

@dex0o0

@dex0o0 dex0o0 commented Nov 15, 2026

Copy link
Copy Markdown

Fixes #396

This PR fixes the handling of the -W and --width options in diffutils.

Previously, only the --width=VALUE syntax was supported. This change reuses the existing option_argument and argument_value helpers to support all standard argument formats:

  • -W 20
  • -W20
  • --width=20
  • --width 20

It also adds tests covering all supported formats, invalid values, zero width, and missing arguments.

Testing

  • cargo fmt --check
  • cargo test

All tests pass.

@codspeed

codspeed Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 32.72%

1 warning

⚠️ 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 improved benchmark
✅ 25 untouched benchmarks

Performance Changes

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

Tip

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


Comparing dex0o0:fix-width-option-arguments (6bb5442) with main (471217f)

Open in CodSpeed

Comment thread src/params.rs Outdated
continue;
}

if tabsize_re.is_match(param.to_string_lossy().as_ref()) {

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.

#396 also reports --tabsize 4 being rejected.
could you please move tabsize to option_argument/argument_value too? it would also get rid of the regex and the unwrap()

Comment thread src/params.rs Outdated
}
Err(_) => return Err(format!("invalid width «{width_str}»")),
Ok(num) if num != 0 => num,
_ => return Err(format!("invalid width «{}»", width_str)),

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.

{width_str} inline, like tabsize below?

Comment thread src/params.rs Outdated
let mut show_c_function = false;
let tabsize_re = Regex::new(r"^--tabsize=(?<num>\d+)$").unwrap();
let width_re = Regex::new(r"^--width=(?P<long>\d+)$").unwrap();

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 remove this empty line

Comment thread src/params.rs
.peekable()
)
);
let parse = |args: &[&str]| {

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 also add the test from the issue in tests/by-util/test_diff.rs, so the real binary is checked with -y -W 20

Allow the -W/--width and --tabsize options to accept arguments
provided as separate command-line parameters.

Replace the tabsize regex parsing with option_argument and
argument_value to handle both attached and separate arguments.

Add unit and integration tests covering separate arguments,
missing arguments, and invalid tabsize values.

ts.ucmd()
.args(&["-y", "-W", "20", "file1", "file2"])
.run()

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 use .fails_with_code(1) instead of .run()? so we also check the exit code

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

2 participants