olson-sean-k / wax

Opinionated and portable globs that can be matched against paths and directory trees.
https://glob.guide
MIT License
112 stars 10 forks source link

Maximum glob depth prediction #36

Closed Dorumin closed 8 months ago

Dorumin commented 1 year ago

An attempt to predict how deep a glob will go. This should only come into effect when the user doesn't provide an explicit depth (in the current state, when usize::MAX is passed to WalkBehavior).

The current heuristic is simple: It walks through every token, and if it's a wildcard or repetition, it bails out. Otherwise, it simply increases the maximum depth by 1 for each separator found.

I may have missed something, and I certainly don't want to break anything. I also haven't tried it in a hyper diverse set of globs; just a healthy few:

.
*
*/*
*/*/*
**/*
**

/src
/src/*
/src/**
src/*
src/**
src/**/*.rs
src/**/*.rs
{src/**/token,bruh}/*.rs
<a*/:0,>
<[!.]*/>[!.]*

It is very very faster when ran on big directories for globs that can have this optimization applied. But I am not super confident that no globs will slip by. And I am also not confident that it won't over-predict; in fact, it definitely will for globs like a/{b/b,c/c,d/d}/e. This is solvable if I simply account for nested structures via some recursion in the try_get_max_depth function, but I'd rather get some feedback before committing too much to the implementation.

Thoughts?