author | Yuya Nishihara <yuya@tcha.org> |
Sat, 21 Mar 2020 13:27:47 +0900 | |
changeset 44582 | 482a6aac1f15 |
parent 44541 | d880805d5442 |
child 44593 | 496868f1030c |
permissions | -rw-r--r-- |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 |
// matchers.rs |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 |
// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 |
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 |
// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 |
// This software may be used and distributed according to the terms of the |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 |
// GNU General Public License version 2 or any later version. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
|
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 |
//! Structs and types for matching files and directories. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 |
|
44519
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
10 |
#[cfg(feature = "with-re2")] |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
11 |
use crate::re2::Re2; |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
12 |
use crate::{ |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
13 |
dirstate::dirs_multiset::DirsChildrenMultiset, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
14 |
filepatterns::{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
15 |
build_single_regex, filter_subincludes, get_patterns_from_file, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
16 |
PatternFileWarning, PatternResult, SubInclude, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
17 |
}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
18 |
utils::{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
19 |
files::find_dirs, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
20 |
hg_path::{HgPath, HgPathBuf}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
21 |
Escaped, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
22 |
}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
23 |
DirsMultiset, DirstateMapError, FastHashMap, IgnorePattern, PatternError, |
44520
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
24 |
PatternSyntax, |
44519
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
25 |
}; |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
26 |
|
44541
d880805d5442
hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents:
44524
diff
changeset
|
27 |
use micro_timer::timed; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
use std::collections::HashSet; |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
29 |
use std::fmt::{Display, Error, Formatter}; |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
30 |
use std::iter::FromIterator; |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
31 |
use std::ops::Deref; |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
32 |
use std::path::Path; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
|
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
34 |
#[derive(Debug, PartialEq)] |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Raphaël Gomès <rgomes@octobus.net>
parents:
43611
diff
changeset
|
35 |
pub enum VisitChildrenSet<'a> { |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
/// Don't visit anything |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
Empty, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 |
/// Only visit this directory |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
This, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
/// Visit this directory and these subdirectories |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 |
/// TODO Should we implement a `NonEmptyHashSet`? |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Raphaël Gomès <rgomes@octobus.net>
parents:
43611
diff
changeset
|
42 |
Set(HashSet<&'a HgPath>), |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
/// Visit this directory and all subdirectories |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
Recursive, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 |
} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
|
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
pub trait Matcher { |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
/// Explicitly listed files |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Raphaël Gomès <rgomes@octobus.net>
parents:
43611
diff
changeset
|
49 |
fn file_set(&self) -> Option<&HashSet<&HgPath>>; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
/// Returns whether `filename` is in `file_set` |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
51 |
fn exact_match(&self, filename: impl AsRef<HgPath>) -> bool; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 |
/// Returns whether `filename` is matched by this matcher |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
53 |
fn matches(&self, filename: impl AsRef<HgPath>) -> bool; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 |
/// Decides whether a directory should be visited based on whether it |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
/// has potential matches in it or one of its subdirectories, and |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 |
/// potentially lists which subdirectories of that directory should be |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 |
/// visited. This is based on the match's primary, included, and excluded |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 |
/// patterns. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 |
/// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 |
/// # Example |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
/// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 |
/// Assume matchers `['path:foo/bar', 'rootfilesin:qux']`, we would |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 |
/// return the following values (assuming the implementation of |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 |
/// visit_children_set is capable of recognizing this; some implementations |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 |
/// are not). |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
/// |
44006
72bced4f2936
rust-matchers: fixing cargo doc
Georges Racinet <georges.racinet@octobus.net>
parents:
43914
diff
changeset
|
67 |
/// ```text |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
68 |
/// ```ignore |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
69 |
/// '' -> {'foo', 'qux'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
70 |
/// 'baz' -> set() |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
/// 'foo' -> {'bar'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
/// // Ideally this would be `Recursive`, but since the prefix nature of |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 |
/// // matchers is applied to the entire matcher, we have to downgrade this |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
74 |
/// // to `This` due to the (yet to be implemented in Rust) non-prefix |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 |
/// // `RootFilesIn'-kind matcher being mixed in. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
76 |
/// 'foo/bar' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 |
/// 'qux' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
/// ``` |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
/// # Important |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 |
/// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 |
/// Most matchers do not know if they're representing files or |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 |
/// directories. They see `['path:dir/f']` and don't know whether `f` is a |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
83 |
/// file or a directory, so `visit_children_set('dir')` for most matchers |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 |
/// will return `HashSet{ HgPath { "f" } }`, but if the matcher knows it's |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 |
/// a file (like the yet to be implemented in Rust `ExactMatcher` does), |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
86 |
/// it may return `VisitChildrenSet::This`. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
87 |
/// Do not rely on the return being a `HashSet` indicating that there are |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 |
/// no files in this dir to investigate (or equivalently that if there are |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 |
/// files to investigate in 'dir' that it will always return |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 |
/// `VisitChildrenSet::This`). |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 |
fn visit_children_set( |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 |
&self, |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
93 |
directory: impl AsRef<HgPath>, |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
94 |
) -> VisitChildrenSet; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
95 |
/// Matcher will match everything and `files_set()` will be empty: |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
/// optimization might be possible. |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
97 |
fn matches_everything(&self) -> bool; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 |
/// Matcher will match exactly the files in `files_set()`: optimization |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 |
/// might be possible. |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
100 |
fn is_exact(&self) -> bool; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 |
} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 |
|
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 |
/// Matches everything. |
43834
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43832
diff
changeset
|
104 |
///``` |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43832
diff
changeset
|
105 |
/// use hg::{ matchers::{Matcher, AlwaysMatcher}, utils::hg_path::HgPath }; |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43832
diff
changeset
|
106 |
/// |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43832
diff
changeset
|
107 |
/// let matcher = AlwaysMatcher; |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43832
diff
changeset
|
108 |
/// |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
109 |
/// assert_eq!(matcher.matches(HgPath::new(b"whatever")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
110 |
/// assert_eq!(matcher.matches(HgPath::new(b"b.txt")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
111 |
/// assert_eq!(matcher.matches(HgPath::new(b"main.c")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
112 |
/// assert_eq!(matcher.matches(HgPath::new(br"re:.*\.c$")), true); |
43834
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43832
diff
changeset
|
113 |
/// ``` |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 |
#[derive(Debug)] |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 |
pub struct AlwaysMatcher; |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 |
|
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 |
impl Matcher for AlwaysMatcher { |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Raphaël Gomès <rgomes@octobus.net>
parents:
43611
diff
changeset
|
118 |
fn file_set(&self) -> Option<&HashSet<&HgPath>> { |
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Raphaël Gomès <rgomes@octobus.net>
parents:
43611
diff
changeset
|
119 |
None |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 |
} |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
121 |
fn exact_match(&self, _filename: impl AsRef<HgPath>) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
122 |
false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
123 |
} |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
124 |
fn matches(&self, _filename: impl AsRef<HgPath>) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
125 |
true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
126 |
} |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
fn visit_children_set( |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 |
&self, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 |
_directory: impl AsRef<HgPath>, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 |
) -> VisitChildrenSet { |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 |
VisitChildrenSet::Recursive |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 |
} |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
133 |
fn matches_everything(&self) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
134 |
true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
135 |
} |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
136 |
fn is_exact(&self) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
137 |
false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43438
diff
changeset
|
138 |
} |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 |
} |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
140 |
|
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
141 |
/// Matches the input files exactly. They are interpreted as paths, not |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
142 |
/// patterns. |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
143 |
/// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
144 |
///``` |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
145 |
/// use hg::{ matchers::{Matcher, FileMatcher}, utils::hg_path::HgPath }; |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
146 |
/// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
147 |
/// let files = [HgPath::new(b"a.txt"), HgPath::new(br"re:.*\.c$")]; |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
148 |
/// let matcher = FileMatcher::new(&files).unwrap(); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
149 |
/// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
150 |
/// assert_eq!(matcher.matches(HgPath::new(b"a.txt")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
151 |
/// assert_eq!(matcher.matches(HgPath::new(b"b.txt")), false); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
152 |
/// assert_eq!(matcher.matches(HgPath::new(b"main.c")), false); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
153 |
/// assert_eq!(matcher.matches(HgPath::new(br"re:.*\.c$")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
154 |
/// ``` |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
155 |
#[derive(Debug)] |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
156 |
pub struct FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
157 |
files: HashSet<&'a HgPath>, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
158 |
dirs: DirsMultiset, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
159 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
160 |
|
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
161 |
impl<'a> FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
162 |
pub fn new( |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
163 |
files: &'a [impl AsRef<HgPath>], |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
164 |
) -> Result<Self, DirstateMapError> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
165 |
Ok(Self { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
166 |
files: HashSet::from_iter(files.iter().map(|f| f.as_ref())), |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
167 |
dirs: DirsMultiset::from_manifest(files)?, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
168 |
}) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
169 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
170 |
fn inner_matches(&self, filename: impl AsRef<HgPath>) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
171 |
self.files.contains(filename.as_ref()) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
172 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
173 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
174 |
|
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
175 |
impl<'a> Matcher for FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
176 |
fn file_set(&self) -> Option<&HashSet<&HgPath>> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
177 |
Some(&self.files) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
178 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
179 |
fn exact_match(&self, filename: impl AsRef<HgPath>) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
180 |
self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
181 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
182 |
fn matches(&self, filename: impl AsRef<HgPath>) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
183 |
self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
184 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
185 |
fn visit_children_set( |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
186 |
&self, |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
187 |
directory: impl AsRef<HgPath>, |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
188 |
) -> VisitChildrenSet { |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
189 |
if self.files.is_empty() || !self.dirs.contains(&directory) { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
190 |
return VisitChildrenSet::Empty; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
191 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
192 |
let dirs_as_set = self.dirs.iter().map(|k| k.deref()).collect(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
193 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
194 |
let mut candidates: HashSet<&HgPath> = |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
195 |
self.files.union(&dirs_as_set).map(|k| *k).collect(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
196 |
candidates.remove(HgPath::new(b"")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
197 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
198 |
if !directory.as_ref().is_empty() { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
199 |
let directory = [directory.as_ref().as_bytes(), b"/"].concat(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
200 |
candidates = candidates |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
201 |
.iter() |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
202 |
.filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
203 |
if c.as_bytes().starts_with(&directory) { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
204 |
Some(HgPath::new(&c.as_bytes()[directory.len()..])) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
205 |
} else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
206 |
None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
207 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
208 |
}) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
209 |
.collect(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
210 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
211 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
212 |
// `self.dirs` includes all of the directories, recursively, so if |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
213 |
// we're attempting to match 'foo/bar/baz.txt', it'll have '', 'foo', |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
214 |
// 'foo/bar' in it. Thus we can safely ignore a candidate that has a |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
215 |
// '/' in it, indicating it's for a subdir-of-a-subdir; the immediate |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
216 |
// subdir will be in there without a slash. |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
217 |
VisitChildrenSet::Set( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
218 |
candidates |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
219 |
.iter() |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
220 |
.filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
221 |
if c.bytes().all(|b| *b != b'/') { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
222 |
Some(*c) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
223 |
} else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
224 |
None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
225 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
226 |
}) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
227 |
.collect(), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
228 |
) |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
229 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
230 |
fn matches_everything(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
231 |
false |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
232 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
233 |
fn is_exact(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
234 |
true |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
235 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
236 |
} |
44519
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
237 |
|
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
238 |
/// Matches files that are included in the ignore rules. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
239 |
#[cfg_attr( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
240 |
feature = "with-re2", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
241 |
doc = r##" |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
242 |
``` |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
243 |
use hg::{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
244 |
matchers::{IncludeMatcher, Matcher}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
245 |
IgnorePattern, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
246 |
PatternSyntax, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
247 |
utils::hg_path::HgPath |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
248 |
}; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
249 |
use std::path::Path; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
250 |
/// |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
251 |
let ignore_patterns = |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
252 |
vec![IgnorePattern::new(PatternSyntax::RootGlob, b"this*", Path::new(""))]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
253 |
let (matcher, _) = IncludeMatcher::new(ignore_patterns, "").unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
254 |
/// |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
255 |
assert_eq!(matcher.matches(HgPath::new(b"testing")), false); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
256 |
assert_eq!(matcher.matches(HgPath::new(b"this should work")), true); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
257 |
assert_eq!(matcher.matches(HgPath::new(b"this also")), true); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
258 |
assert_eq!(matcher.matches(HgPath::new(b"but not this")), false); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
259 |
``` |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
260 |
"## |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
261 |
)] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
262 |
pub struct IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
263 |
patterns: Vec<u8>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
264 |
match_fn: Box<dyn for<'r> Fn(&'r HgPath) -> bool + 'a + Sync>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
265 |
/// Whether all the patterns match a prefix (i.e. recursively) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
266 |
prefix: bool, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
267 |
roots: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
268 |
dirs: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
269 |
parents: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
270 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
271 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
272 |
impl<'a> Matcher for IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
273 |
fn file_set(&self) -> Option<&HashSet<&HgPath>> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
274 |
None |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
275 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
276 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
277 |
fn exact_match(&self, _filename: impl AsRef<HgPath>) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
278 |
false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
279 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
280 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
281 |
fn matches(&self, filename: impl AsRef<HgPath>) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
282 |
(self.match_fn)(filename.as_ref()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
283 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
284 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
285 |
fn visit_children_set( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
286 |
&self, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
287 |
directory: impl AsRef<HgPath>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
288 |
) -> VisitChildrenSet { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
289 |
let dir = directory.as_ref(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
290 |
if self.prefix && self.roots.contains(dir) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
291 |
return VisitChildrenSet::Recursive; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
292 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
293 |
if self.roots.contains(HgPath::new(b"")) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
294 |
|| self.roots.contains(dir) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
295 |
|| self.dirs.contains(dir) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
296 |
|| find_dirs(dir).any(|parent_dir| self.roots.contains(parent_dir)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
297 |
{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
298 |
return VisitChildrenSet::This; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
299 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
300 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
301 |
if self.parents.contains(directory.as_ref()) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
302 |
let multiset = self.get_all_parents_children(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
303 |
if let Some(children) = multiset.get(dir) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
304 |
return VisitChildrenSet::Set(children.to_owned()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
305 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
306 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
307 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
308 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
309 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
310 |
fn matches_everything(&self) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
311 |
false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
312 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
313 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
314 |
fn is_exact(&self) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
315 |
false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
316 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
317 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
318 |
|
44519
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
319 |
#[cfg(feature = "with-re2")] |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
320 |
/// Returns a function that matches an `HgPath` against the given regex |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
321 |
/// pattern. |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
322 |
/// |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
323 |
/// This can fail when the pattern is invalid or not supported by the |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
324 |
/// underlying engine `Re2`, for instance anything with back-references. |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
325 |
fn re_matcher( |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
326 |
pattern: &[u8], |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
327 |
) -> PatternResult<impl Fn(&HgPath) -> bool + Sync> { |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
328 |
let regex = Re2::new(pattern); |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
329 |
let regex = regex.map_err(|e| PatternError::UnsupportedSyntax(e))?; |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
330 |
Ok(move |path: &HgPath| regex.is_match(path.as_bytes())) |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
331 |
} |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
332 |
|
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
333 |
#[cfg(not(feature = "with-re2"))] |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
334 |
fn re_matcher(_: &[u8]) -> PatternResult<Box<dyn Fn(&HgPath) -> bool + Sync>> { |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
335 |
Err(PatternError::Re2NotInstalled) |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
336 |
} |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44353
diff
changeset
|
337 |
|
44521
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
338 |
/// Returns the regex pattern and a function that matches an `HgPath` against |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
339 |
/// said regex formed by the given ignore patterns. |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
340 |
fn build_regex_match<'a>( |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
341 |
ignore_patterns: &'a [&'a IgnorePattern], |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
342 |
) -> PatternResult<(Vec<u8>, Box<dyn Fn(&HgPath) -> bool + Sync>)> { |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
343 |
let regexps: Result<Vec<_>, PatternError> = ignore_patterns |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
344 |
.into_iter() |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
345 |
.map(|k| build_single_regex(*k)) |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
346 |
.collect(); |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
347 |
let regexps = regexps?; |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
348 |
let full_regex = regexps.join(&b'|'); |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
349 |
|
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
350 |
let matcher = re_matcher(&full_regex)?; |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
351 |
let func = Box::new(move |filename: &HgPath| matcher(filename)); |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
352 |
|
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
353 |
Ok((full_regex, func)) |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
354 |
} |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44520
diff
changeset
|
355 |
|
44520
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
356 |
/// Returns roots and directories corresponding to each pattern. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
357 |
/// |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
358 |
/// This calculates the roots and directories exactly matching the patterns and |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
359 |
/// returns a tuple of (roots, dirs). It does not return other directories |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
360 |
/// which may also need to be considered, like the parent directories. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
361 |
fn roots_and_dirs( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
362 |
ignore_patterns: &[IgnorePattern], |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
363 |
) -> (Vec<HgPathBuf>, Vec<HgPathBuf>) { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
364 |
let mut roots = Vec::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
365 |
let mut dirs = Vec::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
366 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
367 |
for ignore_pattern in ignore_patterns { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
368 |
let IgnorePattern { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
369 |
syntax, pattern, .. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
370 |
} = ignore_pattern; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
371 |
match syntax { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
372 |
PatternSyntax::RootGlob | PatternSyntax::Glob => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
373 |
let mut root = vec![]; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
374 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
375 |
for p in pattern.split(|c| *c == b'/') { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
376 |
if p.iter().any(|c| match *c { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
377 |
b'[' | b'{' | b'*' | b'?' => true, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
378 |
_ => false, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
379 |
}) { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
380 |
break; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
381 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
382 |
root.push(HgPathBuf::from_bytes(p)); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
383 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
384 |
let buf = |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
385 |
root.iter().fold(HgPathBuf::new(), |acc, r| acc.join(r)); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
386 |
roots.push(buf); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
387 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
388 |
PatternSyntax::Path | PatternSyntax::RelPath => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
389 |
let pat = HgPath::new(if pattern == b"." { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
390 |
&[] as &[u8] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
391 |
} else { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
392 |
pattern |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
393 |
}); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
394 |
roots.push(pat.to_owned()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
395 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
396 |
PatternSyntax::RootFiles => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
397 |
let pat = if pattern == b"." { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
398 |
&[] as &[u8] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
399 |
} else { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
400 |
pattern |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
401 |
}; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
402 |
dirs.push(HgPathBuf::from_bytes(pat)); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
403 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
404 |
_ => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
405 |
roots.push(HgPathBuf::new()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
406 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
407 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
408 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
409 |
(roots, dirs) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
410 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
411 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
412 |
/// Paths extracted from patterns |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
413 |
#[derive(Debug, PartialEq)] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
414 |
struct RootsDirsAndParents { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
415 |
/// Directories to match recursively |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
416 |
pub roots: HashSet<HgPathBuf>, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
417 |
/// Directories to match non-recursively |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
418 |
pub dirs: HashSet<HgPathBuf>, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
419 |
/// Implicitly required directories to go to items in either roots or dirs |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
420 |
pub parents: HashSet<HgPathBuf>, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
421 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
422 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
423 |
/// Extract roots, dirs and parents from patterns. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
424 |
fn roots_dirs_and_parents( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
425 |
ignore_patterns: &[IgnorePattern], |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
426 |
) -> PatternResult<RootsDirsAndParents> { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
427 |
let (roots, dirs) = roots_and_dirs(ignore_patterns); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
428 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
429 |
let mut parents = HashSet::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
430 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
431 |
parents.extend( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
432 |
DirsMultiset::from_manifest(&dirs) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
433 |
.map_err(|e| match e { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
434 |
DirstateMapError::InvalidPath(e) => e, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
435 |
_ => unreachable!(), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
436 |
})? |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
437 |
.iter() |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
438 |
.map(|k| k.to_owned()), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
439 |
); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
440 |
parents.extend( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
441 |
DirsMultiset::from_manifest(&roots) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
442 |
.map_err(|e| match e { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
443 |
DirstateMapError::InvalidPath(e) => e, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
444 |
_ => unreachable!(), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
445 |
})? |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
446 |
.iter() |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
447 |
.map(|k| k.to_owned()), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
448 |
); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
449 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
450 |
Ok(RootsDirsAndParents { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
451 |
roots: HashSet::from_iter(roots), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
452 |
dirs: HashSet::from_iter(dirs), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
453 |
parents, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
454 |
}) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
455 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
456 |
|
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
457 |
/// Returns a function that checks whether a given file (in the general sense) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
458 |
/// should be matched. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
459 |
fn build_match<'a, 'b>( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
460 |
ignore_patterns: &'a [IgnorePattern], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
461 |
root_dir: impl AsRef<Path>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
462 |
) -> PatternResult<( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
463 |
Vec<u8>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
464 |
Box<dyn Fn(&HgPath) -> bool + 'b + Sync>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
465 |
Vec<PatternFileWarning>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
466 |
)> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
467 |
let mut match_funcs: Vec<Box<dyn Fn(&HgPath) -> bool + Sync>> = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
468 |
// For debugging and printing |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
469 |
let mut patterns = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
470 |
let mut all_warnings = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
471 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
472 |
let (subincludes, ignore_patterns) = |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
473 |
filter_subincludes(ignore_patterns, root_dir)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
474 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
475 |
if !subincludes.is_empty() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
476 |
// Build prefix-based matcher functions for subincludes |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
477 |
let mut submatchers = FastHashMap::default(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
478 |
let mut prefixes = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
479 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
480 |
for SubInclude { prefix, root, path } in subincludes.into_iter() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
481 |
let (match_fn, warnings) = get_ignore_function(&[path], root)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
482 |
all_warnings.extend(warnings); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
483 |
prefixes.push(prefix.to_owned()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
484 |
submatchers.insert(prefix.to_owned(), match_fn); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
485 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
486 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
487 |
let match_subinclude = move |filename: &HgPath| { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
488 |
for prefix in prefixes.iter() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
489 |
if let Some(rel) = filename.relative_to(prefix) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
490 |
if (submatchers.get(prefix).unwrap())(rel) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
491 |
return true; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
492 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
493 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
494 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
495 |
false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
496 |
}; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
497 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
498 |
match_funcs.push(Box::new(match_subinclude)); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
499 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
500 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
501 |
if !ignore_patterns.is_empty() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
502 |
// Either do dumb matching if all patterns are rootfiles, or match |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
503 |
// with a regex. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
504 |
if ignore_patterns |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
505 |
.iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
506 |
.all(|k| k.syntax == PatternSyntax::RootFiles) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
507 |
{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
508 |
let dirs: HashSet<_> = ignore_patterns |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
509 |
.iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
510 |
.map(|k| k.pattern.to_owned()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
511 |
.collect(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
512 |
let mut dirs_vec: Vec<_> = dirs.iter().cloned().collect(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
513 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
514 |
let match_func = move |path: &HgPath| -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
515 |
let path = path.as_bytes(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
516 |
let i = path.iter().rfind(|a| **a == b'/'); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
517 |
let dir = if let Some(i) = i { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
518 |
&path[..*i as usize] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
519 |
} else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
520 |
b"." |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
521 |
}; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
522 |
dirs.contains(dir.deref()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
523 |
}; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
524 |
match_funcs.push(Box::new(match_func)); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
525 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
526 |
patterns.extend(b"rootfilesin: "); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
527 |
dirs_vec.sort(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
528 |
patterns.extend(dirs_vec.escaped_bytes()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
529 |
} else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
530 |
let (new_re, match_func) = build_regex_match(&ignore_patterns)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
531 |
patterns = new_re; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
532 |
match_funcs.push(match_func) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
533 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
534 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
535 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
536 |
Ok(if match_funcs.len() == 1 { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
537 |
(patterns, match_funcs.remove(0), all_warnings) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
538 |
} else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
539 |
( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
540 |
patterns, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
541 |
Box::new(move |f: &HgPath| -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
542 |
match_funcs.iter().any(|match_func| match_func(f)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
543 |
}), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
544 |
all_warnings, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
545 |
) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
546 |
}) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
547 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
548 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
549 |
/// Parses all "ignore" files with their recursive includes and returns a |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
550 |
/// function that checks whether a given file (in the general sense) should be |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
551 |
/// ignored. |
44541
d880805d5442
hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents:
44524
diff
changeset
|
552 |
#[timed] |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
553 |
pub fn get_ignore_function<'a>( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
554 |
all_pattern_files: &[impl AsRef<Path>], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
555 |
root_dir: impl AsRef<Path>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
556 |
) -> PatternResult<( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
557 |
impl for<'r> Fn(&'r HgPath) -> bool + Sync, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
558 |
Vec<PatternFileWarning>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
559 |
)> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
560 |
let mut all_patterns = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
561 |
let mut all_warnings = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
562 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
563 |
for pattern_file in all_pattern_files.into_iter() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
564 |
let (patterns, warnings) = |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
565 |
get_patterns_from_file(pattern_file, &root_dir)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
566 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
567 |
all_patterns.extend(patterns); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
568 |
all_warnings.extend(warnings); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
569 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
570 |
let (matcher, warnings) = IncludeMatcher::new(all_patterns, root_dir)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
571 |
all_warnings.extend(warnings); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
572 |
Ok((move |path: &HgPath| matcher.matches(path), all_warnings)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
573 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
574 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
575 |
impl<'a> IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
576 |
pub fn new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
577 |
ignore_patterns: Vec<IgnorePattern>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
578 |
root_dir: impl AsRef<Path>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
579 |
) -> PatternResult<(Self, Vec<PatternFileWarning>)> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
580 |
let (patterns, match_fn, warnings) = |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
581 |
build_match(&ignore_patterns, root_dir)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
582 |
let RootsDirsAndParents { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
583 |
roots, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
584 |
dirs, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
585 |
parents, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
586 |
} = roots_dirs_and_parents(&ignore_patterns)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
587 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
588 |
let prefix = ignore_patterns.iter().any(|k| match k.syntax { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
589 |
PatternSyntax::Path | PatternSyntax::RelPath => true, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
590 |
_ => false, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
591 |
}); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
592 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
593 |
Ok(( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
594 |
Self { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
595 |
patterns, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
596 |
match_fn, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
597 |
prefix, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
598 |
roots, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
599 |
dirs, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
600 |
parents, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
601 |
}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
602 |
warnings, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
603 |
)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
604 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
605 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
606 |
fn get_all_parents_children(&self) -> DirsChildrenMultiset { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
607 |
// TODO cache |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
608 |
let thing = self |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
609 |
.dirs |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
610 |
.iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
611 |
.chain(self.roots.iter()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
612 |
.chain(self.parents.iter()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
613 |
DirsChildrenMultiset::new(thing, Some(&self.parents)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
614 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
615 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
616 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
617 |
impl<'a> Display for IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
618 |
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
619 |
write!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
620 |
f, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
621 |
"IncludeMatcher(includes='{}')", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
622 |
String::from_utf8_lossy(&self.patterns.escaped_bytes()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
623 |
) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
624 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
625 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
626 |
|
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
627 |
#[cfg(test)] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
628 |
mod tests { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
629 |
use super::*; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
630 |
use pretty_assertions::assert_eq; |
44520
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
631 |
use std::path::Path; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
632 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
633 |
#[test] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
634 |
fn test_roots_and_dirs() { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
635 |
let pats = vec![ |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
636 |
IgnorePattern::new(PatternSyntax::Glob, b"g/h/*", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
637 |
IgnorePattern::new(PatternSyntax::Glob, b"g/h", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
638 |
IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
639 |
]; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
640 |
let (roots, dirs) = roots_and_dirs(&pats); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
641 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
642 |
assert_eq!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
643 |
roots, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
644 |
vec!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
645 |
HgPathBuf::from_bytes(b"g/h"), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
646 |
HgPathBuf::from_bytes(b"g/h"), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
647 |
HgPathBuf::new() |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
648 |
), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
649 |
); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
650 |
assert_eq!(dirs, vec!()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
651 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
652 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
653 |
#[test] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
654 |
fn test_roots_dirs_and_parents() { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
655 |
let pats = vec![ |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
656 |
IgnorePattern::new(PatternSyntax::Glob, b"g/h/*", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
657 |
IgnorePattern::new(PatternSyntax::Glob, b"g/h", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
658 |
IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
659 |
]; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
660 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
661 |
let mut roots = HashSet::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
662 |
roots.insert(HgPathBuf::from_bytes(b"g/h")); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
663 |
roots.insert(HgPathBuf::new()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
664 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
665 |
let dirs = HashSet::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
666 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
667 |
let mut parents = HashSet::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
668 |
parents.insert(HgPathBuf::new()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
669 |
parents.insert(HgPathBuf::from_bytes(b"g")); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
670 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
671 |
assert_eq!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
672 |
roots_dirs_and_parents(&pats).unwrap(), |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44522
diff
changeset
|
673 |
RootsDirsAndParents { |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44522
diff
changeset
|
674 |
roots, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44522
diff
changeset
|
675 |
dirs, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44522
diff
changeset
|
676 |
parents |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44522
diff
changeset
|
677 |
} |
44520
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
678 |
); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44519
diff
changeset
|
679 |
} |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
680 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
681 |
#[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
682 |
fn test_filematcher_visit_children_set() { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
683 |
// Visitchildrenset |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
684 |
let files = vec![HgPath::new(b"dir/subdir/foo.txt")]; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
685 |
let matcher = FileMatcher::new(&files).unwrap(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
686 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
687 |
let mut set = HashSet::new(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
688 |
set.insert(HgPath::new(b"dir")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
689 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
690 |
matcher.visit_children_set(HgPath::new(b"")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
691 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
692 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
693 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
694 |
let mut set = HashSet::new(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
695 |
set.insert(HgPath::new(b"subdir")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
696 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
697 |
matcher.visit_children_set(HgPath::new(b"dir")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
698 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
699 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
700 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
701 |
let mut set = HashSet::new(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
702 |
set.insert(HgPath::new(b"foo.txt")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
703 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
704 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
705 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
706 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
707 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
708 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
709 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
710 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
711 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
712 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
713 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/foo.txt")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
714 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
715 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
716 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
717 |
matcher.visit_children_set(HgPath::new(b"folder")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
718 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
719 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
720 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
721 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
722 |
#[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
723 |
fn test_filematcher_visit_children_set_files_and_dirs() { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
724 |
let files = vec![ |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
725 |
HgPath::new(b"rootfile.txt"), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
726 |
HgPath::new(b"a/file1.txt"), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
727 |
HgPath::new(b"a/b/file2.txt"), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
728 |
// No file in a/b/c |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
729 |
HgPath::new(b"a/b/c/d/file4.txt"), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
730 |
]; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
731 |
let matcher = FileMatcher::new(&files).unwrap(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
732 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
733 |
let mut set = HashSet::new(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
734 |
set.insert(HgPath::new(b"a")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
735 |
set.insert(HgPath::new(b"rootfile.txt")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
736 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
737 |
matcher.visit_children_set(HgPath::new(b"")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
738 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
739 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
740 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
741 |
let mut set = HashSet::new(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
742 |
set.insert(HgPath::new(b"b")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
743 |
set.insert(HgPath::new(b"file1.txt")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
744 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
745 |
matcher.visit_children_set(HgPath::new(b"a")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
746 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
747 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
748 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
749 |
let mut set = HashSet::new(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
750 |
set.insert(HgPath::new(b"c")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
751 |
set.insert(HgPath::new(b"file2.txt")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
752 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
753 |
matcher.visit_children_set(HgPath::new(b"a/b")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
754 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
755 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
756 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
757 |
let mut set = HashSet::new(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
758 |
set.insert(HgPath::new(b"d")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
759 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
760 |
matcher.visit_children_set(HgPath::new(b"a/b/c")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
761 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
762 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
763 |
let mut set = HashSet::new(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
764 |
set.insert(HgPath::new(b"file4.txt")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
765 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
766 |
matcher.visit_children_set(HgPath::new(b"a/b/c/d")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
767 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
768 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
769 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
770 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
771 |
matcher.visit_children_set(HgPath::new(b"a/b/c/d/e")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
772 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
773 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
774 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
775 |
matcher.visit_children_set(HgPath::new(b"folder")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
776 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
777 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
778 |
} |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
779 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
780 |
#[cfg(feature = "with-re2")] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
781 |
#[test] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
782 |
fn test_includematcher() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
783 |
// VisitchildrensetPrefix |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
784 |
let (matcher, _) = IncludeMatcher::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
785 |
vec![IgnorePattern::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
786 |
PatternSyntax::RelPath, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
787 |
b"dir/subdir", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
788 |
Path::new(""), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
789 |
)], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
790 |
"", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
791 |
) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
792 |
.unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
793 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
794 |
let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
795 |
set.insert(HgPath::new(b"dir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
796 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
797 |
matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
798 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
799 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
800 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
801 |
let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
802 |
set.insert(HgPath::new(b"subdir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
803 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
804 |
matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
805 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
806 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
807 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
808 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
809 |
VisitChildrenSet::Recursive |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
810 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
811 |
// OPT: This should probably be 'all' if its parent is? |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
812 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
813 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
814 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
815 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
816 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
817 |
matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
818 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
819 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
820 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
821 |
// VisitchildrensetRootfilesin |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
822 |
let (matcher, _) = IncludeMatcher::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
823 |
vec![IgnorePattern::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
824 |
PatternSyntax::RootFiles, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
825 |
b"dir/subdir", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
826 |
Path::new(""), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
827 |
)], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
828 |
"", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
829 |
) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
830 |
.unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
831 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
832 |
let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
833 |
set.insert(HgPath::new(b"dir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
834 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
835 |
matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
836 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
837 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
838 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
839 |
let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
840 |
set.insert(HgPath::new(b"subdir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
841 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
842 |
matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
843 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
844 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
845 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
846 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
847 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
848 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
849 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
850 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
851 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
852 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
853 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
854 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
855 |
matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
856 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
857 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
858 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
859 |
// VisitchildrensetGlob |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
860 |
let (matcher, _) = IncludeMatcher::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
861 |
vec![IgnorePattern::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
862 |
PatternSyntax::Glob, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
863 |
b"dir/z*", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
864 |
Path::new(""), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
865 |
)], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
866 |
"", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
867 |
) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
868 |
.unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
869 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
870 |
let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
871 |
set.insert(HgPath::new(b"dir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
872 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
873 |
matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
874 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
875 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
876 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
877 |
matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
878 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
879 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
880 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
881 |
matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
882 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
883 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
884 |
// OPT: these should probably be set(). |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
885 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
886 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
887 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
888 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
889 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
890 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
891 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
892 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44521
diff
changeset
|
893 |
} |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44006
diff
changeset
|
894 |
} |