##// END OF EJS Templates
rust-matchers: add `build_regex_match` function...
Raphaël Gomès -
r45008:a21881b4 default
parent child Browse files
Show More
@@ -10,7 +10,7 b''
10 #[cfg(feature = "with-re2")]
10 #[cfg(feature = "with-re2")]
11 use crate::re2::Re2;
11 use crate::re2::Re2;
12 use crate::{
12 use crate::{
13 filepatterns::PatternResult,
13 filepatterns::{build_single_regex, PatternResult},
14 utils::hg_path::{HgPath, HgPathBuf},
14 utils::hg_path::{HgPath, HgPathBuf},
15 DirsMultiset, DirstateMapError, IgnorePattern, PatternError,
15 DirsMultiset, DirstateMapError, IgnorePattern, PatternError,
16 PatternSyntax,
16 PatternSyntax,
@@ -242,6 +242,24 b' fn re_matcher(_: &[u8]) -> PatternResult'
242 Err(PatternError::Re2NotInstalled)
242 Err(PatternError::Re2NotInstalled)
243 }
243 }
244
244
245 /// Returns the regex pattern and a function that matches an `HgPath` against
246 /// said regex formed by the given ignore patterns.
247 fn build_regex_match<'a>(
248 ignore_patterns: &'a [&'a IgnorePattern],
249 ) -> PatternResult<(Vec<u8>, Box<dyn Fn(&HgPath) -> bool + Sync>)> {
250 let regexps: Result<Vec<_>, PatternError> = ignore_patterns
251 .into_iter()
252 .map(|k| build_single_regex(*k))
253 .collect();
254 let regexps = regexps?;
255 let full_regex = regexps.join(&b'|');
256
257 let matcher = re_matcher(&full_regex)?;
258 let func = Box::new(move |filename: &HgPath| matcher(filename));
259
260 Ok((full_regex, func))
261 }
262
245 /// Returns roots and directories corresponding to each pattern.
263 /// Returns roots and directories corresponding to each pattern.
246 ///
264 ///
247 /// This calculates the roots and directories exactly matching the patterns and
265 /// This calculates the roots and directories exactly matching the patterns and
General Comments 0
You need to be logged in to leave comments. Login now