Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(globset): better way to see if ALL globs match #2869

Open
tmccombs opened this issue Aug 12, 2024 · 0 comments · May be fixed by #2900
Open

feat(globset): better way to see if ALL globs match #2869

tmccombs opened this issue Aug 12, 2024 · 0 comments · May be fixed by #2900

Comments

@tmccombs
Copy link
Contributor

A have a use case where I have a set of 1 or more globs, and want to know if all of them match, rather than if any of them match.

I can of course use a Vec<Glob> and do something like globs.iter().all(|g| g.is_match(path)), but it sounds like using a GlobSet may be more efficient, since it can use a single pass.

I think I can accomplish this with glob_set.matches(path).len() == glob_set.len(), but then it has to allocate a Vec, and then I just throw it away, because I only care about the length.

Possible ways this could be improved are:

  1. Add a matches_all method that returns true if all globs match (fwiw, I'd also like that on RegexSet)
  2. Return an iterator similar to how RegexSet.matches returns an iterator, so it can be counted instead of storing in a Vec.
tmccombs added a commit to tmccombs/ripgrep that referenced this issue Sep 19, 2024
This returns true if all globs in the set match the supplied file.

Fixes: BurntSushi#2869
@tmccombs tmccombs linked a pull request Sep 19, 2024 that will close this issue
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 a pull request may close this issue.

1 participant