Skip to content
Snippets Groups Projects
Commit bec6e9c1 authored by Martin von Zweigbergk's avatar Martin von Zweigbergk
Browse files

matchers: use correct method for finding index in vector

The path matcher has an optimization for when all paths are `rootfilesin:`. This
optimization exists in both Python and Rust. However, the Rust implementation
currently has a bug that makes it fail in most cases. The bug is that it
`rfind()` where it was clearly intended to use `rposition()`. This patch fixes
that and adds a test.
parent 79cd29d5
No related branches found
No related tags found
1 merge request!739narrow: strip trailing `/` from manifest dir before matching it
......@@ -388,6 +388,15 @@
/// assert_eq!(matcher.matches(HgPath::new(b"this should work")), true);
/// assert_eq!(matcher.matches(HgPath::new(b"this also")), true);
/// assert_eq!(matcher.matches(HgPath::new(b"but not this")), false);
/// ///
/// let ignore_patterns =
/// vec![IgnorePattern::new(PatternSyntax::RootFiles, b"dir/subdir", Path::new(""))];
/// let matcher = IncludeMatcher::new(ignore_patterns).unwrap();
/// ///
/// assert!(!matcher.matches(HgPath::new(b"file")));
/// assert!(!matcher.matches(HgPath::new(b"dir/file")));
/// assert!(matcher.matches(HgPath::new(b"dir/subdir/file")));
/// assert!(!matcher.matches(HgPath::new(b"dir/subdir/subsubdir/file")));
/// ```
pub struct IncludeMatcher<'a> {
patterns: Vec<u8>,
......@@ -951,12 +960,8 @@
let match_func = move |path: &HgPath| -> bool {
let path = path.as_bytes();
let i = path.iter().rfind(|a| **a == b'/');
let dir = if let Some(i) = i {
&path[..*i as usize]
} else {
b"."
};
let i = path.iter().rposition(|a| *a == b'/');
let dir = if let Some(i) = i { &path[..i] } else { b"." };
dirs.contains(dir)
};
match_funcs.push(Box::new(match_func));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment