fix: replace substring pattern matching with globset in FileWalker#21
Open
oudeis01 wants to merge 1 commit into
Open
fix: replace substring pattern matching with globset in FileWalker#21oudeis01 wants to merge 1 commit into
oudeis01 wants to merge 1 commit into
Conversation
matches_patterns() used path_str.contains(pattern), treating every pattern as a literal substring. Patterns like "**/vendor/**" never matched any path because the string "**/vendor/**" is not a substring of real file paths, making exclude_patterns effectively broken for glob-style inputs. globset is already a declared dependency. This change: - Adds build_glob_set() to compile patterns into a GlobSet once on construction rather than on every call to matches_patterns(). - Rewrites matches_patterns() to match against the path relative to the walk root, so patterns behave correctly regardless of where the root directory sits in the filesystem. - Updates tests to use glob-style patterns (e.g. **/*.rs, **/target/**) that reflect actual usage.
|
Please merge. Include and exclude patterns don't work currently |
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.
Problem
matches_patterns()usedpath_str.contains(pattern)to check include and exclude patterns. This treats every pattern as a literal substring, so glob-style inputs like**/vendor/**or**/*.rsnever match any real path -- the string"**/vendor/**"is simply not a substring of"project/vendor/foo.c".The
globsetcrate is already a declared dependency inCargo.tomlbut was unused in this module.Fix
build_glob_set()to compile patterns into aGlobSetonce inwith_patterns(), avoiding recompilation on every call tomatches_patterns().matches_patterns()to match against the path relative to the walk root, so patterns behave correctly regardless of where the root directory sits in the filesystem.**/*.rs,**/target/**, etc.) that reflect real-world usage.Test plan
cargo test --lib indexer::file_walkerpasses (34 tests)exclude_patterns: ["**/vendor/**"]correctly skips vendored filesinclude_patterns: ["**/*.rs"]correctly includes only Rust files