Implement a glob to regexp/re2 transpiler
Problem to solve
Various parts of the product implement glob matches, but inconsistently:
- Some parts use
File.fnmatch?- This is fine for one-off matches, but performs worse than regular expressions for repeated searches against the same pattern
- Others transpile a subset to regular expressions (example)
- This is problematic because users now need to know which glob implementation is used where
- Some may pass the glob off to an external system for matching
- This is out of scope of the issue, but worth keeping in mind
Proposal
- Write a
globset-like ruby gem that can output Ruby compatible regex strings, and Go-compatible RE2 regex strings. It can be implemented in ruby, but consider starting with the core in rust and creating a ruby wrapper (forkingglobsetmight be the easiest). - Use this gem for this use case
- Review uses of
File.fnmatch?and switch over to globs backed by eitherRegexporGitlab::Regexwhen applicable (individually feature flagged, with clear performance metrics ahead of time to measure impact)
Edited by 🤖 GitLab Bot 🤖