Skip to content

feat(protocol): port upstream f_name_cmp byte-wise name comparator (#2252) - #4256

Merged
oferchen merged 1 commit into
masterfrom
feat/upstream-f-name-cmp-2252
May 17, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/upstream-f-name-cmp-2252

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds f_name_cmp(&FileEntry, &FileEntry) -> Ordering in crates/protocol/src/flist/name_cmp.rs, mirroring upstream flist.c:f_name_cmp() (flist.c:3217-3334). Comparison is (dirname, basename) in unsigned byte order - no locale, no case folding, no protocol-29 file-vs-dir disambiguation (that stays in sort.rs).
  • Adds name_cmp_eq (folds a trailing / on basenames to mirror upstream's implicit directory-slash equivalence, flist.c:3206-3211) and a f_name_cmp_components components-only helper for fuzzers/callers that already hold the dirname/basename byte pair.
  • Foundational sort key for the parallel-deterministic-delete pipeline (DDP). No wiring of existing callers in this PR - that lives in DDP-B2.

Upstream lines cited

  • flist.c:3197 enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING }
  • flist.c:3198 enum fnc_type { t_PATH, t_ITEM }
  • flist.c:3217-3334 f_name_cmp()
  • flist.c:3331 (int)*c1++ - (int)*c2++ - the unsigned byte compare
  • flist.c:3206-3211 - implicit trailing-/ equivalence on directories

Test plan

  • CI: fmt + clippy
  • CI: nextest stable on Linux musl
  • CI: nextest macOS
  • CI: nextest Windows
  • Unit tests cover: plain ASCII, same-basename/different-dirname, same-dirname/different-basename, high-byte unsigned order (>= 0x80, both via OsStr bytes on Unix and via components helper portably), dot/double-dot, hidden dotfiles, embedded slashes, deep nesting, file-vs-dir byte-only equality
  • Proptest covers reflexivity, antisymmetry, transitivity, and agreement with the components helper

…2252)

Adds a foundational `f_name_cmp` that compares two `FileEntry` values by
`(dirname, basename)` in unsigned byte order, mirroring upstream rsync's
`flist.c:f_name_cmp()`. Bytes with the high bit set sort after ASCII; no
locale awareness, no case folding, no protocol-29 file-vs-directory
disambiguation (that logic stays in `sort.rs`).

This is the sort key the parallel-deterministic-delete pipeline needs to
merge candidate lists with byte-identical ordering to upstream's pre-sort
scan. Wiring callers over to this comparator is left to follow-up tasks.

Includes a `name_cmp_eq` helper that tolerates a single trailing `/` on
the basename to mirror upstream's implicit directory-slash equivalence,
and a components-only `f_name_cmp_components` helper for callers and
fuzzers that already hold dirname/basename byte slices.

Unit tests cover ASCII ordering, same-basename/different-dirname,
high-byte unsigned order (>= 0x80), dot/double-dot, hidden dotfiles,
embedded slashes, deep nesting, and the file-vs-dir byte-only fold.
Proptest covers reflexivity, antisymmetry, transitivity, and agreement
with the components helper.

Upstream references:
  - flist.c:3197 enum fnc_state
  - flist.c:3198 enum fnc_type
  - flist.c:3217-3334 f_name_cmp()
  - flist.c:3331 (int)*c1++ - (int)*c2++  (unsigned byte compare)
