Skip to content

fix: flat layout sort order and spacing - #11

Merged
jeiang merged 2 commits into
masterfrom
fix/flat-layout
Oct 14, 2026
Merged

jeiang merged 2 commits into
masterfrom
fix/flat-layout

Conversation

@jeiang

@jeiang jeiang commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Fixes upstream solidiquis#224 and solidiquis#241.

Sorting (solidiquis#224). Flat/iflat output walked the tree that was sorted per directory, so with e.g. --sort size --dirs-only a nested dir smaller than its parent's sibling appeared out of order. Evaluated upstream PR solidiquis#234: it re-parents all nodes to the root during assembly and re-sorts, but its updated test expectations are not actually sorted and it drops ordering of parents vs. children; I instead added Tree::flat_order, which globally stable-sorts all non-root nodes (by --sort/--dir-order) over a pre-order walk, root pinned first (iflat) / last (flat, which is the reverse). Ties list a directory before its contents. Regular/inverted layouts are untouched. Author credited via Co-authored-by.

Whitespace (solidiquis#241). An empty size cell (--suppress-size, or no sizes) no longer emits a blank column; the row is just the path. Spacing otherwise unchanged (3 spaces after the size).

Changed expectations: flat and flat_human in tests/flat.rs encoded the hierarchical (per-directory) order, which is the bug; they now show the global order.

Tests: new tests/flat_data fixture + tests for flat/iflat dirs-only and files+dirs size ordering and a whitespace test (run_cmd_untrimmed added because run_cmd trims). All fail before the fix.

Before (erd --layout flat --sort size --dirs-only tests/flat_data): 50 b, 40 a/c, 60 a, 110 flat_data; after: 40 a/c, 50 b, 60 a, 110 flat_data. --suppress-size: rows were path (3 leading spaces), now path.

Flat layouts walked the per-directory-sorted hierarchy, so --sort (and
--dirs-only) produced an order that only made sense for a tree. Sort all
entries globally for flat/iflat via Tree::flat_order (root pinned last/first)
and drop the per-hierarchy walk.

When the size column is empty (--suppress-size), omit it and its separator
instead of printing a blank column with leading whitespace.

Fixes solidiquis#224, solidiquis#241.
Based on the approach in solidiquis#234.

Co-authored-by: siqpush <98565842+siqpush@users.noreply.github.com>
@jeiang
jeiang enabled auto-merge October 14, 2026 14:30
@jeiang
jeiang merged commit ad02c7d into master Oct 14, 2026
15 checks passed
@jeiang
jeiang deleted the fix/flat-layout branch October 14, 2026 14:35
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.

1 participant