D11818: rhg: refactor to use IgnoreFnType alias more widely
aalekseyev (Arseniy Alekseyev)
phabricator at mercurial-scm.org
Mon Nov 29 14:09:51 UTC 2021
aalekseyev created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D11818
AFFECTED FILES
rust/hg-core/src/matchers.rs
CHANGE DETAILS
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
@@ -22,6 +22,7 @@
PatternSyntax,
};
+use crate::dirstate::status::IgnoreFnType;
use crate::filepatterns::normalize_path_bytes;
use std::borrow::ToOwned;
use std::collections::HashSet;
@@ -246,7 +247,7 @@
/// ```
pub struct IncludeMatcher<'a> {
patterns: Vec<u8>,
- match_fn: Box<dyn for<'r> Fn(&'r HgPath) -> bool + 'a + Sync>,
+ match_fn: IgnoreFnType<'a>,
/// Whether all the patterns match a prefix (i.e. recursively)
prefix: bool,
roots: HashSet<HgPathBuf>,
@@ -341,9 +342,9 @@
/// Returns the regex pattern and a function that matches an `HgPath` against
/// said regex formed by the given ignore patterns.
-fn build_regex_match(
- ignore_patterns: &[IgnorePattern],
-) -> PatternResult<(Vec<u8>, Box<dyn Fn(&HgPath) -> bool + Sync>)> {
+fn build_regex_match<'a, 'b>(
+ ignore_patterns: &'a [IgnorePattern],
+) -> PatternResult<(Vec<u8>, IgnoreFnType<'b>)> {
let mut regexps = vec![];
let mut exact_set = HashSet::new();
@@ -365,10 +366,10 @@
let func = move |filename: &HgPath| {
exact_set.contains(filename) || matcher(filename)
};
- Box::new(func) as Box<dyn Fn(&HgPath) -> bool + Sync>
+ Box::new(func) as IgnoreFnType
} else {
let func = move |filename: &HgPath| exact_set.contains(filename);
- Box::new(func) as Box<dyn Fn(&HgPath) -> bool + Sync>
+ Box::new(func) as IgnoreFnType
};
Ok((full_regex, func))
@@ -479,8 +480,8 @@
/// should be matched.
fn build_match<'a, 'b>(
ignore_patterns: Vec<IgnorePattern>,
-) -> PatternResult<(Vec<u8>, Box<dyn Fn(&HgPath) -> bool + 'b + Sync>)> {
- let mut match_funcs: Vec<Box<dyn Fn(&HgPath) -> bool + Sync>> = vec![];
+) -> PatternResult<(Vec<u8>, IgnoreFnType<'b>)> {
+ let mut match_funcs: Vec<IgnoreFnType<'b>> = vec![];
// For debugging and printing
let mut patterns = vec![];
@@ -567,10 +568,7 @@
mut all_pattern_files: Vec<PathBuf>,
root_dir: &Path,
inspect_pattern_bytes: &mut impl FnMut(&[u8]),
-) -> PatternResult<(
- Box<dyn for<'r> Fn(&'r HgPath) -> bool + Sync + 'a>,
- Vec<PatternFileWarning>,
-)> {
+) -> PatternResult<(IgnoreFnType<'a>, Vec<PatternFileWarning>)> {
let mut all_patterns = vec![];
let mut all_warnings = vec![];
To: aalekseyev, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list