feat(engine): --sort=name for deterministic sibling ordering - #114
Merged
Conversation
Add --sort[=name], an xff extension: order each directory's entries by name before
visiting, so the walk is reproducible and diffable instead of filesystem-readdir
order (find's default, which --sort=none / absence preserves). Bare --sort means
--sort=name; last occurrence wins.
- WalkOptions gains SortOrder { kNone, kName }; Walker::Descend sorts the ReadDir
result by path (siblings share the dir prefix, so path order is name order) when
kName, covering both pre- and post-order.
- run.cc ResolveSort(globals) maps --sort / --sort=name -> kName, --sort=none -> kNone.
Tests: run_test (--sort visits root, a.txt < b.md < sub, sub/c.txt in that exact
order via ElementsAre; the unsorted default stays UnorderedElementsAre). Green in
both configs; clang-format + em-dash clean.
The parallel-traversal half of #43 remains a separate follow-up.
helly25
added a commit
that referenced
this pull request
Jul 6, 2026
A per-text-file line count in the field vocabulary: {lines}, %{lines} in
-printf, and --template - wc -l style but also counting a final unterminated
line. Empty for a non-regular, unreadable, or binary file (grep/ripgrep's
NUL-byte-in-first-8KiB heuristic), so binaries render nothing rather than a
misleading count.
- xff/content: CountLines (pure, reuses the CollectLineMatches grep line
semantics via ForEachLine) + FileLineCount (reads via mbo::file::Artefact,
skips binary), next to the line-match logic they share.
- xff/fields: LinesField reads by path (like {hash}), gated on a regular-file
metadata type; registered in the field table + FieldDocs (so --help=fields,
man, and markdown list it by construction).
- Tests: CountLines/FileLineCount unit tests, LinesField render tests
(text/no-newline/empty/binary/unreadable/non-regular), and a CLI bashtest
driving -printf %{lines} end to end.
The aggregate side (sum + distribution across matches) is the histograms
work (#81), not part of this field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--sort=name- reproducible traversal orderAdds
--sort[=name], an xff extension: order each directory's entries by name before visiting, so xff's output is reproducible and diffable instead of filesystem-readdir order (find's default - non-deterministic across filesystems/runs).--sort=none(or no flag) keeps the fast readdir order; bare--sortmeans--sort=name; last occurrence wins.What
WalkOptionsgainsSortOrder { kNone, kName };Walker::Descendsorts theReadDirresult by.path(siblings share the directory prefix, so path order == name order) whenkName- covering both pre-order and-depthpost-order in one place.run.ccResolveSort(globals)maps--sort/--sort=name->kName,--sort=none->kNone.Test
run_test:--sortvisitsroot, thena.txt<b.md<sub, thensub/c.txtin that exact order (ElementsAre); the unsorted default keepsUnorderedElementsAre.bazel test //...green in both--config=clangand--config=clang --config=asan. clang-format + em-dash clean.The parallel-traversal half of #43 remains a separate follow-up (it needs the walk threaded, deferred to keep this contained and low-risk).