Repository navigation
Conversation
d35033b to
abfacf9
Compare
Refresh the existing fix without rewriting its branch history. Preserve directory headers, empty sections and hidden-entry attribution while retaining short names, long metadata and native-output fallback. Recognize date-shaped directory labels before parsing file rows. Validated with fmt, clippy, all 5329 tests (8 ignored), and eight CLI cases.
|
@KuSh, thanks for directing #2868 to this PR. The CI run for current head Could a maintainer approve or restart CI for this head and review the multi-directory header fix for #2857? I can address any concrete CI or review findings. |
KuSh
left a comment
There was a problem hiding this comment.
Round 1 — CHANGES REQUESTED
Claim: with several directory operands, rtk ls keeps each directory's path: header and shows an empty operand as path: plus (empty), instead of one flat list.
Scope: accept if narrowed to "several directory operands without -R" (round 1, frozen). The header test also catches the sections of -R, so this PR currently regroups recursive listings too. That is #714's problem, handled by #1251 in another format. With -R/--recursive given, keep develop's output and leave it to #1251, with a test pinning that.
Ran: develop @42961225 vs this PR merged on it, real GNU ls 9.x under LC_ALL=C, every row through rtk rewrite first. 18 rows: the PR's 3 repros + ls -l a b, -lR, -la with an empty dir, a dir named total samples, over-cap (120 + 3 entries), a missing operand (exit 2), ACL/fifo/symlink rows ending in :, a file named (empty), plus a sweep of 40 flag spellings × 2 operand sets (80 runs) over a dir holding same:, fifo:, sub:/, ln: -> plain. Invariants: non-default targets, over-cap + accounting, under the hook, every decision. Savings 57% (ls -l a b), 85% (over-cap) vs the 20% floor (CONTRIBUTING.md).
Pins: 20 decisions, 20 mutated, 4 survived the suite: the row regex's type letters and its .+@ suffix (item 1), the header of a group cut entirely by the cap (item 3), and the regex's link-count field, which no real header reaches
Matrix: executed this round; pin check: executed this round
CI @1a90d22d: all green (15/15). Local gate on the merge with develop @42961225: fmt, clippy, 5921 tests pass.
Blocks merge (3, frozen at round 1)
src/cmds/system/ls.rs:528: a row ending in:is taken for a directory header when something comes before the permission field. 20 of the 80 sweep runs:-s/--size,-i/--inode,--diredand every combination containing them, including-lash. These flags put block counts or inode numbers in front of the permissions (--diredindents the row), soLS_ROW_REmisses, and a file, fifo or directory whose name ends in:opens a new section. Single directory,rtk ls -lash colon:
develop:plain 0B/same: 0B
this PR:plain 0B/ (blank) /0 -rw-rw-r-- 1 nlecam nlecam 0 Nov 28 02:01 same:/(empty)
With two operands,rtk ls -lash sweep bprintssweep:then(empty)for a directory holding four entries, and listsln:andplainunder a section named after thefifo:row. That is the misattribution #2857 is about, and here develop gave the right answer. A header is only ever the first line of the output or the line after a blank line; a test on that position, rather than on the row's shape, holds for all these flags. The rows a fix must pass:rtk ls -lash d,-li dand-ls d b, wheredholdssame:,fifo:(a fifo) andsub:(a directory): every entry is listed underd, and nothing prints(empty).- These shapes stay entries, each pinned by a test on captured output, because the mutations dropping them from
LS_ROW_REpass the suite today: the ACL row-rw-rw-r--+ 1 … acl:, the macOS row-rw-r--r--@ 1 … x:, the fifo rowprw-rw-r-- 1 … fifo:, and the symlink rowlrwxrwxrwx 1 … link -> tgt:.
src/cmds/system/ls.rs:662:(empty)is printed for a directory that holds entries. A group prints(empty)whenever none of its rows was displayed, including rows the parser dropped:- a file name ending in
.is classified byis_dotdir(which checks how the line ends) as./..:rtk ls -l dotend b, withdotend/notes., printsdotend:/(empty). Develop leavesnotes.out without saying the directory is empty. - a row the date parser rejects (mtime in year 10000, set with
touch -d 10000-01-01on tmpfs):rtk ls -l a bprintsb:/(empty)/... (1 filtered), where develop only said(3 filtered).
A fix must make both rows print the entry, or at least no(empty)for that group.is_dotdircomparing the name after the date with.and..closes the first. Printing(empty)only for a group with no rows besides real./..closes the second.
- a file name ending in
src/cmds/system/ls.rs:653: unpinned behaviour: a group whose entries all fall past the cap prints no header. Evidence: mutationif all_lines.is_empty() || displayed < CAP_INVENTORY {→if true {passes the whole ls suite andtests/ls_never_worse_test.rs. Test must: onls -l big colon(120 files inbig, 2 incolon), check that the output has nocolon:line and that the 2 entries are in the hidden list attributed tocolon:. The mutation must turn it red.
Optional (will not hold merge)
- The recall hint counts lines, not entries.
rtk ls -l big asays... (72 more, 1 filtered)and then[+146 hidden: …], because each hidden entry is stored asheader\nentry. Writing a header only when it changes halves the stored file and brings the count closer to the line above it. - Empty groups that come after the cap still print, between the last visible entry and
... (70 more)(rtk ls -l big empty1 empty2), so the cut entries read as if they followedempty2:. - The
compact_lsdoc comment saysfilteredholds "the display name of each entry". Those entries now carry the sameheader\nprefix astruncated.
Follow-ups
Checked and correct (no need to re-verify)
- Headers and grouping in long mode for 2 and 3 operands, a file operand before directory operands,
-laon an empty dir ((empty)), a directory namedtotal samples, a directory nameda b c d Jan 1 12:00 folder. - Short mode: the compact view with headers is printed only when it is smaller (
rtk ls big a: 514 bytes against 1105); in every other row the plain listing is printed unchanged, as on develop. - Over-cap accounting: 50 shown + 72 more + 1 filtered = the 123 entries
lsprints; the recall output lists all 73, each attributed to its directory. - A missing operand (exit 2) still passes the child's output and exit code through.
- Names containing a newline: GNU ls prints them as
?to rtk's pipe, so no fake header comes from them. - Merged with #4103: fmt, clippy and 5943 tests pass.
Your questions
- "Could a maintainer approve or restart CI for this head and review the multi-directory header fix for #2857?" → CI approved and green on 1a90d22; this is the review.
Next
Narrow to non-recursive listings (with -R, the output equals develop's, pinned by a test), fix items 1 and 2 so that their rows pass, and add the tests from items 1 and 3.
Threads: 3 open (waiting on the author), 0 resolved this round.
| LazyLock::new(|| Regex::new(r"^[bcdlps?-][rwxstST-]{9}[.+@]?\s+\d+\s").unwrap()); | ||
|
|
||
| fn is_listing_header(line: &str) -> bool { | ||
| line.ends_with(':') && !LS_ROW_RE.is_match(line) |
There was a problem hiding this comment.
With -s, -i or --dired (all passed through to the child), something comes before the permission field, so this check misses and a row ending in : opens a fake section. rtk ls -lash colon turns same: into the header 0 -rw-rw-r-- … same: followed by (empty). The rows a fix must pass are in item 1 of the review.
| entries.push('\n'); | ||
| } | ||
| if all_lines.is_empty() { | ||
| entries.push_str("(empty)\n"); |
There was a problem hiding this comment.
This fires for groups whose rows were dropped, not only for empty ones. A file named notes. (taken for ./.. by is_dotdir) or a row the date regex rejects leaves the group with entries and still prints (empty). See item 2.
| if all_lines.is_empty() && group.header.is_none() && groups.len() > 1 { | ||
| continue; | ||
| } | ||
| if all_lines.is_empty() || displayed < CAP_INVENTORY { |
There was a problem hiding this comment.
Mutating this to if true { passes the suite. Item 3 gives the test that has to fail on it.
Summary
rtk lsoutput for multiple directory operands.dir:plus(empty)instead of collapsing all output into one unlabeled empty result.Fixes #2857.
Testing
rustup run 1.91.0 cargo fmt --all -- --checkrustup run 1.91.0 cargo clippy --all-targetsrustup run 1.91.0 cargo testrtk ls dir_a dir_brtk ls empty_a empty_brtk ls root.txt dir_a