@oferchen
oferchen merged commit 8526315 into master May 17, 2026
13 checks passed
oferchen added a commit that referenced this pull request May 17, 2026
…lel deterministic delete (#2253, #2254) (#4259)

* feat(engine): DeletePlan, DeletePlanMap, DirTraversalCursor (#2253, #2254)

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline described in docs/design/parallel-deterministic-delete.md
(PR #4257). Three new modules under crates/engine/src/delete/:

- plan.rs: DeletePlan (sorted, frozen per-directory work item),
  DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and a
  HardlinkCohortId newtype. sort_by_name() uses upstream's f_name_cmp
  (PR #4256) ascending then reverses, matching delete_in_dir's loop
  at generator.c:320.
- plan_map.rs: DeletePlanMap, the publish-once concurrent rendezvous
  between phase-1 workers and the phase-2 emitter. Backed by
  Mutex<HashMap> for now; bench-driven choice between Mutex,
  DashMap, and a sharded map is deferred to task DDP-B4 (see code
  comment).
- traversal.rs: DirTraversalCursor, yields directories in upstream's
  depth-first f_name_cmp-ascending order. Tree built from observed
  flist segments via observe_segment(); next_ready() returns the
  next directory whose parent has been emitted.

Pure data structures, no callers; phase-1 and phase-2 wiring lands in
later tasks (#2255-#2278). Unit tests cover plan ordering, concurrent
inserts and takes from 16 threads, out-of-order segment observation,
non-directory filtering, duplicate observations, and high-byte
basename ordering on Unix.

* fix(engine): avoid borrow-checker conflict in DirTraversalCursor::next_ready

Splits the frame inspection from the mutation so the mutable borrow of
the top frame is released before pushing a new frame or popping the
old one. Functionally equivalent.
@github-actions github-actions Bot added the enhancement New feature or request label May 17, 2026
oferchen added a commit that referenced this pull request May 18, 2026
…2252) (#4256)

Adds a foundational `f_name_cmp` that compares two `FileEntry` values by
`(dirname, basename)` in unsigned byte order, mirroring upstream rsync's
`flist.c:f_name_cmp()`. Bytes with the high bit set sort after ASCII; no
locale awareness, no case folding, no protocol-29 file-vs-directory
disambiguation (that logic stays in `sort.rs`).

This is the sort key the parallel-deterministic-delete pipeline needs to
merge candidate lists with byte-identical ordering to upstream's pre-sort
scan. Wiring callers over to this comparator is left to follow-up tasks.

Includes a `name_cmp_eq` helper that tolerates a single trailing `/` on
the basename to mirror upstream's implicit directory-slash equivalence,
and a components-only `f_name_cmp_components` helper for callers and
fuzzers that already hold dirname/basename byte slices.

Unit tests cover ASCII ordering, same-basename/different-dirname,
high-byte unsigned order (>= 0x80), dot/double-dot, hidden dotfiles,
embedded slashes, deep nesting, and the file-vs-dir byte-only fold.
Proptest covers reflexivity, antisymmetry, transitivity, and agreement
with the components helper.

Upstream references:
  - flist.c:3197 enum fnc_state
  - flist.c:3198 enum fnc_type
  - flist.c:3217-3334 f_name_cmp()
  - flist.c:3331 (int)*c1++ - (int)*c2++  (unsigned byte compare)
oferchen added a commit that referenced this pull request May 18, 2026
…lel deterministic delete (#2253, #2254) (#4259)

* feat(engine): DeletePlan, DeletePlanMap, DirTraversalCursor (#2253, #2254)

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline described in docs/design/parallel-deterministic-delete.md
(PR #4257). Three new modules under crates/engine/src/delete/:

- plan.rs: DeletePlan (sorted, frozen per-directory work item),
  DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and a
  HardlinkCohortId newtype. sort_by_name() uses upstream's f_name_cmp
  (PR #4256) ascending then reverses, matching delete_in_dir's loop
  at generator.c:320.
- plan_map.rs: DeletePlanMap, the publish-once concurrent rendezvous
  between phase-1 workers and the phase-2 emitter. Backed by
  Mutex<HashMap> for now; bench-driven choice between Mutex,
  DashMap, and a sharded map is deferred to task DDP-B4 (see code
  comment).
- traversal.rs: DirTraversalCursor, yields directories in upstream's
  depth-first f_name_cmp-ascending order. Tree built from observed
  flist segments via observe_segment(); next_ready() returns the
  next directory whose parent has been emitted.

Pure data structures, no callers; phase-1 and phase-2 wiring lands in
later tasks (#2255-#2278). Unit tests cover plan ordering, concurrent
inserts and takes from 16 threads, out-of-order segment observation,
non-directory filtering, duplicate observations, and high-byte
basename ordering on Unix.

* fix(engine): avoid borrow-checker conflict in DirTraversalCursor::next_ready

Splits the frame inspection from the mutation so the mutable borrow of
the top frame is released before pushing a new frame or popping the
old one. Functionally equivalent.
oferchen added a commit that referenced this pull request May 18, 2026
…2252) (#4256)

Adds a foundational `f_name_cmp` that compares two `FileEntry` values by
`(dirname, basename)` in unsigned byte order, mirroring upstream rsync's
`flist.c:f_name_cmp()`. Bytes with the high bit set sort after ASCII; no
locale awareness, no case folding, no protocol-29 file-vs-directory
disambiguation (that logic stays in `sort.rs`).

This is the sort key the parallel-deterministic-delete pipeline needs to
merge candidate lists with byte-identical ordering to upstream's pre-sort
scan. Wiring callers over to this comparator is left to follow-up tasks.

Includes a `name_cmp_eq` helper that tolerates a single trailing `/` on
the basename to mirror upstream's implicit directory-slash equivalence,
and a components-only `f_name_cmp_components` helper for callers and
fuzzers that already hold dirname/basename byte slices.

Unit tests cover ASCII ordering, same-basename/different-dirname,
high-byte unsigned order (>= 0x80), dot/double-dot, hidden dotfiles,
embedded slashes, deep nesting, and the file-vs-dir byte-only fold.
Proptest covers reflexivity, antisymmetry, transitivity, and agreement
with the components helper.

Upstream references:
  - flist.c:3197 enum fnc_state
  - flist.c:3198 enum fnc_type
  - flist.c:3217-3334 f_name_cmp()
  - flist.c:3331 (int)*c1++ - (int)*c2++  (unsigned byte compare)
oferchen added a commit that referenced this pull request May 18, 2026
…lel deterministic delete (#2253, #2254) (#4259)

* feat(engine): DeletePlan, DeletePlanMap, DirTraversalCursor (#2253, #2254)

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline described in docs/design/parallel-deterministic-delete.md
(PR #4257). Three new modules under crates/engine/src/delete/:

- plan.rs: DeletePlan (sorted, frozen per-directory work item),
  DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and a
  HardlinkCohortId newtype. sort_by_name() uses upstream's f_name_cmp
  (PR #4256) ascending then reverses, matching delete_in_dir's loop
  at generator.c:320.
- plan_map.rs: DeletePlanMap, the publish-once concurrent rendezvous
  between phase-1 workers and the phase-2 emitter. Backed by
  Mutex<HashMap> for now; bench-driven choice between Mutex,
  DashMap, and a sharded map is deferred to task DDP-B4 (see code
  comment).
- traversal.rs: DirTraversalCursor, yields directories in upstream's
  depth-first f_name_cmp-ascending order. Tree built from observed
  flist segments via observe_segment(); next_ready() returns the
  next directory whose parent has been emitted.

Pure data structures, no callers; phase-1 and phase-2 wiring lands in
later tasks (#2255-#2278). Unit tests cover plan ordering, concurrent
inserts and takes from 16 threads, out-of-order segment observation,
non-directory filtering, duplicate observations, and high-byte
basename ordering on Unix.

* fix(engine): avoid borrow-checker conflict in DirTraversalCursor::next_ready

Splits the frame inspection from the mutation so the mutable borrow of
the top frame is released before pushing a new frame or popping the
old one. Functionally equivalent.
@oferchen
oferchen deleted the feat/upstream-f-name-cmp-2252 branch May 19, 2026 19:28
oferchen added a commit that referenced this pull request Aug 24, 2026
…2252) (#4256)

Adds a foundational `f_name_cmp` that compares two `FileEntry` values by
`(dirname, basename)` in unsigned byte order, mirroring upstream rsync's
`flist.c:f_name_cmp()`. Bytes with the high bit set sort after ASCII; no
locale awareness, no case folding, no protocol-29 file-vs-directory
disambiguation (that logic stays in `sort.rs`).

This is the sort key the parallel-deterministic-delete pipeline needs to
merge candidate lists with byte-identical ordering to upstream's pre-sort
scan. Wiring callers over to this comparator is left to follow-up tasks.

Includes a `name_cmp_eq` helper that tolerates a single trailing `/` on
the basename to mirror upstream's implicit directory-slash equivalence,
and a components-only `f_name_cmp_components` helper for callers and
fuzzers that already hold dirname/basename byte slices.

Unit tests cover ASCII ordering, same-basename/different-dirname,
high-byte unsigned order (>= 0x80), dot/double-dot, hidden dotfiles,
embedded slashes, deep nesting, and the file-vs-dir byte-only fold.
Proptest covers reflexivity, antisymmetry, transitivity, and agreement
with the components helper.

Upstream references:
  - flist.c:3197 enum fnc_state
  - flist.c:3198 enum fnc_type
  - flist.c:3217-3334 f_name_cmp()
  - flist.c:3331 (int)*c1++ - (int)*c2++  (unsigned byte compare)
oferchen added a commit that referenced this pull request Aug 24, 2026
…lel deterministic delete (#2253, #2254) (#4259)

* feat(engine): DeletePlan, DeletePlanMap, DirTraversalCursor (#2253, #2254)

Adds the data-structure foundation for the parallel-deterministic-delete
pipeline described in docs/design/parallel-deterministic-delete.md
(PR #4257). Three new modules under crates/engine/src/delete/:

- plan.rs: DeletePlan (sorted, frozen per-directory work item),
  DeleteEntry, DeleteEntryKind (mirrors DeleteStats buckets), and a
  HardlinkCohortId newtype. sort_by_name() uses upstream's f_name_cmp
  (PR #4256) ascending then reverses, matching delete_in_dir's loop
  at generator.c:320.
- plan_map.rs: DeletePlanMap, the publish-once concurrent rendezvous
  between phase-1 workers and the phase-2 emitter. Backed by
  Mutex<HashMap> for now; bench-driven choice between Mutex,
  DashMap, and a sharded map is deferred to task DDP-B4 (see code
  comment).
- traversal.rs: DirTraversalCursor, yields directories in upstream's
  depth-first f_name_cmp-ascending order. Tree built from observed
  flist segments via observe_segment(); next_ready() returns the
  next directory whose parent has been emitted.

Pure data structures, no callers; phase-1 and phase-2 wiring lands in
later tasks (#2255-#2278). Unit tests cover plan ordering, concurrent
inserts and takes from 16 threads, out-of-order segment observation,
non-directory filtering, duplicate observations, and high-byte
basename ordering on Unix.

* fix(engine): avoid borrow-checker conflict in DirTraversalCursor::next_ready

Splits the frame inspection from the mutation so the mutable borrow of
the top frame is released before pushing a new frame or popping the
old one. Functionally equivalent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant