Patchwork D7924: rust-matchers: add `build_regex_match` function

login
register
mail settings
Submitter phabricator
Date March 11, 2020, 4:23 p.m.
Message ID <ac481ffbab15b1a2cec45e62be33250d@localhost.localdomain>
Download mbox | patch
Permalink /patch/45718/
State Not Applicable
Headers show

Comments

phabricator - March 11, 2020, 4:23 p.m.
Closed by commit rHGa21881b40942: rust-matchers: add `build_regex_match` function (authored by Alphare).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7924?vs=20162&id=20714

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7924/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7924

AFFECTED FILES
  rust/hg-core/src/matchers.rs

CHANGE DETAILS




To: Alphare, #hg-reviewers, kevincox, martinvonz
Cc: durin42, kevincox, mercurial-devel

Patch

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
@@ -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