# HG changeset patch # User Arseniy Alekseyev # Date 2024-04-12 13:09:55 # Node ID 529a655874fb91c2f6b3e2bbf0b912decd8f941e # Parent 95c083d21ac60a39dae725f59505754ccebb7934 matchers: fix the bug in rust PatternMatcher that made it cut off early This brings the rust output in line with the Python output. diff --git a/rust/hg-core/src/matchers.rs b/rust/hg-core/src/matchers.rs --- a/rust/hg-core/src/matchers.rs +++ b/rust/hg-core/src/matchers.rs @@ -17,7 +17,7 @@ use crate::{ PatternFileWarning, PatternResult, }, utils::{ - files::find_dirs, + files::{dir_ancestors, find_dirs}, hg_path::{HgPath, HgPathBuf, HgPathError}, Escaped, }, @@ -354,7 +354,7 @@ impl<'a> Matcher for PatternMatcher<'a> 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 @@ mod tests { #[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 @@ mod tests { )]) .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 @@ mod tests { 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); diff --git a/rust/hg-core/src/utils/files.rs b/rust/hg-core/src/utils/files.rs --- a/rust/hg-core/src/utils/files.rs +++ b/rust/hg-core/src/utils/files.rs @@ -120,6 +120,10 @@ pub fn find_dirs(path: &HgPath) -> Ances dirs } +pub fn dir_ancestors(path: &HgPath) -> Ancestors { + Ancestors { next: Some(path) } +} + /// Returns an iterator yielding ancestor directories of the given repository /// path. /// diff --git a/tests/test-status.t b/tests/test-status.t --- a/tests/test-status.t +++ b/tests/test-status.t @@ -842,19 +842,19 @@ Check the output 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: