Skip to content

fix(filters): parse :C modifier on per-directory merge rules for CVS-ignore - #5842

Merged
oferchen merged 7 commits into
masterfrom
fix/uts-merge-c-modifier-parse
Jun 16, 2026
Merged

oferchen merged 7 commits into
masterfrom
fix/uts-merge-c-modifier-parse

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

When a filter file read from disk (e.g. a .rsync-filter or per-directory
merge file like mid/.filt) contains a :C (or .C) directive with an
empty pattern, oc-rsync's filters::parse_rules parser rejected it as
unrecognized filter rule instead of defaulting the filename to
.cvsignore, and the C (CVS-ignore) modifier was never propagated from
RuleModifiers onto the resulting FilterRule. The wire-format path
(transfer::generator::filters::wire_rule_to_dir_merge_config) and the
CLI argv path (crates/cli/.../parsing/merge.rs) already handle :C
correctly; only the merge-file-on-disk path was broken. The failing
upstream merge.test and exclude-lsh.test scenarios depend on this
short form. Tracks task #4428 (UTS-V4.B).

Changes

  • FilterRule gains a cvs_mode: bool field with builder
    with_cvs_mode and accessor is_cvs_mode.
  • RuleModifiers::apply propagates cvs_mode onto the rule.
  • try_parse_short_form in crates/filters/src/merge/parse.rs
    special-cases empty pattern with cvs_mode set on Merge/DirMerge
    and defaults to .cvsignore.
  • Destructure in crates/filters/src/compiled/mod.rs updated to accept
    the new field via cvs_mode: _.
  • Three regression tests in crates/filters/src/merge/tests.rs cover
    :C\n, :C my.ignore\n, and .C\n.

Upstream references

  • target/interop/upstream-src/rsync-3.4.4/exclude.c:1248-1255 -- :C
    sets FILTRULE_NO_PREFIXES | FILTRULE_WORD_SPLIT | FILTRULE_NO_INHERIT | FILTRULE_CVS_IGNORE.
  • target/interop/upstream-src/rsync-3.4.4/exclude.c:1324 -- empty
    pattern is only an error when FILTRULE_CVS_IGNORE is unset.
  • target/interop/upstream-src/rsync-3.4.4/exclude.c:1404-1408 --
    empty-pattern merge defaults to .cvsignore.
  • target/interop/upstream-src/rsync-3.4.4/testsuite/merge.test and
    testsuite/exclude-lsh.test:86-88 -- failing fixtures.

Test plan

  • cargo fmt --all
  • cargo check -p filters --all-features (clean)
  • CI full nextest matrix
  • Upstream merge.test and exclude-lsh.test re-run on Linux host

Notes

Task tracker #4428. Audit document referenced as the spec source.
The pre-existing PR #5817 is orthogonal: it changes the post-load
scope-evaluation path; this PR fixes the pre-load parse path. They
can land independently.

…ignore

