Mercurial > public > mercurial-scm > hg
annotate rust/hg-core/src/matchers.rs @ 44522:c697638e0e91
rust-matchers: add `IgnoreMatcher`
This is a big change but all of the pieces call each other, so it makes sense
to have this all in one patch.
Differential Revision: https://phab.mercurial-scm.org/D7925
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Fri, 17 Jan 2020 11:53:31 +0100 |
parents | a21881b40942 |
children | 483fce658e43 |
rev | line source |
---|---|
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 |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
27 use std::collections::HashSet; |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
28 use std::fmt::{Display, Error, Formatter}; |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
29 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
|
30 use std::ops::Deref; |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
31 use std::path::Path; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
33 #[derive(Debug, PartialEq)] |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43611
diff
changeset
|
34 pub enum VisitChildrenSet<'a> { |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
35 /// Don't visit anything |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
36 Empty, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
37 /// Only visit this directory |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
38 This, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
39 /// 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
|
40 /// 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
|
41 Set(HashSet<&'a HgPath>), |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
42 /// 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
|
43 Recursive, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
44 } |
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 pub trait Matcher { |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
47 /// Explicitly listed files |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43611
diff
changeset
|
48 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
|
49 /// 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
|
50 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
|
51 /// 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
|
52 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
|
53 /// 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
|
54 /// 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
|
55 /// 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
|
56 /// 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
|
57 /// patterns. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
58 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
59 /// # Example |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
60 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
61 /// 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
|
62 /// 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
|
63 /// 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
|
64 /// are not). |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
65 /// |
44006
72bced4f2936
rust-matchers: fixing cargo doc
Georges Racinet <georges.racinet@octobus.net>
parents:
43914
diff
changeset
|
66 /// ```text |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
67 /// ```ignore |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
68 /// '' -> {'foo', 'qux'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 /// 'baz' -> set() |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
70 /// 'foo' -> {'bar'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
71 /// // 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
|
72 /// // 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
|
73 /// // 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
|
74 /// // `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
|
75 /// 'foo/bar' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
76 /// 'qux' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
77 /// ``` |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
78 /// # Important |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
79 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
80 /// 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
|
81 /// 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
|
82 /// 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
|
83 /// 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
|
84 /// 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
|
85 /// it may return `VisitChildrenSet::This`. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
86 /// 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
|
87 /// 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
|
88 /// 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
|
89 /// `VisitChildrenSet::This`). |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
90 fn visit_children_set( |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
91 &self, |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
92 directory: impl AsRef<HgPath>, |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
93 ) -> VisitChildrenSet; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
94 /// 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
|
95 /// 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
|
96 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
|
97 /// 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
|
98 /// might be possible. |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
99 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
|
100 } |
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 /// Matches everything. |
43834
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43832
diff
changeset
|
103 ///``` |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43832
diff
changeset
|
104 /// 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
|
105 /// |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43832
diff
changeset
|
106 /// let matcher = AlwaysMatcher; |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43832
diff
changeset
|
107 /// |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
108 /// 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
|
109 /// 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
|
110 /// 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
|
111 /// 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
|
112 /// ``` |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
113 #[derive(Debug)] |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
114 pub struct AlwaysMatcher; |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
115 |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
116 impl Matcher for AlwaysMatcher { |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43611
diff
changeset
|
117 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
|
118 None |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
119 } |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
120 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
|
121 false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
122 } |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
123 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
|
124 true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
125 } |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
126 fn visit_children_set( |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
127 &self, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
128 _directory: impl AsRef<HgPath>, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
129 ) -> VisitChildrenSet { |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
130 VisitChildrenSet::Recursive |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
131 } |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
132 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
|
133 true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
134 } |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
135 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
|
136 false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
137 } |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
138 } |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
139 |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
140 /// 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
|
141 /// patterns. |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
142 /// |
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 /// 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
|
145 /// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
146 /// 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
|
147 /// let matcher = FileMatcher::new(&files).unwrap(); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
148 /// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
149 /// 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
|
150 /// 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
|
151 /// 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
|
152 /// 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
|
153 /// ``` |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
154 #[derive(Debug)] |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
155 pub struct FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
156 files: HashSet<&'a HgPath>, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
157 dirs: DirsMultiset, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
158 } |
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 impl<'a> FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
161 pub fn new( |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
162 files: &'a [impl AsRef<HgPath>], |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
163 ) -> Result<Self, DirstateMapError> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
164 Ok(Self { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
165 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
|
166 dirs: DirsMultiset::from_manifest(files)?, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
167 }) |
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 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
|
170 self.files.contains(filename.as_ref()) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
171 } |
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 impl<'a> Matcher for FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
175 fn file_set(&self) -> Option<&HashSet<&HgPath>> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
176 Some(&self.files) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
177 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
178 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
|
179 self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
180 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
181 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
|
182 self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
183 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
184 fn visit_children_set( |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
185 &self, |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
186 directory: impl AsRef<HgPath>, |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
187 ) -> VisitChildrenSet { |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
188 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
|
189 return VisitChildrenSet::Empty; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
190 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
191 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
|
192 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
197 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
|
198 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
|
199 candidates = candidates |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
200 .iter() |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
201 .filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
202 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
|
203 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
|
204 } else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
205 None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
206 } |
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 .collect(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
209 } |
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 // `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
|
212 // 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
|
213 // '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
|
214 // '/' 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
|
215 // 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
|
216 VisitChildrenSet::Set( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
217 candidates |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
218 .iter() |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
219 .filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
220 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
|
221 Some(*c) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
222 } else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
223 None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
224 } |
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 .collect(), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
227 ) |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
228 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
229 fn matches_everything(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
230 false |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
231 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
232 fn is_exact(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
233 true |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
234 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
235 } |
44519
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
236 |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
237 /// 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
|
238 #[cfg_attr( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
239 feature = "with-re2", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
240 doc = r##" |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
241 ``` |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
242 use hg::{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
243 matchers::{IncludeMatcher, Matcher}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
244 IgnorePattern, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
245 PatternSyntax, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
246 utils::hg_path::HgPath |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
247 }; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
248 use std::path::Path; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
249 /// |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
250 let ignore_patterns = |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
251 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
|
252 let (matcher, _) = IncludeMatcher::new(ignore_patterns, "").unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
253 /// |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 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
|
258 ``` |
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 pub struct IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
262 patterns: Vec<u8>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
263 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
|
264 /// 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
|
265 prefix: bool, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
266 roots: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
267 dirs: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
268 parents: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
269 } |
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 impl<'a> Matcher for IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
272 fn file_set(&self) -> Option<&HashSet<&HgPath>> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
273 None |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
274 } |
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 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
|
277 false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
278 } |
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 fn matches(&self, filename: impl AsRef<HgPath>) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
281 (self.match_fn)(filename.as_ref()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
282 } |
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 fn visit_children_set( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
285 &self, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
286 directory: impl AsRef<HgPath>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
287 ) -> VisitChildrenSet { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
288 let dir = directory.as_ref(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
289 if self.prefix && self.roots.contains(dir) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
290 return VisitChildrenSet::Recursive; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
291 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
292 if self.roots.contains(HgPath::new(b"")) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
293 || self.roots.contains(dir) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
294 || self.dirs.contains(dir) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
295 || 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
|
296 { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
297 return VisitChildrenSet::This; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
298 } |
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 if self.parents.contains(directory.as_ref()) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
301 let multiset = self.get_all_parents_children(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
302 if let Some(children) = multiset.get(dir) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
303 return VisitChildrenSet::Set(children.to_owned()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
304 } |
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 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
307 } |
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 fn matches_everything(&self) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
310 false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
311 } |
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 fn is_exact(&self) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
314 false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
315 } |
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 |
44519
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
318 #[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
|
319 /// 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
|
320 /// pattern. |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
321 /// |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
322 /// 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
|
323 /// 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
|
324 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
|
325 pattern: &[u8], |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
326 ) -> 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
|
327 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
|
328 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
|
329 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
|
330 } |
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 #[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
|
333 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
|
334 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
|
335 } |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
336 |
44521
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
337 /// 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
|
338 /// 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
|
339 fn build_regex_match<'a>( |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
340 ignore_patterns: &'a [&'a IgnorePattern], |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
341 ) -> 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
|
342 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
|
343 .into_iter() |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
344 .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
|
345 .collect(); |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
346 let regexps = regexps?; |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
347 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
|
348 |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
349 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
|
350 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
|
351 |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
352 Ok((full_regex, func)) |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
353 } |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44520
diff
changeset
|
354 |
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
|
355 /// 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
|
356 /// |
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 /// 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
|
358 /// 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
|
359 /// 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
|
360 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
|
361 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
|
362 ) -> (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
|
363 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
|
364 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
|
365 |
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 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
|
367 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
|
368 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
|
369 } = 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
|
370 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
|
371 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
|
372 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
|
373 |
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 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
|
375 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
|
376 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
|
377 _ => 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
|
378 }) { |
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 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
|
380 } |
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 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
|
382 } |
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 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
|
384 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
|
385 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
|
386 } |
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 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
|
388 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
|
389 &[] 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
|
390 } 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
|
391 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
|
392 }); |
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 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
|
394 } |
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 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
|
396 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
|
397 &[] 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
|
398 } 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
|
399 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
|
400 }; |
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 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
|
402 } |
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 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
|
405 } |
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 (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
|
409 } |
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 /// 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
|
412 #[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
|
413 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
|
414 /// 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
|
415 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
|
416 /// 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
|
417 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
|
418 /// 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
|
419 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
|
420 } |
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 /// 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
|
423 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
|
424 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
|
425 ) -> 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
|
426 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
|
427 |
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 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
|
429 |
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 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
|
431 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
|
432 .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
|
433 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
|
434 _ => 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
|
435 })? |
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 .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
|
437 .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
|
438 ); |
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 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
|
440 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
|
441 .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
|
442 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
|
443 _ => 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
|
444 })? |
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 .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
|
446 .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
|
447 ); |
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 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
|
450 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
|
451 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
|
452 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
|
453 }) |
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 |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
456 /// 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
|
457 /// should be matched. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
458 fn build_match<'a, 'b>( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
459 ignore_patterns: &'a [IgnorePattern], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
460 root_dir: impl AsRef<Path>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
461 ) -> PatternResult<( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
462 Vec<u8>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
463 Box<dyn Fn(&HgPath) -> bool + 'b + Sync>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
464 Vec<PatternFileWarning>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
465 )> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
466 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
|
467 // For debugging and printing |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
468 let mut patterns = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
469 let mut all_warnings = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
470 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
471 let (subincludes, ignore_patterns) = |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
472 filter_subincludes(ignore_patterns, root_dir)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
473 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
474 if !subincludes.is_empty() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
475 // Build prefix-based matcher functions for subincludes |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
476 let mut submatchers = FastHashMap::default(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
477 let mut prefixes = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
478 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
479 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
|
480 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
|
481 all_warnings.extend(warnings); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
482 prefixes.push(prefix.to_owned()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
483 submatchers.insert(prefix.to_owned(), match_fn); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
484 } |
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 let match_subinclude = move |filename: &HgPath| { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
487 for prefix in prefixes.iter() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
488 if let Some(rel) = filename.relative_to(prefix) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
489 if (submatchers.get(prefix).unwrap())(rel) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
490 return true; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
491 } |
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 false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
495 }; |
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 match_funcs.push(Box::new(match_subinclude)); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
498 } |
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 if !ignore_patterns.is_empty() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
501 // 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
|
502 // with a regex. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
503 if ignore_patterns |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
504 .iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
505 .all(|k| k.syntax == PatternSyntax::RootFiles) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
506 { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
507 let dirs: HashSet<_> = ignore_patterns |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
508 .iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
509 .map(|k| k.pattern.to_owned()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
510 .collect(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
511 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
|
512 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
513 let match_func = move |path: &HgPath| -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
514 let path = path.as_bytes(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
515 let i = path.iter().rfind(|a| **a == b'/'); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
516 let dir = if let Some(i) = i { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
517 &path[..*i as usize] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
518 } else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
519 b"." |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
520 }; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
521 dirs.contains(dir.deref()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
522 }; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
523 match_funcs.push(Box::new(match_func)); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
524 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
525 patterns.extend(b"rootfilesin: "); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
526 dirs_vec.sort(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
527 patterns.extend(dirs_vec.escaped_bytes()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
528 } else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
529 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
|
530 patterns = new_re; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
531 match_funcs.push(match_func) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
532 } |
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 Ok(if match_funcs.len() == 1 { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
536 (patterns, match_funcs.remove(0), all_warnings) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
537 } else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
538 ( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
539 patterns, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
540 Box::new(move |f: &HgPath| -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
541 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
|
542 }), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
543 all_warnings, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
544 ) |
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 /// 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
|
549 /// 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
|
550 /// ignored. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
551 pub fn get_ignore_function<'a>( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
552 all_pattern_files: &[impl AsRef<Path>], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
553 root_dir: impl AsRef<Path>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
554 ) -> PatternResult<( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
555 impl for<'r> Fn(&'r HgPath) -> bool + Sync, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
556 Vec<PatternFileWarning>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
557 )> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
558 let mut all_patterns = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
559 let mut all_warnings = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
560 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
561 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
|
562 let (patterns, warnings) = |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
563 get_patterns_from_file(pattern_file, &root_dir)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
564 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
565 all_patterns.extend(patterns); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
566 all_warnings.extend(warnings); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
567 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
568 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
|
569 all_warnings.extend(warnings); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
570 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
|
571 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
572 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
573 impl<'a> IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
574 pub fn new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
575 ignore_patterns: Vec<IgnorePattern>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
576 root_dir: impl AsRef<Path>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
577 ) -> PatternResult<(Self, Vec<PatternFileWarning>)> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
578 let (patterns, match_fn, warnings) = |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
579 build_match(&ignore_patterns, root_dir)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
580 let RootsDirsAndParents { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
581 roots, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
582 dirs, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
583 parents, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
584 } = roots_dirs_and_parents(&ignore_patterns)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
585 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
586 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
|
587 PatternSyntax::Path | PatternSyntax::RelPath => true, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
588 _ => false, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
589 }); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
590 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
591 Ok(( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
592 Self { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
593 patterns, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
594 match_fn, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
595 prefix, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
596 roots, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
597 dirs, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
598 parents, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
599 }, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
600 warnings, |
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 } |
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 fn get_all_parents_children(&self) -> DirsChildrenMultiset { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
605 // TODO cache |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
606 let thing = self |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
607 .dirs |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
608 .iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
609 .chain(self.roots.iter()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
610 .chain(self.parents.iter()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
611 DirsChildrenMultiset::new(thing, Some(&self.parents)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
612 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
613 } |
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 impl<'a> Display for IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
616 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
617 write!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
618 f, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
619 "IncludeMatcher(includes='{}')", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
620 String::from_utf8_lossy(&self.patterns.escaped_bytes()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
621 ) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
622 } |
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 |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
625 #[cfg(test)] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
626 mod tests { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
627 use super::*; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
628 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
|
629 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
|
630 |
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 #[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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 ]; |
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 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
|
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 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 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
|
646 ), |
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 ); |
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 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
|
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 |
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 #[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
|
652 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
|
653 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
|
654 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
|
655 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
|
656 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
|
657 ]; |
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 |
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 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
|
660 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
|
661 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
|
662 |
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 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
|
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 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
|
666 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
|
667 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
|
668 |
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 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
|
670 roots_dirs_and_parents(&pats).unwrap(), |
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 RootsDirsAndParents {roots, dirs, 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
|
672 ); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
673 } |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
674 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
675 #[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
676 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
|
677 // Visitchildrenset |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
678 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
|
679 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
|
680 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
681 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
|
682 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
|
683 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
684 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
|
685 VisitChildrenSet::Set(set) |
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 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
688 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
|
689 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
|
690 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
691 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
|
692 VisitChildrenSet::Set(set) |
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 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
695 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
|
696 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
|
697 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
698 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
|
699 VisitChildrenSet::Set(set) |
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 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
702 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
703 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
|
704 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
705 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
706 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
707 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
|
708 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
709 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
710 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
711 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
|
712 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
713 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
714 } |
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 #[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
717 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
|
718 let files = vec![ |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
719 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
|
720 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
|
721 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
|
722 // 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
|
723 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
|
724 ]; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
725 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
|
726 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
727 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
|
728 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
|
729 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
|
730 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
731 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
|
732 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
733 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
734 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
735 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
|
736 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
|
737 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
|
738 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
739 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
|
740 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
741 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
742 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
743 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
|
744 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
|
745 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
|
746 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
747 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
|
748 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
749 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
750 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
751 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
|
752 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
|
753 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
754 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
|
755 VisitChildrenSet::Set(set) |
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"file4.txt")); |
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/d")), |
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 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
764 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
765 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
|
766 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
767 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
768 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
769 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
|
770 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
771 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
772 } |
44522
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
773 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
774 #[cfg(feature = "with-re2")] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
775 #[test] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
776 fn test_includematcher() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
777 // VisitchildrensetPrefix |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
778 let (matcher, _) = IncludeMatcher::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
779 vec![IgnorePattern::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
780 PatternSyntax::RelPath, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
781 b"dir/subdir", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
782 Path::new(""), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
783 )], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
784 "", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
785 ) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
786 .unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
787 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
788 let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
789 set.insert(HgPath::new(b"dir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
790 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
791 matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
792 VisitChildrenSet::Set(set) |
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 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
795 let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
796 set.insert(HgPath::new(b"subdir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
797 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
798 matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
799 VisitChildrenSet::Set(set) |
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 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
802 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
|
803 VisitChildrenSet::Recursive |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
804 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
805 // 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
|
806 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
807 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
|
808 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
809 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
810 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
811 matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
812 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
813 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
814 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
815 // VisitchildrensetRootfilesin |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
816 let (matcher, _) = IncludeMatcher::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
817 vec![IgnorePattern::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
818 PatternSyntax::RootFiles, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
819 b"dir/subdir", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
820 Path::new(""), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
821 )], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
822 "", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
823 ) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
824 .unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
825 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
826 let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
827 set.insert(HgPath::new(b"dir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
828 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
829 matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
830 VisitChildrenSet::Set(set) |
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 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
833 let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
834 set.insert(HgPath::new(b"subdir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
835 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
836 matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
837 VisitChildrenSet::Set(set) |
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 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
840 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
841 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
|
842 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
843 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
844 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
845 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
|
846 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
847 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
848 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
849 matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
850 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
851 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
852 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
853 // VisitchildrensetGlob |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
854 let (matcher, _) = IncludeMatcher::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
855 vec![IgnorePattern::new( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
856 PatternSyntax::Glob, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
857 b"dir/z*", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
858 Path::new(""), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
859 )], |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
860 "", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
861 ) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
862 .unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
863 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
864 let mut set = HashSet::new(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
865 set.insert(HgPath::new(b"dir")); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
866 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
867 matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
868 VisitChildrenSet::Set(set) |
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 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
871 matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
872 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
873 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
874 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
875 matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
876 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
877 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
878 // OPT: these should probably be set(). |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
879 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
880 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
|
881 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
882 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
883 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
884 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
|
885 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
886 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44521
diff
changeset
|
887 } |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
888 } |