diff 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
line wrap: on
line diff
--- a/mercurial/match.py	Mon Aug 26 08:25:01 2019 -0400
+++ b/mercurial/match.py	Sun Aug 25 22:53:42 2019 -0400
@@ -1223,7 +1223,12 @@
         # Anything after the pattern must be a non-directory.
         return escaped + '[^/]+$'
     if kind == 'relglob':
-        return '(?:|.*/)' + _globre(pat) + globsuffix
+        globre = _globre(pat)
+        if globre.startswith('[^/]*'):
+            # When pat has the form *XYZ (common), make the returned regex more
+            # legible by returning the regex for **XYZ instead of **/*XYZ.
+            return '.*' + globre[len('[^/]*'):] + globsuffix
+        return '(?:|.*/)' + globre + globsuffix
     if kind == 'relre':
         if pat.startswith('^'):
             return pat