When a per-directory merge rule uses the `:C` (or `.C`) short form with
an empty pattern, the parser rejected it as "unrecognized filter rule"
instead of defaulting the filename to `.cvsignore`, and the `C`
(CVS-ignore) modifier was never propagated from `RuleModifiers` onto the
resulting `FilterRule`. The wire-format path and the CLI `--filter :C`
path already handle this correctly; only merge files read from disk via
`parse_rules` (e.g. `mid/.filt`) were affected. This breaks the upstream
`merge` and `exclude-lsh` testsuite scenarios (task #4428, UTS-V4.B).

Add a `cvs_mode` flag to `FilterRule` with a `with_cvs_mode` builder and
`is_cvs_mode` accessor; propagate it through `RuleModifiers::apply`; and
in `try_parse_short_form`, when a `:`/`.` rule has empty pattern and the
`C` modifier set, default to the filename `.cvsignore`.

upstream references (rsync-3.4.4):
  - exclude.c:1248-1255: `:C` sets FILTRULE_NO_PREFIXES |
    FILTRULE_WORD_SPLIT | FILTRULE_NO_INHERIT | FILTRULE_CVS_IGNORE.
  - exclude.c:1324: empty pattern only errors when FILTRULE_CVS_IGNORE
    is unset.
  - exclude.c:1404-1408: empty-pattern merge defaults to `.cvsignore`.
  - testsuite/merge.test, testsuite/exclude-lsh.test:86-88: failing
    fixtures.
@github-actions github-actions Bot added the bug Something isn't working label Jun 15, 2026
oferchen added 6 commits June 16, 2026 03:32
The :C modifier work added a cvs_mode field to FilterRule but missed
the test-side struct literal initializations in crates/filters/src/
compiled/{clear,mod,rule}.rs. The build now fails with E0063 because
those literals omit the new field.

Add cvs_mode: false to every FilterRule struct literal in those test
modules so the field set matches the public struct definition.
@oferchen

Copy link
Copy Markdown
Owner Author

NACK — testsuite/exclude-lsh.test still shows FAIL exclude-lsh (exit 1) on this branch.

Root cause: the parsing fix is incomplete. When /mid/.filt contains :C, the rule is parsed (with cvs_mode flag) but never triggers the runtime loading of /mid/.cvsignore. Two gaps:

  1. crates/filters/src/merge/parse.rs:151-157 — RuleModifiers::apply() never calls .with_cvs_mode(self.cvs_mode), so the parsed flag doesn't propagate to the FilterRule.
  2. crates/filters/src/chain/mod.rs:260-263 — After a merge file is loaded, its rules are compiled into a FilterSet without scanning for nested DirMerge actions. The new :C rule never causes .cvsignore to be loaded at directory entry.

For a complete fix: when loading a merge file, walk its rules for FilterAction::DirMerge, extract pattern + cvs_mode, register a new DirMergeConfig, and trigger enter_directory semantics for the nested file. Verify locally with bash testsuite/exclude-lsh.test before re-pushing.

@oferchen
oferchen merged commit 6856737 into master Jun 16, 2026
65 of 67 checks passed
oferchen added a commit that referenced this pull request Jun 16, 2026
…o .cvsignore

PR #5842 fixed the merge-file parser to accept a bare `:C` line by
adding `cvs_mode` to `FilterRule`. Two related wire-side gaps still let
the upstream `exclude` / `exclude-lsh` testsuite fail when `-f:C -f-C`
is invoked over remote shell:

- `build_wire_format_rules` ignored the `C` modifier when encoding a
  DirMerge spec, because `DirMergeOptions` had no dedicated cvs-mode
  bit. The CLI parsed `:C` correctly, but `cvs_exclude` was always
  false on the wire, so the remote sender never saw the `C` flag.
- `wire_rule_to_dir_merge_config` did not implement upstream
  `exclude.c:1404-1408`'s "empty pattern defaults to `.cvsignore`"
  fallback, so a wire rule like `:C ` (cvs_exclude set, no pattern)
  produced a `DirMergeConfig` with an empty filename and silently
  disabled per-directory `.cvsignore` lookup.

Add a `cvs_mode` field to `DirMergeOptions` with `cvs_mode()` /
`is_cvs_mode()` accessors, set it from the CLI `parse_merge_modifiers`
`C` branch, forward it as `cvs_exclude=true` in `build_wire_format_rules`,
and substitute `.cvsignore` as the default pattern inside
`wire_rule_to_dir_merge_config` when the wire rule has cvs_exclude set
with no pattern.
oferchen added a commit that referenced this pull request Jun 16, 2026
…o .cvsignore

PR #5842 fixed the merge-file parser to accept a bare `:C` line by
adding `cvs_mode` to `FilterRule`. Two related wire-side gaps still let
the upstream `exclude` / `exclude-lsh` testsuite fail when `-f:C -f-C`
is invoked over remote shell:

- `build_wire_format_rules` ignored the `C` modifier when encoding a
  DirMerge spec, because `DirMergeOptions` had no dedicated cvs-mode
  bit. The CLI parsed `:C` correctly, but `cvs_exclude` was always
  false on the wire, so the remote sender never saw the `C` flag.
- `wire_rule_to_dir_merge_config` did not implement upstream
  `exclude.c:1404-1408`'s "empty pattern defaults to `.cvsignore`"
  fallback, so a wire rule like `:C ` (cvs_exclude set, no pattern)
  produced a `DirMergeConfig` with an empty filename and silently
  disabled per-directory `.cvsignore` lookup.

Add a `cvs_mode` field to `DirMergeOptions` with `cvs_mode()` /
`is_cvs_mode()` accessors, set it from the CLI `parse_merge_modifiers`
`C` branch, forward it as `cvs_exclude=true` in `build_wire_format_rules`,
and substitute `.cvsignore` as the default pattern inside
`wire_rule_to_dir_merge_config` when the wire rule has cvs_exclude set
with no pattern.
oferchen added a commit that referenced this pull request Jun 17, 2026
…o .cvsignore

PR #5842 fixed the merge-file parser to accept a bare `:C` line by
adding `cvs_mode` to `FilterRule`. Two related wire-side gaps still let
the upstream `exclude` / `exclude-lsh` testsuite fail when `-f:C -f-C`
is invoked over remote shell:

- `build_wire_format_rules` ignored the `C` modifier when encoding a
  DirMerge spec, because `DirMergeOptions` had no dedicated cvs-mode
  bit. The CLI parsed `:C` correctly, but `cvs_exclude` was always
  false on the wire, so the remote sender never saw the `C` flag.
- `wire_rule_to_dir_merge_config` did not implement upstream
  `exclude.c:1404-1408`'s "empty pattern defaults to `.cvsignore`"
  fallback, so a wire rule like `:C ` (cvs_exclude set, no pattern)
  produced a `DirMergeConfig` with an empty filename and silently
  disabled per-directory `.cvsignore` lookup.

Add a `cvs_mode` field to `DirMergeOptions` with `cvs_mode()` /
`is_cvs_mode()` accessors, set it from the CLI `parse_merge_modifiers`
`C` branch, forward it as `cvs_exclude=true` in `build_wire_format_rules`,
and substitute `.cvsignore` as the default pattern inside
`wire_rule_to_dir_merge_config` when the wire rule has cvs_exclude set
with no pattern.
oferchen added a commit that referenced this pull request Jun 17, 2026
…o .cvsignore

PR #5842 fixed the merge-file parser to accept a bare `:C` line by
adding `cvs_mode` to `FilterRule`. Two related wire-side gaps still let
the upstream `exclude` / `exclude-lsh` testsuite fail when `-f:C -f-C`
is invoked over remote shell:

- `build_wire_format_rules` ignored the `C` modifier when encoding a
  DirMerge spec, because `DirMergeOptions` had no dedicated cvs-mode
  bit. The CLI parsed `:C` correctly, but `cvs_exclude` was always
  false on the wire, so the remote sender never saw the `C` flag.
- `wire_rule_to_dir_merge_config` did not implement upstream
  `exclude.c:1404-1408`'s "empty pattern defaults to `.cvsignore`"
  fallback, so a wire rule like `:C ` (cvs_exclude set, no pattern)
  produced a `DirMergeConfig` with an empty filename and silently
  disabled per-directory `.cvsignore` lookup.

Add a `cvs_mode` field to `DirMergeOptions` with `cvs_mode()` /
`is_cvs_mode()` accessors, set it from the CLI `parse_merge_modifiers`
`C` branch, forward it as `cvs_exclude=true` in `build_wire_format_rules`,
and substitute `.cvsignore` as the default pattern inside
`wire_rule_to_dir_merge_config` when the wire rule has cvs_exclude set
with no pattern.
oferchen added a commit that referenced this pull request Jun 17, 2026
…o .cvsignore

PR #5842 fixed the merge-file parser to accept a bare `:C` line by
adding `cvs_mode` to `FilterRule`. Two related wire-side gaps still let
the upstream `exclude` / `exclude-lsh` testsuite fail when `-f:C -f-C`
is invoked over remote shell:

- `build_wire_format_rules` ignored the `C` modifier when encoding a
  DirMerge spec, because `DirMergeOptions` had no dedicated cvs-mode
  bit. The CLI parsed `:C` correctly, but `cvs_exclude` was always
  false on the wire, so the remote sender never saw the `C` flag.
- `wire_rule_to_dir_merge_config` did not implement upstream
  `exclude.c:1404-1408`'s "empty pattern defaults to `.cvsignore`"
  fallback, so a wire rule like `:C ` (cvs_exclude set, no pattern)
  produced a `DirMergeConfig` with an empty filename and silently
  disabled per-directory `.cvsignore` lookup.

Add a `cvs_mode` field to `DirMergeOptions` with `cvs_mode()` /
`is_cvs_mode()` accessors, set it from the CLI `parse_merge_modifiers`
`C` branch, forward it as `cvs_exclude=true` in `build_wire_format_rules`,
and substitute `.cvsignore` as the default pattern inside
`wire_rule_to_dir_merge_config` when the wire rule has cvs_exclude set
with no pattern.
oferchen added a commit that referenced this pull request Jun 17, 2026
…o .cvsignore

PR #5842 fixed the merge-file parser to accept a bare `:C` line by
adding `cvs_mode` to `FilterRule`. Two related wire-side gaps still let
the upstream `exclude` / `exclude-lsh` testsuite fail when `-f:C -f-C`
is invoked over remote shell:

- `build_wire_format_rules` ignored the `C` modifier when encoding a
  DirMerge spec, because `DirMergeOptions` had no dedicated cvs-mode
  bit. The CLI parsed `:C` correctly, but `cvs_exclude` was always
  false on the wire, so the remote sender never saw the `C` flag.
- `wire_rule_to_dir_merge_config` did not implement upstream
  `exclude.c:1404-1408`'s "empty pattern defaults to `.cvsignore`"
  fallback, so a wire rule like `:C ` (cvs_exclude set, no pattern)
  produced a `DirMergeConfig` with an empty filename and silently
  disabled per-directory `.cvsignore` lookup.

Add a `cvs_mode` field to `DirMergeOptions` with `cvs_mode()` /
`is_cvs_mode()` accessors, set it from the CLI `parse_merge_modifiers`
`C` branch, forward it as `cvs_exclude=true` in `build_wire_format_rules`,
and substitute `.cvsignore` as the default pattern inside
`wire_rule_to_dir_merge_config` when the wire rule has cvs_exclude set
with no pattern.
oferchen added a commit that referenced this pull request Jun 17, 2026
…5817)

