Skip to content

Split the Rust wildmatch port into smaller functions - #2703

Closed
somewhatabstract wants to merge 3 commits into
mainfrom
claude/jolly-galileo-72zesp-wildmatch-split
Closed

somewhatabstract wants to merge 3 commits into
mainfrom
claude/jolly-galileo-72zesp-wildmatch-split

Conversation

@somewhatabstract

Copy link
Copy Markdown
Owner

The Rust port of git's wildmatch was one long dowild function with nested loops for *, which was hard to follow. This splits it into named steps, each in its own file with its own tests. Behaviour doesn't change.

  • match_wild_from walks the pattern and text together, as dowild did.
  • match_star handles a run of * and what follows it.
  • read_star_run works out whether a run of * can cross /.
  • try_star_start_points tries each place a * could stop.
  • skip_to_literal skips ahead to the literal byte after a *.
  • byte_at, fold_byte and find_slash are the small byte helpers they share.

The new shared types are in types.rs. This is the first of five PRs for get_files in Rust (#2615). The next ones add brace expansion and a dotfile option to this matcher.

Test plan

  • I ran the restructured code against git's C wildmatch on the same 300,000 random cases as before, and the results are identical.
  • Read match_wild_from and match_star side by side with git's dowild and check that they follow it.

Generated by Claude Code

dowild was one long function with nested loops for `*`. It's now split
into named steps, each with its own tests, and behaves exactly as before:

- match_wild_from walks the pattern and text, as dowild did.
- match_star handles a run of `*` and what follows it.
- read_star_run works out whether a run of `*` can cross `/`.
- try_star_start_points tries each place a `*` could stop.
- skip_to_literal skips ahead to the literal byte after a `*`.
- byte_at, fold_byte and find_slash are the small byte helpers they share.

The match outcome, the pattern and text with their options, and the two
`*` results are types in types.rs. The results still match git's C
wildmatch on 300,000 random cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QjLhVH1NnUc7MzCSYLd8Yn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QjLhVH1NnUc7MzCSYLd8Yn
@changeset-bot

changeset-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 430a9ef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e4aa2ac) to head (430a9ef).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              main     #2703    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           93       101     +8     
  Lines         3177      3513   +336     
  Branches      2383      2721   +338     
==========================================
+ Hits          3177      3513   +336     
Flag Coverage Δ
rust 100.00% <100.00%> (ø)
typescript 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
rust/crates/checksync-core/src/byte_at.rs 100.00% <100.00%> (ø)
rust/crates/checksync-core/src/find_slash.rs 100.00% <100.00%> (ø)
rust/crates/checksync-core/src/fold_byte.rs 100.00% <100.00%> (ø)
rust/crates/checksync-core/src/match_star.rs 100.00% <100.00%> (ø)
rust/crates/checksync-core/src/match_wild_from.rs 100.00% <100.00%> (ø)
rust/crates/checksync-core/src/read_star_run.rs 100.00% <100.00%> (ø)
rust/crates/checksync-core/src/skip_to_literal.rs 100.00% <100.00%> (ø)
...crates/checksync-core/src/try_star_start_points.rs 100.00% <100.00%> (ø)
rust/crates/checksync-core/src/types.rs 100.00% <ø> (ø)
rust/crates/checksync-core/src/wildmatch.rs 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e4aa2ac...430a9ef. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

- Keep each doc summary to one line.
- find_slash returns None past the end of the text rather than panicking.
- skip_to_literal's doc says it never finds a `/` for a `*` that can't
  match one, which callers handle first.
- read_star_run works out match_slash in one place.
- try_star_start_points reads the byte after the `*` once, before its loop.

The results still match git's C wildmatch on 300,000 random cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QjLhVH1NnUc7MzCSYLd8Yn

Copy link
Copy Markdown
Owner Author

I'm closing this unmerged. The Rust wildmatch code it restructures is a line-for-line port of git's wildmatch.c, and the gitignore pattern code is a port of functions from git's dir.c. Both are under git's GPL v2, and checksync is MIT. They're being replaced with a clean-room implementation, written only from documentation, our conformance tables and git's behaviour as a black box, so there's no point restructuring the ported code first.


Generated by Claude Code

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.

2 participants