Implement a glob to regexp/re2 transpiler

Problem to solve

Various parts of the product implement glob matches, but inconsistently:

  1. 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
  2. Others transpile a subset to regular expressions (example)
    • This is problematic because users now need to know which glob implementation is used where
  3. 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

  1. 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 (forking globset might be the easiest).
  2. Use this gem for this use case
  3. Review uses of File.fnmatch? and switch over to globs backed by either Regexp or Gitlab::Regex when applicable (individually feature flagged, with clear performance metrics ahead of time to measure impact)
Edited by 🤖 GitLab Bot 🤖