* fix(filters): fall through to outer scopes when non-inheriting scope has no match

Per-directory filter scope evaluation could short-circuit on a synthetic
`pattern/**` descendant matcher (compiled for anchored excludes like
`- /bar`) and return the inner scope's traversal-mode decision before
the outer scope's real user-written rule could fire.

Replace the previous `has_matching_rule` helper - which called the
public `allows_during_traversal` and `allows_deletion` and so saw the
descendant optimisation - with two context-aware predicates that only
consider real direct matchers. This mirrors upstream
`exclude.c:rule_matches()`, which has no descendant matching at all -
descendant exclusion is a side effect of the sender walk not descending
into excluded directories. Both the Transfer (`allows`) and Deletion
(`allows_deletion`) paths now fall through to outer scopes when the
current scope contains no real rule matching the path, and continue to
honour protect/risk rules on the deletion side.

Add regression coverage that pins the inner-scope descendant fall-
through, root-level rule propagation through silent per-dir scopes,
`:C`-style non-inheriting scope fall-through, and the symmetric
deletion-side behaviour.

* fix(filters): forward :C cvs_mode on wire and default empty pattern to .cvsignore

PR #5842 fixed the merge-file parser to accept a bare `:C` line by
adding `cvs_mode` to `FilterRule`. Two related wire-side gaps still let
the upstream `exclude` / `exclude-lsh` testsuite fail when `-f:C -f-C`
is invoked over remote shell:

