Mercurial > hg
changeset 44521:a21881b40942
rust-matchers: add `build_regex_match` function
This function will be used to help build the upcoming `IncludeMatcher`.
Differential Revision: https://phab.mercurial-scm.org/D7924
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Fri, 17 Jan 2020 11:32:02 +0100 |
parents | d4e8cfcde012 |
children | c697638e0e91 |
files | rust/hg-core/src/matchers.rs |
diffstat | 1 files changed, 19 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs Fri Jan 17 11:31:12 2020 +0100 +++ b/rust/hg-core/src/matchers.rs Fri Jan 17 11:32:02 2020 +0100 @@ -10,7 +10,7 @@ #[cfg(feature = "with-re2")] use crate::re2::Re2; use crate::{ - filepatterns::PatternResult, + filepatterns::{build_single_regex, PatternResult}, utils::hg_path::{HgPath, HgPathBuf}, DirsMultiset, DirstateMapError, IgnorePattern, PatternError, PatternSyntax, @@ -242,6 +242,24 @@ Err(PatternError::Re2NotInstalled) } +/// Returns the regex pattern and a function that matches an `HgPath` against +/// said regex formed by the given ignore patterns. +fn build_regex_match<'a>( + ignore_patterns: &'a [&'a IgnorePattern], +) -> PatternResult<(Vec<u8>, Box<dyn Fn(&HgPath) -> bool + Sync>)> { + let regexps: Result<Vec<_>, PatternError> = ignore_patterns + .into_iter() + .map(|k| build_single_regex(*k)) + .collect(); + let regexps = regexps?; + let full_regex = regexps.join(&b'|'); + + let matcher = re_matcher(&full_regex)?; + let func = Box::new(move |filename: &HgPath| matcher(filename)); + + Ok((full_regex, func)) +} + /// Returns roots and directories corresponding to each pattern. /// /// This calculates the roots and directories exactly matching the patterns and