Mercurial > hg
comparison mercurial/match.py @ 42864:72890d8f9860
match: simplify the regexps created for glob patterns
For legibility of the resulting regexes, although it may help with
performance as well.
Differential Revision: https://phab.mercurial-scm.org/D6764
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Sun, 25 Aug 2019 22:53:42 -0400 |
parents | e94c8f584ee2 |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
42863:62eabdf91f85 | 42864:72890d8f9860 |
---|---|
1221 # Pattern is a directory name. | 1221 # Pattern is a directory name. |
1222 escaped = util.stringutil.reescape(pat) + '/' | 1222 escaped = util.stringutil.reescape(pat) + '/' |
1223 # Anything after the pattern must be a non-directory. | 1223 # Anything after the pattern must be a non-directory. |
1224 return escaped + '[^/]+$' | 1224 return escaped + '[^/]+$' |
1225 if kind == 'relglob': | 1225 if kind == 'relglob': |
1226 return '(?:|.*/)' + _globre(pat) + globsuffix | 1226 globre = _globre(pat) |
1227 if globre.startswith('[^/]*'): | |
1228 # When pat has the form *XYZ (common), make the returned regex more | |
1229 # legible by returning the regex for **XYZ instead of **/*XYZ. | |
1230 return '.*' + globre[len('[^/]*'):] + globsuffix | |
1231 return '(?:|.*/)' + globre + globsuffix | |
1227 if kind == 'relre': | 1232 if kind == 'relre': |
1228 if pat.startswith('^'): | 1233 if pat.startswith('^'): |
1229 return pat | 1234 return pat |
1230 return '.*' + pat | 1235 return '.*' + pat |
1231 if kind in ('glob', 'rootglob'): | 1236 if kind in ('glob', 'rootglob'): |