- `build_wire_format_rules` ignored the `C` modifier when encoding a
  DirMerge spec, because `DirMergeOptions` had no dedicated cvs-mode
  bit. The CLI parsed `:C` correctly, but `cvs_exclude` was always
  false on the wire, so the remote sender never saw the `C` flag.
- `wire_rule_to_dir_merge_config` did not implement upstream
  `exclude.c:1404-1408`'s "empty pattern defaults to `.cvsignore`"
  fallback, so a wire rule like `:C ` (cvs_exclude set, no pattern)
  produced a `DirMergeConfig` with an empty filename and silently
  disabled per-directory `.cvsignore` lookup.

Add a `cvs_mode` field to `DirMergeOptions` with `cvs_mode()` /
`is_cvs_mode()` accessors, set it from the CLI `parse_merge_modifiers`
`C` branch, forward it as `cvs_exclude=true` in `build_wire_format_rules`,
and substitute `.cvsignore` as the default pattern inside
`wire_rule_to_dir_merge_config` when the wire rule has cvs_exclude set
with no pattern.
@oferchen
oferchen deleted the fix/uts-merge-c-modifier-parse branch June 17, 2026 12:51
oferchen added a commit that referenced this pull request Aug 24, 2026
…ignore (#5842)

* fix(filters): parse :C modifier on per-directory merge rules for CVS-ignore

When a per-directory merge rule uses the `:C` (or `.C`) short form with
an empty pattern, the parser rejected it as "unrecognized filter rule"
instead of defaulting the filename to `.cvsignore`, and the `C`
(CVS-ignore) modifier was never propagated from `RuleModifiers` onto the
resulting `FilterRule`. The wire-format path and the CLI `--filter :C`
path already handle this correctly; only merge files read from disk via
`parse_rules` (e.g. `mid/.filt`) were affected. This breaks the upstream
`merge` and `exclude-lsh` testsuite scenarios (task #4428, UTS-V4.B).

Add a `cvs_mode` flag to `FilterRule` with a `with_cvs_mode` builder and
`is_cvs_mode` accessor; propagate it through `RuleModifiers::apply`; and
in `try_parse_short_form`, when a `:`/`.` rule has empty pattern and the
`C` modifier set, default to the filename `.cvsignore`.

upstream references (rsync-3.4.4):
  - exclude.c:1248-1255: `:C` sets FILTRULE_NO_PREFIXES |
    FILTRULE_WORD_SPLIT | FILTRULE_NO_INHERIT | FILTRULE_CVS_IGNORE.
  - exclude.c:1324: empty pattern only errors when FILTRULE_CVS_IGNORE
    is unset.
  - exclude.c:1404-1408: empty-pattern merge defaults to `.cvsignore`.
  - testsuite/merge.test, testsuite/exclude-lsh.test:86-88: failing
    fixtures.

* fix(filters): backfill cvs_mode in FilterRule struct literals

The :C modifier work added a cvs_mode field to FilterRule but missed
the test-side struct literal initializations in crates/filters/src/
compiled/{clear,mod,rule}.rs. The build now fails with E0063 because
those literals omit the new field.

Add cvs_mode: false to every FilterRule struct literal in those test
modules so the field set matches the public struct definition.
oferchen added a commit that referenced this pull request Aug 24, 2026
…5817)

* fix(filters): fall through to outer scopes when non-inheriting scope has no match

Per-directory filter scope evaluation could short-circuit on a synthetic
`pattern/**` descendant matcher (compiled for anchored excludes like
`- /bar`) and return the inner scope's traversal-mode decision before
the outer scope's real user-written rule could fire.

Replace the previous `has_matching_rule` helper - which called the
public `allows_during_traversal` and `allows_deletion` and so saw the
descendant optimisation - with two context-aware predicates that only
consider real direct matchers. This mirrors upstream
`exclude.c:rule_matches()`, which has no descendant matching at all -
descendant exclusion is a side effect of the sender walk not descending
into excluded directories. Both the Transfer (`allows`) and Deletion
(`allows_deletion`) paths now fall through to outer scopes when the
current scope contains no real rule matching the path, and continue to
honour protect/risk rules on the deletion side.

Add regression coverage that pins the inner-scope descendant fall-
through, root-level rule propagation through silent per-dir scopes,
`:C`-style non-inheriting scope fall-through, and the symmetric
deletion-side behaviour.

* fix(filters): forward :C cvs_mode on wire and default empty pattern to .cvsignore

PR #5842 fixed the merge-file parser to accept a bare `:C` line by
adding `cvs_mode` to `FilterRule`. Two related wire-side gaps still let
the upstream `exclude` / `exclude-lsh` testsuite fail when `-f:C -f-C`
is invoked over remote shell:

- `build_wire_format_rules` ignored the `C` modifier when encoding a
  DirMerge spec, because `DirMergeOptions` had no dedicated cvs-mode
  bit. The CLI parsed `:C` correctly, but `cvs_exclude` was always
  false on the wire, so the remote sender never saw the `C` flag.
- `wire_rule_to_dir_merge_config` did not implement upstream
  `exclude.c:1404-1408`'s "empty pattern defaults to `.cvsignore`"
  fallback, so a wire rule like `:C ` (cvs_exclude set, no pattern)
  produced a `DirMergeConfig` with an empty filename and silently
  disabled per-directory `.cvsignore` lookup.

Add a `cvs_mode` field to `DirMergeOptions` with `cvs_mode()` /
`is_cvs_mode()` accessors, set it from the CLI `parse_merge_modifiers`
`C` branch, forward it as `cvs_exclude=true` in `build_wire_format_rules`,
and substitute `.cvsignore` as the default pattern inside
`wire_rule_to_dir_merge_config` when the wire rule has cvs_exclude set
with no pattern.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant