Skip to content

fix(rg): apply max-count after multiline invert#1752

Merged
chaliy merged 1 commit into
mainfrom
2026-05-25-fix-rg-multiline-invert-to-respect-max-count
May 25, 2026
Merged

fix(rg): apply max-count after multiline invert#1752
chaliy merged 1 commit into
mainfrom
2026-05-25-fix-rg-multiline-invert-to-respect-max-count

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented May 25, 2026

Motivation

  • Multiline --invert-match was passing opts.max_count into positive-span collection, truncating positive spans before inversion and producing too much inverted output.
  • Goal is to match ripgrep semantics: collect all positive multiline spans, then apply -m/--max-count to the inverted result.

Description

  • In crates/bashkit/src/builtins/rg/mod.rs call collect_rg_multiline_matches with None when opts.invert_match so positive spans are fully collected instead of truncated by opts.max_count.
  • After building inverted_match_lines, apply opts.max_count by truncating the vector to enforce the max-count limit on inverted output.
  • Added a focused regression test test_rg_multiline_invert_max_count in crates/bashkit/src/builtins/rg/mod.rs that verifies -m 1 -v -U 'foo\nbar' returns only the first inverted line.

Testing

  • Added unit test test_rg_multiline_invert_max_count which reproduces the reported regression and asserts expected output.
  • Ran cargo test -p bashkit test_rg_multiline_invert_max_count -- --nocapture and the test passed (1 passed; 0 failed).

Codex Task

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 25, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 842647e Commit Preview URL May 25 2026, 04:31 PM

Multiline --invert-match was passing opts.max_count into positive-span
collection, truncating positive spans before inversion and producing
too much inverted output. Match ripgrep: collect all positive spans,
then apply -m/--max-count to the inverted result.

Rebased on current main; original PR #1752 by chaliy.
@chaliy chaliy force-pushed the 2026-05-25-fix-rg-multiline-invert-to-respect-max-count branch from 39160da to 842647e Compare May 25, 2026 15:08
@chaliy chaliy merged commit 1041fda into main May 25, 2026
33 checks passed
@chaliy chaliy deleted the 2026-05-25-fix-rg-multiline-invert-to-respect-max-count branch May 25, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant