diff rust/hg-core/src/filepatterns.rs @ 42870: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 62eabdf91f85
children 69195b6f8f97
line wrap: on
line diff
--- a/rust/hg-core/src/filepatterns.rs	Mon Aug 26 08:25:01 2019 -0400
+++ b/rust/hg-core/src/filepatterns.rs	Sun Aug 25 22:53:42 2019 -0400
@@ -185,14 +185,21 @@
             res.extend(b"[^/]+$");
             res
         }
-        PatternSyntax::Glob
-        | PatternSyntax::RelGlob
-        | PatternSyntax::RootGlob => {
+        PatternSyntax::RelGlob => {
             let mut res: Vec<u8> = vec![];
-            if syntax == PatternSyntax::RelGlob {
+            let glob_re = glob_to_re(pattern);
+            if let Some(rest) = glob_re.drop_prefix(b"[^/]*") {
+                res.extend(b".*");
+                res.extend(rest);
+            } else {
                 res.extend(b"(?:|.*/)");
+                res.extend(glob_re);
             }
-
+            res.extend(globsuffix.iter());
+            res
+        }
+        PatternSyntax::Glob | PatternSyntax::RootGlob => {
+            let mut res: Vec<u8> = vec![];
             res.extend(glob_to_re(pattern));
             res.extend(globsuffix.iter());
             res