changeset 51566:529a655874fb stable

matchers: fix the bug in rust PatternMatcher that made it cut off early This brings the rust output in line with the Python output.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 12 Apr 2024 14:09:55 +0100
parents 95c083d21ac6
children cae0be933434
files rust/hg-core/src/matchers.rs rust/hg-core/src/utils/files.rs tests/test-status.t
diffstat 3 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs	Fri Apr 12 13:48:38 2024 +0100
+++ b/rust/hg-core/src/matchers.rs	Fri Apr 12 14:09:55 2024 +0100
@@ -17,7 +17,7 @@
         PatternFileWarning, PatternResult,
     },
     utils::{
-        files::find_dirs,
+        files::{dir_ancestors, find_dirs},
         hg_path::{HgPath, HgPathBuf, HgPathError},
         Escaped,
     },
@@ -354,7 +354,7 @@
         if self.prefix && self.files.contains(directory) {
             return VisitChildrenSet::Recursive;
         }
-        let path_or_parents_in_set = find_dirs(directory)
+        let path_or_parents_in_set = dir_ancestors(directory)
             .any(|parent_dir| self.files.contains(parent_dir));
         if self.dirs.contains(directory) || path_or_parents_in_set {
             VisitChildrenSet::This
@@ -2298,7 +2298,7 @@
     #[test]
     fn test_pattern_matcher_visit_children_set() {
         let tree = make_example_tree();
-        let _pattern_dir1_glob_c =
+        let pattern_dir1_glob_c =
             PatternMatcher::new(vec![IgnorePattern::new(
                 PatternSyntax::Glob,
                 b"dir1/*.c",
@@ -2327,10 +2327,6 @@
             )])
             .unwrap()
         };
-        //        // TODO: re-enable this test when the corresponding bug is
-        // fixed        if false {
-        //            tree.check_matcher(&pattern_dir1_glob_c);
-        //        }
         let files = vec![HgPathBuf::from_bytes(b"dir/subdir/b.txt")];
         let file_dir_subdir_b = FileMatcher::new(files).unwrap();
 
@@ -2393,6 +2389,7 @@
 
         tree.check_matcher(&pattern_dir1(), 25);
         tree.check_matcher(&pattern_dir1_a, 1);
+        tree.check_matcher(&pattern_dir1_glob_c, 2);
         tree.check_matcher(&pattern_relglob_c(), 14);
         tree.check_matcher(&AlwaysMatcher, 112);
         tree.check_matcher(&NeverMatcher, 0);
--- a/rust/hg-core/src/utils/files.rs	Fri Apr 12 13:48:38 2024 +0100
+++ b/rust/hg-core/src/utils/files.rs	Fri Apr 12 14:09:55 2024 +0100
@@ -120,6 +120,10 @@
     dirs
 }
 
+pub fn dir_ancestors(path: &HgPath) -> Ancestors {
+    Ancestors { next: Some(path) }
+}
+
 /// Returns an iterator yielding ancestor directories of the given repository
 /// path.
 ///
--- a/tests/test-status.t	Fri Apr 12 13:48:38 2024 +0100
+++ b/tests/test-status.t	Fri Apr 12 14:09:55 2024 +0100
@@ -842,19 +842,19 @@
   C clean
   C subdir/clean
 
+Test various matchers interatction with dirstate code:
+
   $ hg status path:subdir
   M subdir/modified
   R subdir/removed
   ! subdir/deleted
   ? subdir/unknown
 
-FIXME: it's a bug in rhg that the status below is empty:
-
   $ hg status 'glob:subdir/*'
-  M subdir/modified (no-rhg !)
-  R subdir/removed (no-rhg !)
-  ! subdir/deleted (no-rhg !)
-  ? subdir/unknown (no-rhg !)
+  M subdir/modified
+  R subdir/removed
+  ! subdir/deleted
+  ? subdir/unknown
 
 FIXME: it's a bug (both in rhg and in Python) that the status below is wrong,
 in rhg it's empty, in Python it's missing the unknown file: