diff rust/hg-core/src/matchers.rs @ 50695:1c31b343e514

match: add `filepath:` pattern to match an exact filepath relative to the root It's useful in certain automated workflows to make sure we recurse in directories whose name conflicts with files in other revisions. In addition it makes it possible to avoid building a potentially costly regex, improving performance when the set of files to match explicitly is large. The benchmark below are run in the following configuration : # data-env-vars.name = mozilla-central-2018-08-01-zstd-sparse-revlog # benchmark.name = files # benchmark.variants.rev = tip # benchmark.variants.files = all-list-filepath-sorted # bin-env-vars.hg.flavor = no-rust It also includes timings using the re2 engine (through the `google-re2` module) to show how much can be saved by just using a better regexp engine. Pattern time (seconds) time using re2 ----------------------------------------------------------- just "." 0.4 0.4 list of "filepath:…" 1.3 1.3 list of "path:…" 25.7 3.9 list of patterns 29.7 10.4 As you can see, Without re2, using "filepath:" instead of "path:" is a huge win. With re2, it is still about three times faster to not have to build the regex.
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 12 Jun 2023 16:51:08 +0200
parents e98fd81bb151
children e037af7de2ce
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs	Sun Jun 18 00:09:39 2023 +0200
+++ b/rust/hg-core/src/matchers.rs	Mon Jun 12 16:51:08 2023 +0200
@@ -708,7 +708,9 @@
                 }
                 roots.push(root);
             }
-            PatternSyntax::Path | PatternSyntax::RelPath => {
+            PatternSyntax::Path
+            | PatternSyntax::RelPath
+            | PatternSyntax::FilePath => {
                 let pat = HgPath::new(if pattern == b"." {
                     &[] as &[u8]
                 } else {
@@ -1223,6 +1225,40 @@
             VisitChildrenSet::This
         );
 
+        // VisitchildrensetFilePath
+        let matcher = IncludeMatcher::new(vec![IgnorePattern::new(
+            PatternSyntax::FilePath,
+            b"dir/z",
+            Path::new(""),
+        )])
+        .unwrap();
+
+        let mut set = HashSet::new();
+        set.insert(HgPathBuf::from_bytes(b"dir"));
+        assert_eq!(
+            matcher.visit_children_set(HgPath::new(b"")),
+            VisitChildrenSet::Set(set)
+        );
+        assert_eq!(
+            matcher.visit_children_set(HgPath::new(b"folder")),
+            VisitChildrenSet::Empty
+        );
+        let mut set = HashSet::new();
+        set.insert(HgPathBuf::from_bytes(b"z"));
+        assert_eq!(
+            matcher.visit_children_set(HgPath::new(b"dir")),
+            VisitChildrenSet::Set(set)
+        );
+        // OPT: these should probably be set().
+        assert_eq!(
+            matcher.visit_children_set(HgPath::new(b"dir/subdir")),
+            VisitChildrenSet::Empty
+        );
+        assert_eq!(
+            matcher.visit_children_set(HgPath::new(b"dir/subdir/x")),
+            VisitChildrenSet::Empty
+        );
+
         // Test multiple patterns
         let matcher = IncludeMatcher::new(vec![
             IgnorePattern::new(PatternSyntax::RelPath, b"foo", Path::new("")),