Repository navigation
tail: accept obsolete -cf and allow only one trailing f - #15518
emirmrkaljevic wants to merge 2 commits into
Conversation
| pub fn parse_args(args: impl uucore::Args) -> UResult<Settings> { | ||
| let args_vec: Vec<OsString> = args.collect(); | ||
| let clap_args = uu_app().try_get_matches_from(args_vec.clone()); | ||
| let mut invalid_value = false; |
There was a problem hiding this comment.
invalid_value is set for any settings error, not only an invalid count, maybe a clearer name?
| } | ||
| // `tail -cf` is obsolete syntax even though clap reads it as `-c f`, | ||
| // but in `tail -c f` the separate argument is always the count. | ||
| if invalid_value && possible_obsolete_args.len() <= 2 { |
There was a problem hiding this comment.
len() <= 2 is a bit magic, could you please make it explicit that it means "no value attached to the option"?
| if invalid_value && possible_obsolete_args.len() <= 2 { | ||
| return clap_result; | ||
| } | ||
| match parse_obsolete(possible_obsolete_args, args_vec.get(2))? { |
There was a problem hiding this comment.
could you please run the GNU tail tests too? tail.pl has lots of obsolete syntax cases
setup: git clone https://github.com/coreutils/coreutils.git ../gnu
run: bash util/build-gnu.sh && bash util/run-gnu-test.sh tests/tail/tail.pl
| .make_assertion() | ||
| .with_all_output() | ||
| .stdout_only("hijklmnop\n"); | ||
|
|
There was a problem hiding this comment.
could you please also add the stdin case (-cf without a file)? it is in the issue
|
Thanks for the review! I renamed |
Merging this PR will degrade performance by 13.34%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | complex_relative_date |
277.7 µs | 386.2 µs | -28.1% |
| ⚡ |
Simulation | du_deep_tree[(100, 3)] |
1.9 ms | 1.9 ms | +4.45% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing emirmrkaljevic:tail-obsolete-c (41cb88b) with main (5fda18e)2
Footnotes
-
70 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. ↩
-
No successful run was found on
main(b77b664) during the generation of this report, so 5fda18e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Summary
tail -cf FILEfailed withinvalid number of bytes: 'f', while GNU prints the last 10 bytes and follows. clap reads-cfas-c f, and the count error was returned with?before the obsolete-syntax parser got a chance. Now an invalid count falls through to the obsolete parser when the value was attached to the option (-cf); a separate argument (tail -c f) is still an invalid count, as in GNU.fs (-5ff,-cff,+cff). GNU accepts only one, so-5ffis nowoption used in invalid context -- 5and+cffis a file name, like GNU.Fixes #15517
Test plan
test_tail_obsolete_bytes_followcovers-cf FILE(follows, prints the last 10 bytes),-c f(still an error) and-5ff; it fails without the change-cff,+ffand-5ffcargo test --no-default-features --features tail test_tail::: 168 passed, 12 ignored;cargo test -p uu_tail --lib: 38 passedcargo fmt --check,cargo clippy -p uu_tail --all-targets -- -D warnings-cf,-cf FILE,-c FILE,-cl,-cff,-cfv,-c3f,-nf,-vcf,--bytes=f,-5ff,+cff,-3cf,+5f,-5f,+fFound with behave.