Mercurial > public > mercurial-scm > hg
annotate rust/hg-core/src/matchers.rs @ 44520:d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
These functions will be used to help build the upcoming `IncludeMatcher`.
Differential Revision: https://phab.mercurial-scm.org/D7923
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Fri, 17 Jan 2020 11:31:12 +0100 |
parents | 52d40f8fb82d |
children | a21881b40942 |
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::{ |
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
|
13 filepatterns::PatternResult, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
14 utils::hg_path::{HgPath, 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
|
15 DirsMultiset, DirstateMapError, IgnorePattern, PatternError, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
16 PatternSyntax, |
44519
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
17 }; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
18 use std::collections::HashSet; |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
19 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
|
20 use std::ops::Deref; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
22 #[derive(Debug, PartialEq)] |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43611
diff
changeset
|
23 pub enum VisitChildrenSet<'a> { |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
24 /// Don't visit anything |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
25 Empty, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
26 /// Only visit this directory |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
27 This, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
28 /// 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
|
29 /// 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
|
30 Set(HashSet<&'a HgPath>), |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
31 /// 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
|
32 Recursive, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
33 } |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
35 pub trait Matcher { |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
36 /// Explicitly listed files |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43611
diff
changeset
|
37 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
|
38 /// 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
|
39 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
|
40 /// 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
|
41 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
|
42 /// 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
|
43 /// 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
|
44 /// 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
|
45 /// 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
|
46 /// patterns. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
47 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
48 /// # Example |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
49 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
50 /// 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
|
51 /// 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
|
52 /// 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
|
53 /// are not). |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
54 /// |
44006
72bced4f2936
rust-matchers: fixing cargo doc
Georges Racinet <georges.racinet@octobus.net>
parents:
43914
diff
changeset
|
55 /// ```text |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
56 /// ```ignore |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
57 /// '' -> {'foo', 'qux'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
58 /// 'baz' -> set() |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
59 /// 'foo' -> {'bar'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
60 /// // 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
|
61 /// // 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
|
62 /// // 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
|
63 /// // `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
|
64 /// 'foo/bar' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
65 /// 'qux' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
66 /// ``` |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
67 /// # Important |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
68 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 /// 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
|
70 /// 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
|
71 /// 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
|
72 /// 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
|
73 /// 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
|
74 /// it may return `VisitChildrenSet::This`. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
75 /// 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
|
76 /// 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
|
77 /// 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
|
78 /// `VisitChildrenSet::This`). |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
79 fn visit_children_set( |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
80 &self, |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
81 directory: impl AsRef<HgPath>, |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
82 ) -> VisitChildrenSet; |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
83 /// 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
|
84 /// 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
|
85 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
|
86 /// 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
|
87 /// might be possible. |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
88 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
|
89 } |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
90 |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
91 /// Matches everything. |
43834
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43832
diff
changeset
|
92 ///``` |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43832
diff
changeset
|
93 /// 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
|
94 /// |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43832
diff
changeset
|
95 /// let matcher = AlwaysMatcher; |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43832
diff
changeset
|
96 /// |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
97 /// 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
|
98 /// 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
|
99 /// 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
|
100 /// 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
|
101 /// ``` |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
102 #[derive(Debug)] |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
103 pub struct AlwaysMatcher; |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
104 |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
105 impl Matcher for AlwaysMatcher { |
43832
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43611
diff
changeset
|
106 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
|
107 None |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
108 } |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
109 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
|
110 false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
111 } |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
112 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
|
113 true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
114 } |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
115 fn visit_children_set( |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
116 &self, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
117 _directory: impl AsRef<HgPath>, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
118 ) -> VisitChildrenSet { |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
119 VisitChildrenSet::Recursive |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
120 } |
43611
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
121 fn matches_everything(&self) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
122 true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
123 } |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
124 fn is_exact(&self) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
125 false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43438
diff
changeset
|
126 } |
43438
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
127 } |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
128 |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
129 /// 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
|
130 /// patterns. |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
131 /// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
132 ///``` |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
133 /// 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
|
134 /// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
135 /// 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
|
136 /// let matcher = FileMatcher::new(&files).unwrap(); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
137 /// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
138 /// 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
|
139 /// 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
|
140 /// 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
|
141 /// 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
|
142 /// ``` |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
143 #[derive(Debug)] |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
144 pub struct FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
145 files: HashSet<&'a HgPath>, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
146 dirs: DirsMultiset, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
147 } |
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 impl<'a> FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
150 pub fn new( |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
151 files: &'a [impl AsRef<HgPath>], |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
152 ) -> Result<Self, DirstateMapError> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
153 Ok(Self { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
154 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
|
155 dirs: DirsMultiset::from_manifest(files)?, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
156 }) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
157 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
158 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
|
159 self.files.contains(filename.as_ref()) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
160 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
161 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
162 |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
163 impl<'a> Matcher for FileMatcher<'a> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
164 fn file_set(&self) -> Option<&HashSet<&HgPath>> { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
165 Some(&self.files) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
166 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
167 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
|
168 self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
169 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
170 fn matches(&self, filename: impl AsRef<HgPath>) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
171 self.inner_matches(filename) |
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 fn visit_children_set( |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
174 &self, |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
175 directory: impl AsRef<HgPath>, |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
176 ) -> VisitChildrenSet { |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
177 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
|
178 return VisitChildrenSet::Empty; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
179 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
180 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
|
181 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
186 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
|
187 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
|
188 candidates = candidates |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
189 .iter() |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
190 .filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
191 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
|
192 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
|
193 } else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
194 None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
195 } |
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 .collect(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
198 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
199 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
200 // `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
|
201 // 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
|
202 // '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
|
203 // '/' 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
|
204 // 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
|
205 VisitChildrenSet::Set( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
206 candidates |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
207 .iter() |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
208 .filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
209 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
|
210 Some(*c) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
211 } else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
212 None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
213 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
214 }) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
215 .collect(), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
216 ) |
43914
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
217 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
218 fn matches_everything(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
219 false |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
220 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
221 fn is_exact(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
222 true |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
223 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43863
diff
changeset
|
224 } |
44519
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
225 |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
226 #[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
|
227 /// 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
|
228 /// pattern. |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
229 /// |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
230 /// 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
|
231 /// 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
|
232 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
|
233 pattern: &[u8], |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
234 ) -> 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
|
235 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
|
236 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
|
237 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
|
238 } |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
239 |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
240 #[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
|
241 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
|
242 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
|
243 } |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44353
diff
changeset
|
244 |
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
|
245 /// 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
|
246 /// |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
247 /// 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
|
248 /// 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
|
249 /// 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
|
250 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
|
251 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
|
252 ) -> (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
|
253 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
|
254 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
|
255 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 } = 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
|
260 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
|
261 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
|
262 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
|
263 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 _ => 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
|
268 }) { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
269 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
|
270 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
271 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
|
272 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
277 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
|
278 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
|
279 &[] 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
|
280 } 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
|
281 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
|
282 }); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
283 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
|
284 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
285 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
|
286 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
|
287 &[] 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
|
288 } 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
|
289 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
|
290 }; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
291 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
|
292 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
293 _ => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
294 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
|
295 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
296 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
297 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
298 (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
|
299 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
300 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
301 /// 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
|
302 #[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
|
303 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
|
304 /// 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
|
305 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
|
306 /// 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
|
307 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
|
308 /// 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
|
309 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
|
310 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
311 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
312 /// 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
|
313 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
|
314 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
|
315 ) -> 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
|
316 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
|
317 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
318 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
|
319 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
320 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
|
321 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
|
322 .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
|
323 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
|
324 _ => 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
|
325 })? |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
326 .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
|
327 .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
|
328 ); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
329 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
|
330 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
|
331 .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
|
332 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
|
333 _ => 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
|
334 })? |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
335 .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
|
336 .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
|
337 ); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
338 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 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
|
343 }) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
344 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
345 |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
346 #[cfg(test)] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
347 mod tests { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
348 use super::*; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
349 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
|
350 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
|
351 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
352 #[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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 ]; |
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 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
|
360 |
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 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 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
|
367 ), |
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 ); |
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 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
|
370 } |
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 |
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 #[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
|
373 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
|
374 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
|
375 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
|
376 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
|
377 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
|
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 |
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 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
|
381 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
|
382 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
|
383 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
384 let 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
|
385 |
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 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
|
387 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
|
388 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
|
389 |
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 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
|
391 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
|
392 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
|
393 ); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44519
diff
changeset
|
394 } |
44353
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
395 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
396 #[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
397 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
|
398 // Visitchildrenset |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
399 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
|
400 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
|
401 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
402 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
|
403 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
|
404 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
405 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
|
406 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
407 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
408 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
409 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
|
410 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
|
411 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
412 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
|
413 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
414 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
415 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
416 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
|
417 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
|
418 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
419 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
|
420 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
421 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
422 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
423 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
424 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
|
425 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
426 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
427 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
428 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
|
429 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
430 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
431 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
432 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
|
433 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
434 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
435 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
436 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
437 #[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
438 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
|
439 let files = vec![ |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
440 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
|
441 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
|
442 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
|
443 // 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
|
444 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
|
445 ]; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
446 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
|
447 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
452 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
|
453 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
454 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
455 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
456 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
|
457 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
|
458 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
|
459 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
460 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
|
461 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
462 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
463 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
464 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
|
465 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
|
466 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
|
467 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
468 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
|
469 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
470 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
471 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
472 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
|
473 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
|
474 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
475 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
|
476 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
477 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
478 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
|
479 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
|
480 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
481 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
|
482 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
483 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
484 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
485 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
486 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
|
487 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
488 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
489 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
490 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
|
491 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
492 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
493 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44006
diff
changeset
|
494 } |