Mercurial > hg
comparison rust/hg-core/src/matchers.rs @ 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 | f5c367dc6541 |
children | cae0be933434 |
comparison
equal
deleted
inserted
replaced
51565:95c083d21ac6 | 51566:529a655874fb |
---|---|
15 filepatterns::{ | 15 filepatterns::{ |
16 build_single_regex, filter_subincludes, get_patterns_from_file, | 16 build_single_regex, filter_subincludes, get_patterns_from_file, |
17 PatternFileWarning, PatternResult, | 17 PatternFileWarning, PatternResult, |
18 }, | 18 }, |
19 utils::{ | 19 utils::{ |
20 files::find_dirs, | 20 files::{dir_ancestors, find_dirs}, |
21 hg_path::{HgPath, HgPathBuf, HgPathError}, | 21 hg_path::{HgPath, HgPathBuf, HgPathError}, |
22 Escaped, | 22 Escaped, |
23 }, | 23 }, |
24 DirsMultiset, FastHashMap, IgnorePattern, PatternError, PatternSyntax, | 24 DirsMultiset, FastHashMap, IgnorePattern, PatternError, PatternSyntax, |
25 }; | 25 }; |
352 | 352 |
353 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { | 353 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
354 if self.prefix && self.files.contains(directory) { | 354 if self.prefix && self.files.contains(directory) { |
355 return VisitChildrenSet::Recursive; | 355 return VisitChildrenSet::Recursive; |
356 } | 356 } |
357 let path_or_parents_in_set = find_dirs(directory) | 357 let path_or_parents_in_set = dir_ancestors(directory) |
358 .any(|parent_dir| self.files.contains(parent_dir)); | 358 .any(|parent_dir| self.files.contains(parent_dir)); |
359 if self.dirs.contains(directory) || path_or_parents_in_set { | 359 if self.dirs.contains(directory) || path_or_parents_in_set { |
360 VisitChildrenSet::This | 360 VisitChildrenSet::This |
361 } else { | 361 } else { |
362 VisitChildrenSet::Empty | 362 VisitChildrenSet::Empty |
2296 } | 2296 } |
2297 | 2297 |
2298 #[test] | 2298 #[test] |
2299 fn test_pattern_matcher_visit_children_set() { | 2299 fn test_pattern_matcher_visit_children_set() { |
2300 let tree = make_example_tree(); | 2300 let tree = make_example_tree(); |
2301 let _pattern_dir1_glob_c = | 2301 let pattern_dir1_glob_c = |
2302 PatternMatcher::new(vec![IgnorePattern::new( | 2302 PatternMatcher::new(vec![IgnorePattern::new( |
2303 PatternSyntax::Glob, | 2303 PatternSyntax::Glob, |
2304 b"dir1/*.c", | 2304 b"dir1/*.c", |
2305 Path::new(""), | 2305 Path::new(""), |
2306 )]) | 2306 )]) |
2325 b"*.c", | 2325 b"*.c", |
2326 Path::new(""), | 2326 Path::new(""), |
2327 )]) | 2327 )]) |
2328 .unwrap() | 2328 .unwrap() |
2329 }; | 2329 }; |
2330 // // TODO: re-enable this test when the corresponding bug is | |
2331 // fixed if false { | |
2332 // tree.check_matcher(&pattern_dir1_glob_c); | |
2333 // } | |
2334 let files = vec![HgPathBuf::from_bytes(b"dir/subdir/b.txt")]; | 2330 let files = vec![HgPathBuf::from_bytes(b"dir/subdir/b.txt")]; |
2335 let file_dir_subdir_b = FileMatcher::new(files).unwrap(); | 2331 let file_dir_subdir_b = FileMatcher::new(files).unwrap(); |
2336 | 2332 |
2337 let files = vec![ | 2333 let files = vec![ |
2338 HgPathBuf::from_bytes(b"file.txt"), | 2334 HgPathBuf::from_bytes(b"file.txt"), |
2391 .unwrap(), | 2387 .unwrap(), |
2392 ]; | 2388 ]; |
2393 | 2389 |
2394 tree.check_matcher(&pattern_dir1(), 25); | 2390 tree.check_matcher(&pattern_dir1(), 25); |
2395 tree.check_matcher(&pattern_dir1_a, 1); | 2391 tree.check_matcher(&pattern_dir1_a, 1); |
2392 tree.check_matcher(&pattern_dir1_glob_c, 2); | |
2396 tree.check_matcher(&pattern_relglob_c(), 14); | 2393 tree.check_matcher(&pattern_relglob_c(), 14); |
2397 tree.check_matcher(&AlwaysMatcher, 112); | 2394 tree.check_matcher(&AlwaysMatcher, 112); |
2398 tree.check_matcher(&NeverMatcher, 0); | 2395 tree.check_matcher(&NeverMatcher, 0); |
2399 tree.check_matcher( | 2396 tree.check_matcher( |
2400 &IntersectionMatcher::new( | 2397 &IntersectionMatcher::new( |