Skip to content

Conversation

@cerdelen
Copy link
Contributor

Fix: #10188

Added a runtime check that --no-preserve-root is literal and was not abbreviated.

regression tests are included.

@cerdelen cerdelen marked this pull request as ready for review January 12, 2026 17:27
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 12, 2026

Merging this PR will degrade performance by 10.76%

❌ 2 regressed benchmarks
✅ 139 untouched benchmarks
⏩ 38 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
rm_force_files 2 ms 2.2 ms -10.76%
rm_multiple_files 2.2 ms 2.5 ms -9.29%

Comparing cerdelen:rm_no_abbreviation_no_preserve_root (b370eea) with main (1d6bd99)

Open in CodSpeed

Footnotes

  1. 38 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

By checking later we can reuse the result of looking up the clap flag. Since this is a map lookup it's relatively inefficient so reusing the previous lookup should improve benchmark in most cases.
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)

@anastygnome
Copy link
Contributor

anastygnome commented Jan 13, 2026

Hmm
Maybe you could do it this way :
Add a --no-preserve-roo (yes , without the t) explicit arg to the clap parser. Check if it matches, if it does, reject. This way you don't have to parse all args :)

@cerdelen
Copy link
Contributor Author

This way i would produce more overhead at the parsing stage though that will be run everytime, while the way it is right now the iteration over all args only occurs if at the parsing stage it was determined no preserve mode was active, right?

Also using matches.get_flag() also is just an iteration over all "valid args" as far as i see, so introducing the --no-preserve-roo (without t) makes the clap get_matches have a bigger overhead and doesn't save any runtime cost later on.

Please tell me if i have somewhere a wrong understanding how clap works.

@anastygnome
Copy link
Contributor

anastygnome commented Jan 13, 2026

No, because the parser is already trying to match no preserve root, so clap will optimize the parsing. , you're already adding overhead with trying to get the match every time.
You should create a new arg as in m'y above message with a value parser that always returns a Err

@cerdelen
Copy link
Contributor Author

As soon as i add another arg as you proposed clap starts enforcing the correct spelling but the error Messages are the long ones from clap itself.

`❯ ./target/debug/rm --no-pre l
error: unexpected argument '--no-pre' found

tip: a similar argument exists: '--no-preserve-roo'

Usage: rm [OPTION]... FILE...

For more information, try '--help'.
`

Also trying to use a value_parser that always returns an Error produces a different error Message by clap

`❯ ./target/debug/rm --no-pre l
error: invalid value 'l' for '--no-preserve-roo ': you may not abbreviate the --no-preserve-root option

For more information, try '--help'.`

So if we want a clean GNU style error message of just 'you may not abbreviate the --no-preserve-root option' i think we have to parse this manually apart from the clap library unfortunately.

@anastygnome
Copy link
Contributor

Oh, okay. if that's the case, you should add the no-preserve-roo flag and make the check after parsing. If it is present, just throw an error. That way we get most performance

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.

rm: allows dangerous abbreviation of --no-preserve-root option

2 participants