Mercurial > public > mercurial-scm > hg-stable
annotate rust/hg-core/src/matchers.rs @ 51667:11a9e2fc0caf stable 6.8.1
relnotes: add 6.8.1
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 01 Aug 2024 15:38:24 +0200 |
parents | 74230abb2504 |
children | 71044315a536 918ceb5a3d25 |
rev | line source |
---|---|
43490
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 |
51113
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
10 use format_bytes::format_bytes; |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
11 use once_cell::sync::OnceCell; |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
12 |
44529
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44387
diff
changeset
|
13 use crate::{ |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
14 dirstate::dirs_multiset::DirsChildrenMultiset, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
15 filepatterns::{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
16 build_single_regex, filter_subincludes, get_patterns_from_file, |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
17 PatternFileWarning, PatternResult, |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
18 }, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
19 utils::{ |
51477
529a655874fb
matchers: fix the bug in rust PatternMatcher that made it cut off early
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51475
diff
changeset
|
20 files::{dir_ancestors, find_dirs}, |
50884
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50880
diff
changeset
|
21 hg_path::{HgPath, HgPathBuf, HgPathError}, |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
22 Escaped, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
23 }, |
50884
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50880
diff
changeset
|
24 DirsMultiset, FastHashMap, IgnorePattern, PatternError, PatternSyntax, |
44529
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44387
diff
changeset
|
25 }; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
26 |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
27 use crate::dirstate::status::IgnoreFnType; |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
28 use crate::filepatterns::normalize_path_bytes; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
29 use std::collections::HashSet; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
30 use std::fmt::{Display, Error, Formatter}; |
44604
e62052d0f377
rust-status: only involve ignore mechanism when needed
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44601
diff
changeset
|
31 use std::path::{Path, PathBuf}; |
51113
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
32 use std::{borrow::ToOwned, collections::BTreeSet}; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
34 #[derive(Debug, PartialEq)] |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
35 pub enum VisitChildrenSet { |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
36 /// Don't visit anything |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
37 Empty, |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
38 /// Visit this directory and probably its children |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
39 This, |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
40 /// Only visit the children (both files and directories) if they |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
41 /// are mentioned in this set. (empty set corresponds to [Empty]) |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
42 /// TODO Should we implement a `NonEmptyHashSet`? |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
43 Set(HashSet<HgPathBuf>), |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
44 /// Visit this directory and all subdirectories |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
45 /// (you can stop asking about the children set) |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
46 Recursive, |
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 |
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
49 pub trait Matcher: core::fmt::Debug { |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
50 /// Explicitly listed files |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
51 fn file_set(&self) -> Option<&HashSet<HgPathBuf>>; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
52 /// Returns whether `filename` is in `file_set` |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
53 fn exact_match(&self, filename: &HgPath) -> bool; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
54 /// Returns whether `filename` is matched by this matcher |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
55 fn matches(&self, filename: &HgPath) -> bool; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
56 /// 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
|
57 /// 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
|
58 /// 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
|
59 /// 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
|
60 /// patterns. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
61 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
62 /// # Example |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
63 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
64 /// 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
|
65 /// 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
|
66 /// 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
|
67 /// are not). |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
68 /// |
44009
72bced4f2936
rust-matchers: fixing cargo doc
Georges Racinet <georges.racinet@octobus.net>
parents:
43920
diff
changeset
|
69 /// ```text |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
70 /// ```ignore |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
71 /// '' -> {'foo', 'qux'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
72 /// 'baz' -> set() |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
73 /// 'foo' -> {'bar'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
74 /// // 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
|
75 /// // 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
|
76 /// // 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
|
77 /// // `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
|
78 /// 'foo/bar' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
79 /// 'qux' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
80 /// ``` |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
81 /// # Important |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
82 /// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
83 /// 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
|
84 /// 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
|
85 /// 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
|
86 /// 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
|
87 /// 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
|
88 /// it may return `VisitChildrenSet::This`. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
89 /// 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
|
90 /// 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
|
91 /// 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
|
92 /// `VisitChildrenSet::This`). |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
93 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet; |
43490
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. |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
96 fn matches_everything(&self) -> bool; |
43490
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. |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
99 fn is_exact(&self) -> bool; |
43490
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. |
43852
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43850
diff
changeset
|
103 ///``` |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43850
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:
43850
diff
changeset
|
105 /// |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43850
diff
changeset
|
106 /// let matcher = AlwaysMatcher; |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43850
diff
changeset
|
107 /// |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
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:
43874
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:
43874
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:
43874
diff
changeset
|
111 /// assert_eq!(matcher.matches(HgPath::new(br"re:.*\.c$")), true); |
43852
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43850
diff
changeset
|
112 /// ``` |
43490
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 { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
117 fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
43850
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43655
diff
changeset
|
118 None |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
119 } |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
120 fn exact_match(&self, _filename: &HgPath) -> bool { |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
121 false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
122 } |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
123 fn matches(&self, _filename: &HgPath) -> bool { |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
124 true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
125 } |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
126 fn visit_children_set(&self, _directory: &HgPath) -> VisitChildrenSet { |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
127 VisitChildrenSet::Recursive |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
128 } |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
129 fn matches_everything(&self) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
130 true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
131 } |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
132 fn is_exact(&self) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
133 false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43490
diff
changeset
|
134 } |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
135 } |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
136 |
49355
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
137 /// Matches nothing. |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
138 #[derive(Debug)] |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
139 pub struct NeverMatcher; |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
140 |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
141 impl Matcher for NeverMatcher { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
142 fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
143 None |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
144 } |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
145 fn exact_match(&self, _filename: &HgPath) -> bool { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
146 false |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
147 } |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
148 fn matches(&self, _filename: &HgPath) -> bool { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
149 false |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
150 } |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
151 fn visit_children_set(&self, _directory: &HgPath) -> VisitChildrenSet { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
152 VisitChildrenSet::Empty |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
153 } |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
154 fn matches_everything(&self) -> bool { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
155 false |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
156 } |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
157 fn is_exact(&self) -> bool { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
158 true |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
159 } |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
160 } |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49353
diff
changeset
|
161 |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
162 /// 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:
43874
diff
changeset
|
163 /// patterns. |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
164 /// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
165 ///``` |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
166 /// use hg::{ matchers::{Matcher, FileMatcher}, utils::hg_path::{HgPath, HgPathBuf} }; |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
167 /// |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
168 /// let files = vec![HgPathBuf::from_bytes(b"a.txt"), HgPathBuf::from_bytes(br"re:.*\.c$")]; |
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
169 /// let matcher = FileMatcher::new(files).unwrap(); |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
170 /// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
171 /// assert_eq!(matcher.matches(HgPath::new(b"a.txt")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
172 /// assert_eq!(matcher.matches(HgPath::new(b"b.txt")), false); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
173 /// assert_eq!(matcher.matches(HgPath::new(b"main.c")), false); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
174 /// assert_eq!(matcher.matches(HgPath::new(br"re:.*\.c$")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
175 /// ``` |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
176 #[derive(Debug)] |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
177 pub struct FileMatcher { |
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
178 files: HashSet<HgPathBuf>, |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
179 dirs: DirsMultiset, |
51113
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
180 sorted_visitchildrenset_candidates: OnceCell<BTreeSet<HgPathBuf>>, |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
181 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
182 |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
183 impl FileMatcher { |
50884
f50e71fdfcb4
rust: improve the type on DirsMultiset::from_manifest
Spencer Baugh <sbaugh@janestreet.com>
parents:
50880
diff
changeset
|
184 pub fn new(files: Vec<HgPathBuf>) -> Result<Self, HgPathError> { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
185 let dirs = DirsMultiset::from_manifest(&files)?; |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
186 Ok(Self { |
51118
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51113
diff
changeset
|
187 files: HashSet::from_iter(files), |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
188 dirs, |
51113
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
189 sorted_visitchildrenset_candidates: OnceCell::new(), |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
190 }) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
191 } |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
192 fn inner_matches(&self, filename: &HgPath) -> bool { |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
193 self.files.contains(filename.as_ref()) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
194 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
195 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
196 |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
197 impl Matcher for FileMatcher { |
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
198 fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
199 Some(&self.files) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
200 } |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
201 fn exact_match(&self, filename: &HgPath) -> bool { |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
202 self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
203 } |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
204 fn matches(&self, filename: &HgPath) -> bool { |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
205 self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
206 } |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
207 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
51113
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
208 if self.files.is_empty() || !self.dirs.contains(directory) { |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
209 return VisitChildrenSet::Empty; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
210 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
211 |
51113
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
212 let compute_candidates = || -> BTreeSet<HgPathBuf> { |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
213 let mut candidates: BTreeSet<HgPathBuf> = |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
214 self.dirs.iter().cloned().collect(); |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
215 candidates.extend(self.files.iter().cloned()); |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
216 candidates.remove(HgPath::new(b"")); |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
217 candidates |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
218 }; |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
219 let candidates = |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
220 if directory.as_ref().is_empty() { |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
221 compute_candidates() |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
222 } else { |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
223 let sorted_candidates = self |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
224 .sorted_visitchildrenset_candidates |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
225 .get_or_init(compute_candidates); |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
226 let directory_bytes = directory.as_ref().as_bytes(); |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
227 let start: HgPathBuf = |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
228 format_bytes!(b"{}/", directory_bytes).into(); |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
229 let start_len = start.len(); |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
230 // `0` sorts after `/` |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
231 let end = format_bytes!(b"{}0", directory_bytes).into(); |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
232 BTreeSet::from_iter(sorted_candidates.range(start..end).map( |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
233 |c| HgPathBuf::from_bytes(&c.as_bytes()[start_len..]), |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
234 )) |
687e192dae16
rust-matchers: fix quadratic complexity in `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50889
diff
changeset
|
235 }; |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
236 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
237 // `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:
44009
diff
changeset
|
238 // 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:
44009
diff
changeset
|
239 // '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:
44009
diff
changeset
|
240 // '/' 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:
44009
diff
changeset
|
241 // 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:
44009
diff
changeset
|
242 VisitChildrenSet::Set( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
243 candidates |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
244 .into_iter() |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
245 .filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
246 if c.bytes().all(|b| *b != b'/') { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
247 Some(c) |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
248 } else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
249 None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
250 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
251 }) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
252 .collect(), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
253 ) |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
254 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
255 fn matches_everything(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
256 false |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
257 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
258 fn is_exact(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
259 true |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
260 } |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43874
diff
changeset
|
261 } |
44529
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44387
diff
changeset
|
262 |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
263 /// Matches a set of (kind, pat, source) against a 'root' directory. |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
264 /// (Currently the 'root' directory is effectively always empty) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
265 /// ``` |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
266 /// use hg::{ |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
267 /// matchers::{PatternMatcher, Matcher}, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
268 /// IgnorePattern, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
269 /// PatternSyntax, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
270 /// utils::hg_path::{HgPath, HgPathBuf} |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
271 /// }; |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
272 /// use std::collections::HashSet; |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
273 /// use std::path::Path; |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
274 /// /// |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
275 /// let ignore_patterns : Vec<IgnorePattern> = |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
276 /// vec![IgnorePattern::new(PatternSyntax::Regexp, br".*\.c$", Path::new("")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
277 /// IgnorePattern::new(PatternSyntax::Path, b"foo/a", Path::new("")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
278 /// IgnorePattern::new(PatternSyntax::RelPath, b"b", Path::new("")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
279 /// IgnorePattern::new(PatternSyntax::Glob, b"*.h", Path::new("")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
280 /// ]; |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
281 /// let matcher = PatternMatcher::new(ignore_patterns).unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
282 /// /// |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
283 /// assert_eq!(matcher.matches(HgPath::new(b"main.c")), true); // matches re:.*\.c$ |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
284 /// assert_eq!(matcher.matches(HgPath::new(b"b.txt")), false); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
285 /// assert_eq!(matcher.matches(HgPath::new(b"foo/a")), true); // matches path:foo/a |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
286 /// assert_eq!(matcher.matches(HgPath::new(b"a")), false); // does not match path:b, since 'root' is 'foo' |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
287 /// assert_eq!(matcher.matches(HgPath::new(b"b")), true); // matches relpath:b, since 'root' is 'foo' |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
288 /// assert_eq!(matcher.matches(HgPath::new(b"lib.h")), true); // matches glob:*.h |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
289 /// assert_eq!(matcher.file_set().unwrap(), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
290 /// &HashSet::from([HgPathBuf::from_bytes(b""), HgPathBuf::from_bytes(b"foo/a"), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
291 /// HgPathBuf::from_bytes(b""), HgPathBuf::from_bytes(b"b")])); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
292 /// assert_eq!(matcher.exact_match(HgPath::new(b"foo/a")), true); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
293 /// assert_eq!(matcher.exact_match(HgPath::new(b"b")), true); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
294 /// assert_eq!(matcher.exact_match(HgPath::new(b"lib.h")), false); // exact matches are for (rel)path kinds |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
295 /// ``` |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
296 pub struct PatternMatcher<'a> { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
297 patterns: Vec<u8>, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
298 match_fn: IgnoreFnType<'a>, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
299 /// Whether all the patterns match a prefix (i.e. recursively) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
300 prefix: bool, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
301 files: HashSet<HgPathBuf>, |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
302 dirs_explicit: HashSet<HgPathBuf>, |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
303 dirs: DirsMultiset, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
304 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
305 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
306 impl core::fmt::Debug for PatternMatcher<'_> { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
307 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
308 f.debug_struct("PatternMatcher") |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
309 .field("patterns", &String::from_utf8_lossy(&self.patterns)) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
310 .field("prefix", &self.prefix) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
311 .field("files", &self.files) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
312 .field("dirs", &self.dirs) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
313 .finish() |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
314 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
315 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
316 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
317 impl<'a> PatternMatcher<'a> { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
318 pub fn new(ignore_patterns: Vec<IgnorePattern>) -> PatternResult<Self> { |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
319 let RootsDirsAndParents { |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
320 roots, |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
321 dirs: dirs_explicit, |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
322 parents, |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
323 } = roots_dirs_and_parents(&ignore_patterns)?; |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
324 let files = roots; |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
325 let dirs = parents; |
51118
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51113
diff
changeset
|
326 let files: HashSet<HgPathBuf> = HashSet::from_iter(files); |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
327 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
328 let prefix = ignore_patterns.iter().all(|k| { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
329 matches!(k.syntax, PatternSyntax::Path | PatternSyntax::RelPath) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
330 }); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
331 let (patterns, match_fn) = build_match(ignore_patterns, b"$")?; |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
332 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
333 Ok(Self { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
334 patterns, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
335 match_fn, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
336 prefix, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
337 files, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
338 dirs, |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
339 dirs_explicit, |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
340 }) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
341 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
342 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
343 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
344 impl<'a> Matcher for PatternMatcher<'a> { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
345 fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
346 Some(&self.files) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
347 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
348 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
349 fn exact_match(&self, filename: &HgPath) -> bool { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
350 self.files.contains(filename) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
351 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
352 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
353 fn matches(&self, filename: &HgPath) -> bool { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
354 if self.files.contains(filename) { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
355 return true; |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
356 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
357 (self.match_fn)(filename) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
358 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
359 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
360 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
361 if self.prefix && self.files.contains(directory) { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
362 return VisitChildrenSet::Recursive; |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
363 } |
51478
cae0be933434
match: small tweak to PatternMatcher.visit_children_set
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51477
diff
changeset
|
364 if self.dirs.contains(directory) { |
cae0be933434
match: small tweak to PatternMatcher.visit_children_set
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51477
diff
changeset
|
365 return VisitChildrenSet::This; |
cae0be933434
match: small tweak to PatternMatcher.visit_children_set
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51477
diff
changeset
|
366 } |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
367 if dir_ancestors(directory).any(|parent_dir| { |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
368 self.files.contains(parent_dir) |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
369 || self.dirs_explicit.contains(parent_dir) |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
370 }) { |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
371 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
372 } else { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
373 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
374 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
375 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
376 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
377 fn matches_everything(&self) -> bool { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
378 false |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
379 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
380 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
381 fn is_exact(&self) -> bool { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
382 false |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
383 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
384 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
385 |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
386 /// Matches files that are included in the ignore rules. |
44929
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
387 /// ``` |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
388 /// use hg::{ |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
389 /// matchers::{IncludeMatcher, Matcher}, |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
390 /// IgnorePattern, |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
391 /// PatternSyntax, |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
392 /// utils::hg_path::HgPath |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
393 /// }; |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
394 /// use std::path::Path; |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
395 /// /// |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
396 /// let ignore_patterns = |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
397 /// vec![IgnorePattern::new(PatternSyntax::RootGlob, b"this*", Path::new(""))]; |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
398 /// let matcher = IncludeMatcher::new(ignore_patterns).unwrap(); |
44929
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
399 /// /// |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
400 /// assert_eq!(matcher.matches(HgPath::new(b"testing")), false); |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
401 /// assert_eq!(matcher.matches(HgPath::new(b"this should work")), true); |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
402 /// assert_eq!(matcher.matches(HgPath::new(b"this also")), true); |
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
403 /// assert_eq!(matcher.matches(HgPath::new(b"but not this")), false); |
51294
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
404 /// /// |
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
405 /// let ignore_patterns = |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
406 /// vec![IgnorePattern::new(PatternSyntax::RootFilesIn, b"dir/subdir", Path::new(""))]; |
51294
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
407 /// let matcher = IncludeMatcher::new(ignore_patterns).unwrap(); |
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
408 /// /// |
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
409 /// assert!(!matcher.matches(HgPath::new(b"file"))); |
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
410 /// assert!(!matcher.matches(HgPath::new(b"dir/file"))); |
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
411 /// assert!(matcher.matches(HgPath::new(b"dir/subdir/file"))); |
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
412 /// assert!(!matcher.matches(HgPath::new(b"dir/subdir/subsubdir/file"))); |
44929
9f96beb9bafe
rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44911
diff
changeset
|
413 /// ``` |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
414 pub struct IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
415 patterns: Vec<u8>, |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
416 match_fn: IgnoreFnType<'a>, |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
417 /// Whether all the patterns match a prefix (i.e. recursively) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
418 prefix: bool, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
419 roots: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
420 dirs: HashSet<HgPathBuf>, |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
421 parents: DirsMultiset, |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
422 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
423 |
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
424 impl core::fmt::Debug for IncludeMatcher<'_> { |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
425 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
426 f.debug_struct("IncludeMatcher") |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
427 .field("patterns", &String::from_utf8_lossy(&self.patterns)) |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
428 .field("prefix", &self.prefix) |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
429 .field("roots", &self.roots) |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
430 .field("dirs", &self.dirs) |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
431 .field("parents", &self.parents) |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
432 .finish() |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
433 } |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
434 } |
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
435 |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
436 impl<'a> Matcher for IncludeMatcher<'a> { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
437 fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
438 None |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
439 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
440 |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
441 fn exact_match(&self, _filename: &HgPath) -> bool { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
442 false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
443 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
444 |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
445 fn matches(&self, filename: &HgPath) -> bool { |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
446 (self.match_fn)(filename) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
447 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
448 |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
449 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
450 let dir = directory; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
451 if self.prefix && self.roots.contains(dir) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
452 return VisitChildrenSet::Recursive; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
453 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
454 if self.roots.contains(HgPath::new(b"")) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
455 || self.roots.contains(dir) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
456 || self.dirs.contains(dir) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
457 || find_dirs(dir).any(|parent_dir| self.roots.contains(parent_dir)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
458 { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
459 return VisitChildrenSet::This; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
460 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
461 |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
462 if self.parents.contains(dir.as_ref()) { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
463 let multiset = self.get_all_parents_children(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
464 if let Some(children) = multiset.get(dir) { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
465 return VisitChildrenSet::Set( |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
466 children.iter().map(HgPathBuf::from).collect(), |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
467 ); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
468 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
469 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
470 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
471 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
472 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
473 fn matches_everything(&self) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
474 false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
475 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
476 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
477 fn is_exact(&self) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
478 false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
479 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
480 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
481 |
49351
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
482 /// The union of multiple matchers. Will match if any of the matchers match. |
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
483 #[derive(Debug)] |
49351
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
484 pub struct UnionMatcher { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
485 matchers: Vec<Box<dyn Matcher + Sync>>, |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
486 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
487 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
488 impl Matcher for UnionMatcher { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
489 fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
490 None |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
491 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
492 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
493 fn exact_match(&self, _filename: &HgPath) -> bool { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
494 false |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
495 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
496 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
497 fn matches(&self, filename: &HgPath) -> bool { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
498 self.matchers.iter().any(|m| m.matches(filename)) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
499 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
500 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
501 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
502 let mut result = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
503 let mut this = false; |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
504 for matcher in self.matchers.iter() { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
505 let visit = matcher.visit_children_set(directory); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
506 match visit { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
507 VisitChildrenSet::Empty => continue, |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
508 VisitChildrenSet::This => { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
509 this = true; |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
510 // Don't break, we might have an 'all' in here. |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
511 continue; |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
512 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
513 VisitChildrenSet::Set(set) => { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
514 result.extend(set); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
515 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
516 VisitChildrenSet::Recursive => { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
517 return visit; |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
518 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
519 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
520 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
521 if this { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
522 return VisitChildrenSet::This; |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
523 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
524 if result.is_empty() { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
525 VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
526 } else { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
527 VisitChildrenSet::Set(result) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
528 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
529 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
530 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
531 fn matches_everything(&self) -> bool { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
532 // TODO Maybe if all are AlwaysMatcher? |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
533 false |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
534 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
535 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
536 fn is_exact(&self) -> bool { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
537 false |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
538 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
539 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
540 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
541 impl UnionMatcher { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
542 pub fn new(matchers: Vec<Box<dyn Matcher + Sync>>) -> Self { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
543 Self { matchers } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
544 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
545 } |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
546 |
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
547 #[derive(Debug)] |
49353
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
548 pub struct IntersectionMatcher { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
549 m1: Box<dyn Matcher + Sync>, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
550 m2: Box<dyn Matcher + Sync>, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
551 files: Option<HashSet<HgPathBuf>>, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
552 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
553 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
554 impl Matcher for IntersectionMatcher { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
555 fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
556 self.files.as_ref() |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
557 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
558 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
559 fn exact_match(&self, filename: &HgPath) -> bool { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
560 self.files.as_ref().map_or(false, |f| f.contains(filename)) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
561 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
562 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
563 fn matches(&self, filename: &HgPath) -> bool { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
564 self.m1.matches(filename) && self.m2.matches(filename) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
565 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
566 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
567 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
568 let m1_set = self.m1.visit_children_set(directory); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
569 if m1_set == VisitChildrenSet::Empty { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
570 return VisitChildrenSet::Empty; |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
571 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
572 let m2_set = self.m2.visit_children_set(directory); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
573 if m2_set == VisitChildrenSet::Empty { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
574 return VisitChildrenSet::Empty; |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
575 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
576 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
577 if m1_set == VisitChildrenSet::Recursive { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
578 return m2_set; |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
579 } else if m2_set == VisitChildrenSet::Recursive { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
580 return m1_set; |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
581 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
582 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
583 match (&m1_set, &m2_set) { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
584 (VisitChildrenSet::Recursive, _) => m2_set, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
585 (_, VisitChildrenSet::Recursive) => m1_set, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
586 (VisitChildrenSet::This, _) | (_, VisitChildrenSet::This) => { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
587 VisitChildrenSet::This |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
588 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
589 (VisitChildrenSet::Set(m1), VisitChildrenSet::Set(m2)) => { |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
590 let set: HashSet<_> = m1.intersection(m2).cloned().collect(); |
49353
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
591 if set.is_empty() { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
592 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
593 } else { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
594 VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
595 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
596 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
597 _ => unreachable!(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
598 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
599 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
600 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
601 fn matches_everything(&self) -> bool { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
602 self.m1.matches_everything() && self.m2.matches_everything() |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
603 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
604 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
605 fn is_exact(&self) -> bool { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
606 self.m1.is_exact() || self.m2.is_exact() |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
607 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
608 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
609 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
610 impl IntersectionMatcher { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
611 pub fn new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
612 mut m1: Box<dyn Matcher + Sync>, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
613 mut m2: Box<dyn Matcher + Sync>, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
614 ) -> Self { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
615 let files = if m1.is_exact() || m2.is_exact() { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
616 if !m1.is_exact() { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
617 std::mem::swap(&mut m1, &mut m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
618 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
619 m1.file_set().map(|m1_files| { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
620 m1_files.iter().cloned().filter(|f| m2.matches(f)).collect() |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
621 }) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
622 } else { |
50880
e037af7de2ce
rust-matchers: better support file_set in IntersectionMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50695
diff
changeset
|
623 // without exact input file sets, we can't do an exact |
e037af7de2ce
rust-matchers: better support file_set in IntersectionMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50695
diff
changeset
|
624 // intersection, so we must over-approximate by |
e037af7de2ce
rust-matchers: better support file_set in IntersectionMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50695
diff
changeset
|
625 // unioning instead |
e037af7de2ce
rust-matchers: better support file_set in IntersectionMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50695
diff
changeset
|
626 m1.file_set().map(|m1_files| match m2.file_set() { |
e037af7de2ce
rust-matchers: better support file_set in IntersectionMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50695
diff
changeset
|
627 Some(m2_files) => m1_files.union(m2_files).cloned().collect(), |
e037af7de2ce
rust-matchers: better support file_set in IntersectionMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50695
diff
changeset
|
628 None => m1_files.iter().cloned().collect(), |
e037af7de2ce
rust-matchers: better support file_set in IntersectionMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50695
diff
changeset
|
629 }) |
49353
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
630 }; |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
631 Self { m1, m2, files } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
632 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
633 } |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
634 |
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49492
diff
changeset
|
635 #[derive(Debug)] |
49492
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
636 pub struct DifferenceMatcher { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
637 base: Box<dyn Matcher + Sync>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
638 excluded: Box<dyn Matcher + Sync>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
639 files: Option<HashSet<HgPathBuf>>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
640 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
641 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
642 impl Matcher for DifferenceMatcher { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
643 fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
644 self.files.as_ref() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
645 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
646 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
647 fn exact_match(&self, filename: &HgPath) -> bool { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
648 self.files.as_ref().map_or(false, |f| f.contains(filename)) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
649 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
650 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
651 fn matches(&self, filename: &HgPath) -> bool { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
652 self.base.matches(filename) && !self.excluded.matches(filename) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
653 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
654 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
655 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
656 let excluded_set = self.excluded.visit_children_set(directory); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
657 if excluded_set == VisitChildrenSet::Recursive { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
658 return VisitChildrenSet::Empty; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
659 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
660 let base_set = self.base.visit_children_set(directory); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
661 // Possible values for base: 'recursive', 'this', set(...), set() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
662 // Possible values for excluded: 'this', set(...), set() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
663 // If excluded has nothing under here that we care about, return base, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
664 // even if it's 'recursive'. |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
665 if excluded_set == VisitChildrenSet::Empty { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
666 return base_set; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
667 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
668 match base_set { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
669 VisitChildrenSet::This | VisitChildrenSet::Recursive => { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
670 // Never return 'recursive' here if excluded_set is any kind of |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
671 // non-empty (either 'this' or set(foo)), since excluded might |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
672 // return set() for a subdirectory. |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
673 VisitChildrenSet::This |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
674 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
675 set => { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
676 // Possible values for base: set(...), set() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
677 // Possible values for excluded: 'this', set(...) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
678 // We ignore excluded set results. They're possibly incorrect: |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
679 // base = path:dir/subdir |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
680 // excluded=rootfilesin:dir, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
681 // visit_children_set(''): |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
682 // base returns {'dir'}, excluded returns {'dir'}, if we |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
683 // subtracted we'd return set(), which is *not* correct, we |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
684 // still need to visit 'dir'! |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
685 set |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
686 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
687 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
688 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
689 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
690 fn matches_everything(&self) -> bool { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
691 false |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
692 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
693 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
694 fn is_exact(&self) -> bool { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
695 self.base.is_exact() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
696 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
697 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
698 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
699 impl DifferenceMatcher { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
700 pub fn new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
701 base: Box<dyn Matcher + Sync>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
702 excluded: Box<dyn Matcher + Sync>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
703 ) -> Self { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
704 let base_is_exact = base.is_exact(); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
705 let base_files = base.file_set().map(ToOwned::to_owned); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
706 let mut new = Self { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
707 base, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
708 excluded, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
709 files: None, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
710 }; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
711 if base_is_exact { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
712 new.files = base_files.map(|files| { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
713 files.iter().cloned().filter(|f| new.matches(f)).collect() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
714 }); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
715 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
716 new |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
717 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
718 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
719 |
49564
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
720 /// Wraps [`regex::bytes::Regex`] to improve performance in multithreaded |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
721 /// contexts. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
722 /// |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
723 /// The `status` algorithm makes heavy use of threads, and calling `is_match` |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
724 /// from many threads at once is prone to contention, probably within the |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
725 /// scratch space needed as the regex DFA is built lazily. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
726 /// |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
727 /// We are in the process of raising the issue upstream, but for now |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
728 /// the workaround used here is to store the `Regex` in a lazily populated |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
729 /// thread-local variable, sharing the initial read-only compilation, but |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
730 /// not the lazy dfa scratch space mentioned above. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
731 /// |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
732 /// This reduces the contention observed with 16+ threads, but does not |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
733 /// completely remove it. Hopefully this can be addressed upstream. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
734 struct RegexMatcher { |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
735 /// Compiled at the start of the status algorithm, used as a base for |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
736 /// cloning in each thread-local `self.local`, thus sharing the expensive |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
737 /// first compilation. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
738 base: regex::bytes::Regex, |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
739 /// Thread-local variable that holds the `Regex` that is actually queried |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
740 /// from each thread. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
741 local: thread_local::ThreadLocal<regex::bytes::Regex>, |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
742 } |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
743 |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
744 impl RegexMatcher { |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
745 /// Returns whether the path matches the stored `Regex`. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
746 pub fn is_match(&self, path: &HgPath) -> bool { |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
747 self.local |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
748 .get_or(|| self.base.clone()) |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
749 .is_match(path.as_bytes()) |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
750 } |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
751 } |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
752 |
51447
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
753 /// Return a `RegexBuilder` from a bytes pattern |
44601
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
754 /// |
51447
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
755 /// This works around the fact that even if it works on byte haysacks, |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
756 /// [`regex::bytes::Regex`] still uses UTF-8 patterns. |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
757 pub fn re_bytes_builder(pattern: &[u8]) -> regex::bytes::RegexBuilder { |
44601
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
758 use std::io::Write; |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
759 |
44891
ad1ec40975aa
rust-regex: fix issues with regex anchoring and performance
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44880
diff
changeset
|
760 // The `regex` crate adds `.*` to the start and end of expressions if there |
ad1ec40975aa
rust-regex: fix issues with regex anchoring and performance
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44880
diff
changeset
|
761 // are no anchors, so add the start anchor. |
ad1ec40975aa
rust-regex: fix issues with regex anchoring and performance
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44880
diff
changeset
|
762 let mut escaped_bytes = vec![b'^', b'(', b'?', b':']; |
44601
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
763 for byte in pattern { |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
764 if *byte > 127 { |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
765 write!(escaped_bytes, "\\x{:x}", *byte).unwrap(); |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
766 } else { |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
767 escaped_bytes.push(*byte); |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
768 } |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
769 } |
44891
ad1ec40975aa
rust-regex: fix issues with regex anchoring and performance
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44880
diff
changeset
|
770 escaped_bytes.push(b')'); |
44601
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
771 |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
772 // Avoid the cost of UTF8 checking |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
773 // |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
774 // # Safety |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
775 // This is safe because we escaped all non-ASCII bytes. |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
776 let pattern_string = unsafe { String::from_utf8_unchecked(escaped_bytes) }; |
51447
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
777 regex::bytes::RegexBuilder::new(&pattern_string) |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
778 } |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
779 |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
780 /// Returns a function that matches an `HgPath` against the given regex |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
781 /// pattern. |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
782 /// |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
783 /// This can fail when the pattern is invalid or not supported by the |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
784 /// underlying engine (the `regex` crate), for instance anything with |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
785 /// back-references. |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
786 #[logging_timer::time("trace")] |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
787 fn re_matcher(pattern: &[u8]) -> PatternResult<RegexMatcher> { |
5633de951d34
rust-matchers: raw regular expression builder
Georges Racinet <georges.racinet@octobus.net>
parents:
51294
diff
changeset
|
788 let re = re_bytes_builder(pattern) |
44601
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
789 .unicode(false) |
44762
b15a37d85dbe
rust-regex: increase the DFA size limit for the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44604
diff
changeset
|
790 // Big repos with big `.hgignore` will hit the default limit and |
b15a37d85dbe
rust-regex: increase the DFA size limit for the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44604
diff
changeset
|
791 // incur a significant performance hit. One repo's `hg status` hit |
b15a37d85dbe
rust-regex: increase the DFA size limit for the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44604
diff
changeset
|
792 // multiple *minutes*. |
b15a37d85dbe
rust-regex: increase the DFA size limit for the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44604
diff
changeset
|
793 .dfa_size_limit(50 * (1 << 20)) |
44601
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
794 .build() |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
795 .map_err(|e| PatternError::UnsupportedSyntax(e.to_string()))?; |
496868f1030c
rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44551
diff
changeset
|
796 |
49564
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
797 Ok(RegexMatcher { |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
798 base: re, |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
799 local: Default::default(), |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
800 }) |
44529
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44387
diff
changeset
|
801 } |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44387
diff
changeset
|
802 |
44531
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44530
diff
changeset
|
803 /// 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:
44530
diff
changeset
|
804 /// said regex formed by the given ignore patterns. |
51118
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51113
diff
changeset
|
805 fn build_regex_match<'a>( |
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51113
diff
changeset
|
806 ignore_patterns: &[IgnorePattern], |
50885
090658724abf
rust: de-hardcode glob_suffix
Spencer Baugh <sbaugh@janestreet.com>
parents:
50884
diff
changeset
|
807 glob_suffix: &[u8], |
51118
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51113
diff
changeset
|
808 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'a>)> { |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
809 let mut regexps = vec![]; |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
810 let mut exact_set = HashSet::new(); |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
811 |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
812 for pattern in ignore_patterns { |
50885
090658724abf
rust: de-hardcode glob_suffix
Spencer Baugh <sbaugh@janestreet.com>
parents:
50884
diff
changeset
|
813 if let Some(re) = build_single_regex(pattern, glob_suffix)? { |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
814 regexps.push(re); |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
815 } else { |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
816 let exact = normalize_path_bytes(&pattern.pattern); |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
817 exact_set.insert(HgPathBuf::from_bytes(&exact)); |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
818 } |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
819 } |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
820 |
44531
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44530
diff
changeset
|
821 let full_regex = regexps.join(&b'|'); |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44530
diff
changeset
|
822 |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
823 // An empty pattern would cause the regex engine to incorrectly match the |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
824 // (empty) root directory |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
825 let func = if !(regexps.is_empty()) { |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
826 let matcher = re_matcher(&full_regex)?; |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
827 let func = move |filename: &HgPath| { |
49564
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49550
diff
changeset
|
828 exact_set.contains(filename) || matcher.is_match(filename) |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
829 }; |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
830 Box::new(func) as IgnoreFnType |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
831 } else { |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
832 let func = move |filename: &HgPath| exact_set.contains(filename); |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
833 Box::new(func) as IgnoreFnType |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44861
diff
changeset
|
834 }; |
44531
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44530
diff
changeset
|
835 |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44530
diff
changeset
|
836 Ok((full_regex, func)) |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44530
diff
changeset
|
837 } |
a21881b40942
rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44530
diff
changeset
|
838 |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
839 /// 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:
44529
diff
changeset
|
840 /// |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
841 /// 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:
44529
diff
changeset
|
842 /// 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:
44529
diff
changeset
|
843 /// 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:
44529
diff
changeset
|
844 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:
44529
diff
changeset
|
845 ignore_patterns: &[IgnorePattern], |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
846 ) -> (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:
44529
diff
changeset
|
847 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:
44529
diff
changeset
|
848 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:
44529
diff
changeset
|
849 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
850 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:
44529
diff
changeset
|
851 let IgnorePattern { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
852 syntax, pattern, .. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
853 } = ignore_pattern; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
854 match syntax { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
855 PatternSyntax::RootGlob | PatternSyntax::Glob => { |
48311
6d69e83e6b6e
rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
47415
diff
changeset
|
856 let mut root = HgPathBuf::new(); |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
857 for p in pattern.split(|c| *c == b'/') { |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
858 if p.iter() |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
859 .any(|c| matches!(*c, b'[' | b'{' | b'*' | b'?')) |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
860 { |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
861 break; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
862 } |
48311
6d69e83e6b6e
rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
47415
diff
changeset
|
863 root.push(HgPathBuf::from_bytes(p).as_ref()); |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
864 } |
48311
6d69e83e6b6e
rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
47415
diff
changeset
|
865 roots.push(root); |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
866 } |
50695
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
867 PatternSyntax::Path |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
868 | PatternSyntax::RelPath |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
869 | PatternSyntax::FilePath => { |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
870 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:
44529
diff
changeset
|
871 &[] as &[u8] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
872 } else { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
873 pattern |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
874 }); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
875 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:
44529
diff
changeset
|
876 } |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
877 PatternSyntax::RootFilesIn => { |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
878 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:
44529
diff
changeset
|
879 &[] as &[u8] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
880 } else { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
881 pattern |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
882 }; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
883 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:
44529
diff
changeset
|
884 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
885 _ => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
886 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:
44529
diff
changeset
|
887 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
888 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
889 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
890 (roots, dirs) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
891 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
892 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
893 /// 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:
44529
diff
changeset
|
894 #[derive(Debug, PartialEq)] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
895 struct RootsDirsAndParents { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
896 /// 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:
44529
diff
changeset
|
897 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:
44529
diff
changeset
|
898 /// 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:
44529
diff
changeset
|
899 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:
44529
diff
changeset
|
900 /// Implicitly required directories to go to items in either roots or dirs |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
901 pub parents: DirsMultiset, |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
902 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
903 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
904 /// 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:
44529
diff
changeset
|
905 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:
44529
diff
changeset
|
906 ignore_patterns: &[IgnorePattern], |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
907 ) -> PatternResult<RootsDirsAndParents> { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
908 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:
44529
diff
changeset
|
909 |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
910 let mut parents = DirsMultiset::from_manifest(&dirs)?; |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
911 |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
912 for path in &roots { |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
913 parents.add_path(path)? |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
914 } |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
915 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
916 Ok(RootsDirsAndParents { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
917 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:
44529
diff
changeset
|
918 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:
44529
diff
changeset
|
919 parents, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
920 }) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
921 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
922 |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
923 /// 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:
44531
diff
changeset
|
924 /// should be matched. |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
925 fn build_match<'a>( |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
926 ignore_patterns: Vec<IgnorePattern>, |
50885
090658724abf
rust: de-hardcode glob_suffix
Spencer Baugh <sbaugh@janestreet.com>
parents:
50884
diff
changeset
|
927 glob_suffix: &[u8], |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
928 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'a>)> { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
929 let mut match_funcs: Vec<IgnoreFnType<'a>> = vec![]; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
930 // For debugging and printing |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
931 let mut patterns = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
932 |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
933 let (subincludes, ignore_patterns) = filter_subincludes(ignore_patterns)?; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
934 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
935 if !subincludes.is_empty() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
936 // Build prefix-based matcher functions for subincludes |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
937 let mut submatchers = FastHashMap::default(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
938 let mut prefixes = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
939 |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
940 for sub_include in subincludes { |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
941 let matcher = IncludeMatcher::new(sub_include.included_patterns)?; |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
942 let match_fn = |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
943 Box::new(move |path: &HgPath| matcher.matches(path)); |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
944 prefixes.push(sub_include.prefix.clone()); |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
945 submatchers.insert(sub_include.prefix.clone(), match_fn); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
946 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
947 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
948 let match_subinclude = move |filename: &HgPath| { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
949 for prefix in prefixes.iter() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
950 if let Some(rel) = filename.relative_to(prefix) { |
44998
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44929
diff
changeset
|
951 if (submatchers[prefix])(rel) { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
952 return true; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
953 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
954 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
955 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
956 false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
957 }; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
958 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
959 match_funcs.push(Box::new(match_subinclude)); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
960 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
961 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
962 if !ignore_patterns.is_empty() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
963 // Either do dumb matching if all patterns are rootfiles, or match |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
964 // with a regex. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
965 if ignore_patterns |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
966 .iter() |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
967 .all(|k| k.syntax == PatternSyntax::RootFilesIn) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
968 { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
969 let dirs: HashSet<_> = ignore_patterns |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
970 .iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
971 .map(|k| k.pattern.to_owned()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
972 .collect(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
973 let mut dirs_vec: Vec<_> = dirs.iter().cloned().collect(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
974 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
975 let match_func = move |path: &HgPath| -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
976 let path = path.as_bytes(); |
51294
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
977 let i = path.iter().rposition(|a| *a == b'/'); |
bec6e9c108fd
matchers: use correct method for finding index in vector
Martin von Zweigbergk <martinvonz@google.com>
parents:
51118
diff
changeset
|
978 let dir = if let Some(i) = i { &path[..i] } else { b"." }; |
51118
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51113
diff
changeset
|
979 dirs.contains(dir) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
980 }; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
981 match_funcs.push(Box::new(match_func)); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
982 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
983 patterns.extend(b"rootfilesin: "); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
984 dirs_vec.sort(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
985 patterns.extend(dirs_vec.escaped_bytes()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
986 } else { |
50885
090658724abf
rust: de-hardcode glob_suffix
Spencer Baugh <sbaugh@janestreet.com>
parents:
50884
diff
changeset
|
987 let (new_re, match_func) = |
090658724abf
rust: de-hardcode glob_suffix
Spencer Baugh <sbaugh@janestreet.com>
parents:
50884
diff
changeset
|
988 build_regex_match(&ignore_patterns, glob_suffix)?; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
989 patterns = new_re; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
990 match_funcs.push(match_func) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
991 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
992 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
993 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
994 Ok(if match_funcs.len() == 1 { |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
995 (patterns, match_funcs.remove(0)) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
996 } else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
997 ( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
998 patterns, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
999 Box::new(move |f: &HgPath| -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1000 match_funcs.iter().any(|match_func| match_func(f)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1001 }), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1002 ) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1003 }) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1004 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1005 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1006 /// Parses all "ignore" files with their recursive includes and returns a |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1007 /// 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:
44531
diff
changeset
|
1008 /// ignored. |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1009 pub fn get_ignore_matcher<'a>( |
47415
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1010 mut all_pattern_files: Vec<PathBuf>, |
47384
777c3d231913
rust: Make some file path parameters less generic
Simon Sapin <simon.sapin@octobus.net>
parents:
45610
diff
changeset
|
1011 root_dir: &Path, |
49550
363923bd51cd
dirstate-v2: hash the source of the ignore patterns as well
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49500
diff
changeset
|
1012 inspect_pattern_bytes: &mut impl FnMut(&Path, &[u8]), |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1013 ) -> PatternResult<(IncludeMatcher<'a>, Vec<PatternFileWarning>)> { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1014 let mut all_patterns = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1015 let mut all_warnings = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1016 |
47415
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1017 // Sort to make the ordering of calls to `inspect_pattern_bytes` |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1018 // deterministic even if the ordering of `all_pattern_files` is not (such |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1019 // as when a iteration order of a Python dict or Rust HashMap is involved). |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1020 // Sort by "string" representation instead of the default by component |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1021 // (with a Rust-specific definition of a component) |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1022 all_pattern_files |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1023 .sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str())); |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1024 |
47384
777c3d231913
rust: Make some file path parameters less generic
Simon Sapin <simon.sapin@octobus.net>
parents:
45610
diff
changeset
|
1025 for pattern_file in &all_pattern_files { |
47415
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1026 let (patterns, warnings) = get_patterns_from_file( |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1027 pattern_file, |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1028 root_dir, |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1029 inspect_pattern_bytes, |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
1030 )?; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1031 |
44604
e62052d0f377
rust-status: only involve ignore mechanism when needed
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44601
diff
changeset
|
1032 all_patterns.extend(patterns.to_owned()); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1033 all_warnings.extend(warnings); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1034 } |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1035 let matcher = IncludeMatcher::new(all_patterns)?; |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1036 Ok((matcher, all_warnings)) |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1037 } |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1038 |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1039 /// Parses all "ignore" files with their recursive includes and returns a |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1040 /// function that checks whether a given file (in the general sense) should be |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1041 /// ignored. |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1042 pub fn get_ignore_function<'a>( |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1043 all_pattern_files: Vec<PathBuf>, |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1044 root_dir: &Path, |
49550
363923bd51cd
dirstate-v2: hash the source of the ignore patterns as well
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49500
diff
changeset
|
1045 inspect_pattern_bytes: &mut impl FnMut(&Path, &[u8]), |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1046 ) -> PatternResult<(IgnoreFnType<'a>, Vec<PatternFileWarning>)> { |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1047 let res = |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1048 get_ignore_matcher(all_pattern_files, root_dir, inspect_pattern_bytes); |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1049 res.map(|(matcher, all_warnings)| { |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1050 let res: IgnoreFnType<'a> = |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1051 Box::new(move |path: &HgPath| matcher.matches(path)); |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1052 |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1053 (res, all_warnings) |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1054 }) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1055 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1056 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1057 impl<'a> IncludeMatcher<'a> { |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1058 pub fn new(ignore_patterns: Vec<IgnorePattern>) -> PatternResult<Self> { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1059 let RootsDirsAndParents { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1060 roots, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1061 dirs, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1062 parents, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1063 } = roots_dirs_and_parents(&ignore_patterns)?; |
50003
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
1064 let prefix = ignore_patterns.iter().all(|k| { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49986
diff
changeset
|
1065 matches!(k.syntax, PatternSyntax::Path | PatternSyntax::RelPath) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1066 }); |
50885
090658724abf
rust: de-hardcode glob_suffix
Spencer Baugh <sbaugh@janestreet.com>
parents:
50884
diff
changeset
|
1067 let (patterns, match_fn) = build_match(ignore_patterns, b"(?:/|$)")?; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1068 |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1069 Ok(Self { |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1070 patterns, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1071 match_fn, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1072 prefix, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1073 roots, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1074 dirs, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1075 parents, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1076 }) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1077 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1078 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1079 fn get_all_parents_children(&self) -> DirsChildrenMultiset { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1080 // TODO cache |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1081 let thing = self |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1082 .dirs |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1083 .iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1084 .chain(self.roots.iter()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1085 .chain(self.parents.iter()); |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1086 DirsChildrenMultiset::new(thing, Some(self.parents.iter())) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1087 } |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1088 |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1089 pub fn debug_get_patterns(&self) -> &[u8] { |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1090 self.patterns.as_ref() |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
1091 } |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1092 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1093 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1094 impl<'a> Display for IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1095 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { |
44880
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44879
diff
changeset
|
1096 // XXX What about exact matches? |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44879
diff
changeset
|
1097 // I'm not sure it's worth it to clone the HashSet and keep it |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44879
diff
changeset
|
1098 // around just in case someone wants to display the matcher, plus |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44879
diff
changeset
|
1099 // it's going to be unreadable after a few entries, but we need to |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44879
diff
changeset
|
1100 // inform in this display that exact matches are being used and are |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44879
diff
changeset
|
1101 // (on purpose) missing from the `includes`. |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1102 write!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1103 f, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1104 "IncludeMatcher(includes='{}')", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1105 String::from_utf8_lossy(&self.patterns.escaped_bytes()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1106 ) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1107 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1108 } |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1109 |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1110 #[cfg(test)] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1111 mod tests { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1112 use super::*; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1113 use pretty_assertions::assert_eq; |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
1114 use std::collections::BTreeMap; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
1115 use std::collections::BTreeSet; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
1116 use std::fmt::Debug; |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1117 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:
44529
diff
changeset
|
1118 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1119 #[test] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1120 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:
44529
diff
changeset
|
1121 let pats = vec![ |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1122 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:
44529
diff
changeset
|
1123 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:
44529
diff
changeset
|
1124 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:
44529
diff
changeset
|
1125 ]; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1126 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:
44529
diff
changeset
|
1127 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1128 assert_eq!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1129 roots, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1130 vec!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1131 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:
44529
diff
changeset
|
1132 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:
44529
diff
changeset
|
1133 HgPathBuf::new() |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1134 ), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1135 ); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1136 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:
44529
diff
changeset
|
1137 } |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1138 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1139 #[test] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1140 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:
44529
diff
changeset
|
1141 let pats = vec![ |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1142 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:
44529
diff
changeset
|
1143 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:
44529
diff
changeset
|
1144 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:
44529
diff
changeset
|
1145 ]; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1146 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1147 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:
44529
diff
changeset
|
1148 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:
44529
diff
changeset
|
1149 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:
44529
diff
changeset
|
1150 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1151 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:
44529
diff
changeset
|
1152 |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1153 let parents = DirsMultiset::from_manifest(&[ |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1154 HgPathBuf::from_bytes(b"x"), |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1155 HgPathBuf::from_bytes(b"g/x"), |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1156 HgPathBuf::from_bytes(b"g/y"), |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1157 ]) |
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1158 .unwrap(); |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1159 |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1160 assert_eq!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1161 roots_dirs_and_parents(&pats).unwrap(), |
44534
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1162 RootsDirsAndParents { |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1163 roots, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1164 dirs, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1165 parents |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1166 } |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1167 ); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1168 } |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1169 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1170 #[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1171 fn test_filematcher_visit_children_set() { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1172 // Visitchildrenset |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1173 let files = vec![HgPathBuf::from_bytes(b"dir/subdir/foo.txt")]; |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1174 let matcher = FileMatcher::new(files).unwrap(); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1175 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1176 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1177 set.insert(HgPathBuf::from_bytes(b"dir")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1178 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1179 matcher.visit_children_set(HgPath::new(b"")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1180 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1181 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1182 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1183 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1184 set.insert(HgPathBuf::from_bytes(b"subdir")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1185 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1186 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:
44009
diff
changeset
|
1187 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1188 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1189 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1190 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1191 set.insert(HgPathBuf::from_bytes(b"foo.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1192 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1193 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:
44009
diff
changeset
|
1194 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1195 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1196 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1197 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1198 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:
44009
diff
changeset
|
1199 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1200 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1201 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1202 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:
44009
diff
changeset
|
1203 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1204 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1205 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1206 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:
44009
diff
changeset
|
1207 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1208 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1209 } |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1210 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1211 #[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1212 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:
44009
diff
changeset
|
1213 let files = vec![ |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1214 HgPathBuf::from_bytes(b"rootfile.txt"), |
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1215 HgPathBuf::from_bytes(b"a/file1.txt"), |
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1216 HgPathBuf::from_bytes(b"a/b/file2.txt"), |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1217 // No file in a/b/c |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1218 HgPathBuf::from_bytes(b"a/b/c/d/file4.txt"), |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1219 ]; |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1220 let matcher = FileMatcher::new(files).unwrap(); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1221 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1222 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1223 set.insert(HgPathBuf::from_bytes(b"a")); |
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1224 set.insert(HgPathBuf::from_bytes(b"rootfile.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1225 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1226 matcher.visit_children_set(HgPath::new(b"")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1227 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1228 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1229 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1230 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1231 set.insert(HgPathBuf::from_bytes(b"b")); |
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1232 set.insert(HgPathBuf::from_bytes(b"file1.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1233 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1234 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:
44009
diff
changeset
|
1235 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1236 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1237 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1238 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1239 set.insert(HgPathBuf::from_bytes(b"c")); |
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1240 set.insert(HgPathBuf::from_bytes(b"file2.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1241 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1242 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:
44009
diff
changeset
|
1243 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1244 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1245 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1246 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1247 set.insert(HgPathBuf::from_bytes(b"d")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1248 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1249 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:
44009
diff
changeset
|
1250 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1251 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1252 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1253 set.insert(HgPathBuf::from_bytes(b"file4.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1254 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1255 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:
44009
diff
changeset
|
1256 VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1257 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1258 |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1259 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1260 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:
44009
diff
changeset
|
1261 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1262 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1263 assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1264 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:
44009
diff
changeset
|
1265 VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1266 ); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1267 } |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1268 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1269 #[test] |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1270 fn test_patternmatcher() { |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1271 // VisitdirPrefix |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1272 let m = PatternMatcher::new(vec![IgnorePattern::new( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1273 PatternSyntax::Path, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1274 b"dir/subdir", |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1275 Path::new(""), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1276 )]) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1277 .unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1278 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1279 m.visit_children_set(HgPath::new(b"")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1280 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1281 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1282 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1283 m.visit_children_set(HgPath::new(b"dir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1284 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1285 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1286 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1287 m.visit_children_set(HgPath::new(b"dir/subdir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1288 VisitChildrenSet::Recursive |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1289 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1290 // OPT: This should probably be Recursive if its parent is? |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1291 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1292 m.visit_children_set(HgPath::new(b"dir/subdir/x")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1293 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1294 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1295 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1296 m.visit_children_set(HgPath::new(b"folder")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1297 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1298 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1299 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1300 // VisitchildrensetPrefix |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1301 let m = PatternMatcher::new(vec![IgnorePattern::new( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1302 PatternSyntax::Path, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1303 b"dir/subdir", |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1304 Path::new(""), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1305 )]) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1306 .unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1307 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1308 m.visit_children_set(HgPath::new(b"")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1309 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1310 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1311 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1312 m.visit_children_set(HgPath::new(b"dir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1313 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1314 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1315 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1316 m.visit_children_set(HgPath::new(b"dir/subdir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1317 VisitChildrenSet::Recursive |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1318 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1319 // OPT: This should probably be Recursive if its parent is? |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1320 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1321 m.visit_children_set(HgPath::new(b"dir/subdir/x")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1322 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1323 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1324 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1325 m.visit_children_set(HgPath::new(b"folder")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1326 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1327 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1328 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1329 // VisitdirRootfilesin |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1330 let m = PatternMatcher::new(vec![IgnorePattern::new( |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
1331 PatternSyntax::RootFilesIn, |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1332 b"dir/subdir", |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1333 Path::new(""), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1334 )]) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1335 .unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1336 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1337 m.visit_children_set(HgPath::new(b"dir/subdir/x")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1338 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1339 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1340 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1341 m.visit_children_set(HgPath::new(b"folder")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1342 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1343 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1344 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1345 m.visit_children_set(HgPath::new(b"")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1346 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1347 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1348 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1349 m.visit_children_set(HgPath::new(b"dir")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1350 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1351 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1352 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1353 m.visit_children_set(HgPath::new(b"dir/subdir")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1354 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1355 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1356 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1357 // VisitchildrensetRootfilesin |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1358 let m = PatternMatcher::new(vec![IgnorePattern::new( |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
1359 PatternSyntax::RootFilesIn, |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1360 b"dir/subdir", |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1361 Path::new(""), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1362 )]) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1363 .unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1364 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1365 m.visit_children_set(HgPath::new(b"dir/subdir/x")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1366 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1367 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1368 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1369 m.visit_children_set(HgPath::new(b"folder")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1370 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1371 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1372 // FIXME: These should probably be {'dir'}, {'subdir'} and This, |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1373 // respectively |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1374 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1375 m.visit_children_set(HgPath::new(b"")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1376 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1377 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1378 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1379 m.visit_children_set(HgPath::new(b"dir")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1380 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1381 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1382 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1383 m.visit_children_set(HgPath::new(b"dir/subdir")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1384 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1385 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1386 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1387 // VisitdirGlob |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1388 let m = PatternMatcher::new(vec![IgnorePattern::new( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1389 PatternSyntax::Glob, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1390 b"dir/z*", |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1391 Path::new(""), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1392 )]) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1393 .unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1394 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1395 m.visit_children_set(HgPath::new(b"")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1396 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1397 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1398 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1399 m.visit_children_set(HgPath::new(b"dir")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1400 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1401 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1402 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1403 m.visit_children_set(HgPath::new(b"folder")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1404 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1405 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1406 // OPT: these should probably be False. |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1407 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1408 m.visit_children_set(HgPath::new(b"dir/subdir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1409 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1410 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1411 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1412 m.visit_children_set(HgPath::new(b"dir/subdir/x")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1413 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1414 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1415 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1416 // VisitchildrensetGlob |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1417 let m = PatternMatcher::new(vec![IgnorePattern::new( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1418 PatternSyntax::Glob, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1419 b"dir/z*", |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1420 Path::new(""), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1421 )]) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1422 .unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1423 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1424 m.visit_children_set(HgPath::new(b"")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1425 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1426 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1427 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1428 m.visit_children_set(HgPath::new(b"folder")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1429 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1430 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1431 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1432 m.visit_children_set(HgPath::new(b"dir")), |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
1433 VisitChildrenSet::This |
50889
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1434 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1435 // OPT: these should probably be Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1436 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1437 m.visit_children_set(HgPath::new(b"dir/subdir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1438 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1439 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1440 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1441 m.visit_children_set(HgPath::new(b"dir/subdir/x")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1442 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1443 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1444 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1445 // VisitdirFilepath |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1446 let m = PatternMatcher::new(vec![IgnorePattern::new( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1447 PatternSyntax::FilePath, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1448 b"dir/z", |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1449 Path::new(""), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1450 )]) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1451 .unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1452 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1453 m.visit_children_set(HgPath::new(b"")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1454 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1455 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1456 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1457 m.visit_children_set(HgPath::new(b"dir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1458 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1459 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1460 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1461 m.visit_children_set(HgPath::new(b"folder")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1462 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1463 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1464 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1465 m.visit_children_set(HgPath::new(b"dir/subdir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1466 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1467 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1468 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1469 m.visit_children_set(HgPath::new(b"dir/subdir/x")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1470 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1471 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1472 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1473 // VisitchildrensetFilepath |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1474 let m = PatternMatcher::new(vec![IgnorePattern::new( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1475 PatternSyntax::FilePath, |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1476 b"dir/z", |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1477 Path::new(""), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1478 )]) |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1479 .unwrap(); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1480 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1481 m.visit_children_set(HgPath::new(b"")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1482 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1483 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1484 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1485 m.visit_children_set(HgPath::new(b"folder")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1486 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1487 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1488 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1489 m.visit_children_set(HgPath::new(b"dir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1490 VisitChildrenSet::This |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1491 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1492 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1493 m.visit_children_set(HgPath::new(b"dir/subdir")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1494 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1495 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1496 assert_eq!( |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1497 m.visit_children_set(HgPath::new(b"dir/subdir/x")), |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1498 VisitChildrenSet::Empty |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1499 ); |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1500 } |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1501 |
f874342fa568
rust-matchers: add PatternMatcher
Spencer Baugh <sbaugh@janestreet.com>
parents:
50885
diff
changeset
|
1502 #[test] |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1503 fn test_includematcher() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1504 // VisitchildrensetPrefix |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1505 let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1506 PatternSyntax::RelPath, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1507 b"dir/subdir", |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1508 Path::new(""), |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1509 )]) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1510 .unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1511 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1512 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1513 set.insert(HgPathBuf::from_bytes(b"dir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1514 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1515 matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1516 VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1517 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1518 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1519 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1520 set.insert(HgPathBuf::from_bytes(b"subdir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1521 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1522 matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1523 VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1524 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1525 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1526 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1527 VisitChildrenSet::Recursive |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1528 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1529 // OPT: This should probably be 'all' if its parent is? |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1530 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1531 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1532 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1533 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1534 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1535 matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1536 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1537 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1538 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1539 // VisitchildrensetRootfilesin |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1540 let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
1541 PatternSyntax::RootFilesIn, |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1542 b"dir/subdir", |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1543 Path::new(""), |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1544 )]) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1545 .unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1546 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1547 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1548 set.insert(HgPathBuf::from_bytes(b"dir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1549 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1550 matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1551 VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1552 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1553 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1554 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1555 set.insert(HgPathBuf::from_bytes(b"subdir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1556 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1557 matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1558 VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1559 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1560 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1561 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1562 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1563 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1564 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1565 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1566 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1567 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1568 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1569 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1570 matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1571 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1572 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1573 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1574 // VisitchildrensetGlob |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1575 let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1576 PatternSyntax::Glob, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1577 b"dir/z*", |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1578 Path::new(""), |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1579 )]) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1580 .unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1581 |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1582 let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1583 set.insert(HgPathBuf::from_bytes(b"dir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1584 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1585 matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1586 VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1587 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1588 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1589 matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1590 VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1591 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1592 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1593 matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1594 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1595 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1596 // OPT: these should probably be set(). |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1597 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1598 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1599 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1600 ); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1601 assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1602 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1603 VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1604 ); |
49408
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1605 |
50695
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1606 // VisitchildrensetFilePath |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1607 let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1608 PatternSyntax::FilePath, |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1609 b"dir/z", |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1610 Path::new(""), |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1611 )]) |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1612 .unwrap(); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1613 |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1614 let mut set = HashSet::new(); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1615 set.insert(HgPathBuf::from_bytes(b"dir")); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1616 assert_eq!( |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1617 matcher.visit_children_set(HgPath::new(b"")), |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1618 VisitChildrenSet::Set(set) |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1619 ); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1620 assert_eq!( |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1621 matcher.visit_children_set(HgPath::new(b"folder")), |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1622 VisitChildrenSet::Empty |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1623 ); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1624 let mut set = HashSet::new(); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1625 set.insert(HgPathBuf::from_bytes(b"z")); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1626 assert_eq!( |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1627 matcher.visit_children_set(HgPath::new(b"dir")), |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1628 VisitChildrenSet::Set(set) |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1629 ); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1630 // OPT: these should probably be set(). |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1631 assert_eq!( |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1632 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1633 VisitChildrenSet::Empty |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1634 ); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1635 assert_eq!( |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1636 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1637 VisitChildrenSet::Empty |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1638 ); |
1c31b343e514
match: add `filepath:` pattern to match an exact filepath relative to the root
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50003
diff
changeset
|
1639 |
49408
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1640 // Test multiple patterns |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1641 let matcher = IncludeMatcher::new(vec![ |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1642 IgnorePattern::new(PatternSyntax::RelPath, b"foo", Path::new("")), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1643 IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1644 ]) |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1645 .unwrap(); |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1646 |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1647 assert_eq!( |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1648 matcher.visit_children_set(HgPath::new(b"")), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1649 VisitChildrenSet::This |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1650 ); |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1651 |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1652 // Test multiple patterns |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1653 let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1654 PatternSyntax::Glob, |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1655 b"**/*.exe", |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1656 Path::new(""), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1657 )]) |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1658 .unwrap(); |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1659 |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1660 assert_eq!( |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1661 matcher.visit_children_set(HgPath::new(b"")), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1662 VisitChildrenSet::This |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1663 ); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1664 } |
49351
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1665 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1666 #[test] |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1667 fn test_unionmatcher() { |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1668 // Path + Rootfiles |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1669 let m1 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1670 PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1671 b"dir/subdir", |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1672 Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1673 )]) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1674 .unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1675 let m2 = IncludeMatcher::new(vec![IgnorePattern::new( |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
1676 PatternSyntax::RootFilesIn, |
49351
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1677 b"dir", |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1678 Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1679 )]) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1680 .unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1681 let matcher = UnionMatcher::new(vec![Box::new(m1), Box::new(m2)]); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1682 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1683 let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1684 set.insert(HgPathBuf::from_bytes(b"dir")); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1685 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1686 matcher.visit_children_set(HgPath::new(b"")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1687 VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1688 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1689 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1690 matcher.visit_children_set(HgPath::new(b"dir")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1691 VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1692 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1693 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1694 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1695 VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1696 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1697 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1698 matcher.visit_children_set(HgPath::new(b"dir/foo")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1699 VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1700 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1701 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1702 matcher.visit_children_set(HgPath::new(b"folder")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1703 VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1704 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1705 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1706 matcher.visit_children_set(HgPath::new(b"folder")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1707 VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1708 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1709 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1710 // OPT: These next two could be 'all' instead of 'this'. |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1711 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1712 matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1713 VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1714 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1715 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1716 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1717 VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1718 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1719 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1720 // Path + unrelated Path |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1721 let m1 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1722 PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1723 b"dir/subdir", |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1724 Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1725 )]) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1726 .unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1727 let m2 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1728 PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1729 b"folder", |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1730 Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1731 )]) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1732 .unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1733 let matcher = UnionMatcher::new(vec![Box::new(m1), Box::new(m2)]); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1734 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1735 let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1736 set.insert(HgPathBuf::from_bytes(b"folder")); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1737 set.insert(HgPathBuf::from_bytes(b"dir")); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1738 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1739 matcher.visit_children_set(HgPath::new(b"")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1740 VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1741 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1742 let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1743 set.insert(HgPathBuf::from_bytes(b"subdir")); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1744 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1745 matcher.visit_children_set(HgPath::new(b"dir")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1746 VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1747 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1748 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1749 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1750 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1751 VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1752 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1753 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1754 matcher.visit_children_set(HgPath::new(b"dir/foo")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1755 VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1756 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1757 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1758 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1759 matcher.visit_children_set(HgPath::new(b"folder")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1760 VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1761 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1762 // OPT: These next two could be 'all' instead of 'this'. |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1763 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1764 matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1765 VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1766 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1767 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1768 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1769 VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1770 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1771 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1772 // Path + subpath |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1773 let m1 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1774 PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1775 b"dir/subdir/x", |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1776 Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1777 )]) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1778 .unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1779 let m2 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1780 PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1781 b"dir/subdir", |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1782 Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1783 )]) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1784 .unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1785 let matcher = UnionMatcher::new(vec![Box::new(m1), Box::new(m2)]); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1786 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1787 let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1788 set.insert(HgPathBuf::from_bytes(b"dir")); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1789 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1790 matcher.visit_children_set(HgPath::new(b"")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1791 VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1792 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1793 let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1794 set.insert(HgPathBuf::from_bytes(b"subdir")); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1795 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1796 matcher.visit_children_set(HgPath::new(b"dir")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1797 VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1798 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1799 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1800 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1801 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1802 VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1803 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1804 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1805 matcher.visit_children_set(HgPath::new(b"dir/foo")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1806 VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1807 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1808 |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1809 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1810 matcher.visit_children_set(HgPath::new(b"folder")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1811 VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1812 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1813 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1814 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1815 VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1816 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1817 // OPT: this should probably be 'all' not 'this'. |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1818 assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1819 matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1820 VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1821 ); |
b508cffd3c04
rust: add UnionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1822 } |
49353
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1823 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1824 #[test] |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1825 fn test_intersectionmatcher() { |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1826 // Include path + Include rootfiles |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1827 let m1 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1828 IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1829 PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1830 b"dir/subdir", |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1831 Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1832 )]) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1833 .unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1834 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1835 let m2 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1836 IncludeMatcher::new(vec![IgnorePattern::new( |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
1837 PatternSyntax::RootFilesIn, |
49353
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1838 b"dir", |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1839 Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1840 )]) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1841 .unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1842 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1843 let matcher = IntersectionMatcher::new(m1, m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1844 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1845 let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1846 set.insert(HgPathBuf::from_bytes(b"dir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1847 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1848 matcher.visit_children_set(HgPath::new(b"")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1849 VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1850 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1851 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1852 matcher.visit_children_set(HgPath::new(b"dir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1853 VisitChildrenSet::This |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1854 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1855 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1856 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1857 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1858 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1859 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1860 matcher.visit_children_set(HgPath::new(b"dir/foo")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1861 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1862 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1863 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1864 matcher.visit_children_set(HgPath::new(b"folder")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1865 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1866 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1867 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1868 matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1869 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1870 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1871 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1872 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1873 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1874 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1875 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1876 // Non intersecting paths |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1877 let m1 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1878 IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1879 PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1880 b"dir/subdir", |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1881 Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1882 )]) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1883 .unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1884 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1885 let m2 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1886 IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1887 PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1888 b"folder", |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1889 Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1890 )]) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1891 .unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1892 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1893 let matcher = IntersectionMatcher::new(m1, m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1894 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1895 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1896 matcher.visit_children_set(HgPath::new(b"")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1897 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1898 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1899 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1900 matcher.visit_children_set(HgPath::new(b"dir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1901 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1902 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1903 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1904 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1905 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1906 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1907 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1908 matcher.visit_children_set(HgPath::new(b"dir/foo")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1909 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1910 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1911 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1912 matcher.visit_children_set(HgPath::new(b"folder")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1913 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1914 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1915 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1916 matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1917 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1918 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1919 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1920 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1921 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1922 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1923 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1924 // Nested paths |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1925 let m1 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1926 IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1927 PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1928 b"dir/subdir/x", |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1929 Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1930 )]) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1931 .unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1932 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1933 let m2 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1934 IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1935 PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1936 b"dir/subdir", |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1937 Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1938 )]) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1939 .unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1940 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1941 let matcher = IntersectionMatcher::new(m1, m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1942 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1943 let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1944 set.insert(HgPathBuf::from_bytes(b"dir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1945 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1946 matcher.visit_children_set(HgPath::new(b"")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1947 VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1948 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1949 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1950 let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1951 set.insert(HgPathBuf::from_bytes(b"subdir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1952 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1953 matcher.visit_children_set(HgPath::new(b"dir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1954 VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1955 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1956 let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1957 set.insert(HgPathBuf::from_bytes(b"x")); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1958 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1959 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1960 VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1961 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1962 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1963 matcher.visit_children_set(HgPath::new(b"dir/foo")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1964 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1965 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1966 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1967 matcher.visit_children_set(HgPath::new(b"folder")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1968 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1969 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1970 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1971 matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1972 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1973 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1974 // OPT: this should probably be 'all' not 'this'. |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1975 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1976 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1977 VisitChildrenSet::This |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1978 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1979 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1980 // Diverging paths |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1981 let m1 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1982 IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1983 PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1984 b"dir/subdir/x", |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1985 Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1986 )]) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1987 .unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1988 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1989 let m2 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1990 IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1991 PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1992 b"dir/subdir/z", |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1993 Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1994 )]) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1995 .unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1996 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1997 let matcher = IntersectionMatcher::new(m1, m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1998 |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1999 // OPT: these next two could probably be Empty as well. |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2000 let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2001 set.insert(HgPathBuf::from_bytes(b"dir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2002 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2003 matcher.visit_children_set(HgPath::new(b"")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2004 VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2005 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2006 // OPT: these next two could probably be Empty as well. |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2007 let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2008 set.insert(HgPathBuf::from_bytes(b"subdir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2009 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2010 matcher.visit_children_set(HgPath::new(b"dir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2011 VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2012 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2013 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2014 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2015 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2016 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2017 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2018 matcher.visit_children_set(HgPath::new(b"dir/foo")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2019 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2020 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2021 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2022 matcher.visit_children_set(HgPath::new(b"folder")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2023 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2024 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2025 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2026 matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2027 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2028 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2029 assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2030 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2031 VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2032 ); |
5e53ecbc308f
rust: add IntersectionMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49351
diff
changeset
|
2033 } |
49492
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2034 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2035 #[test] |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2036 fn test_differencematcher() { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2037 // Two alwaysmatchers should function like a nevermatcher |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2038 let m1 = AlwaysMatcher; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2039 let m2 = AlwaysMatcher; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2040 let matcher = DifferenceMatcher::new(Box::new(m1), Box::new(m2)); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2041 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2042 for case in &[ |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2043 &b""[..], |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2044 b"dir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2045 b"dir/subdir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2046 b"dir/subdir/z", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2047 b"dir/foo", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2048 b"dir/subdir/x", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2049 b"folder", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2050 ] { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2051 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2052 matcher.visit_children_set(HgPath::new(case)), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2053 VisitChildrenSet::Empty |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2054 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2055 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2056 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2057 // One always and one never should behave the same as an always |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2058 let m1 = AlwaysMatcher; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2059 let m2 = NeverMatcher; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2060 let matcher = DifferenceMatcher::new(Box::new(m1), Box::new(m2)); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2061 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2062 for case in &[ |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2063 &b""[..], |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2064 b"dir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2065 b"dir/subdir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2066 b"dir/subdir/z", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2067 b"dir/foo", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2068 b"dir/subdir/x", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2069 b"folder", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2070 ] { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2071 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2072 matcher.visit_children_set(HgPath::new(case)), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2073 VisitChildrenSet::Recursive |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2074 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2075 } |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2076 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2077 // Two include matchers |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2078 let m1 = Box::new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2079 IncludeMatcher::new(vec![IgnorePattern::new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2080 PatternSyntax::RelPath, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2081 b"dir/subdir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2082 Path::new("/repo"), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2083 )]) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2084 .unwrap(), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2085 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2086 let m2 = Box::new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2087 IncludeMatcher::new(vec![IgnorePattern::new( |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
2088 PatternSyntax::RootFilesIn, |
49492
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2089 b"dir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2090 Path::new("/repo"), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2091 )]) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2092 .unwrap(), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2093 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2094 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2095 let matcher = DifferenceMatcher::new(m1, m2); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2096 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2097 let mut set = HashSet::new(); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2098 set.insert(HgPathBuf::from_bytes(b"dir")); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2099 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2100 matcher.visit_children_set(HgPath::new(b"")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2101 VisitChildrenSet::Set(set) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2102 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2103 |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2104 let mut set = HashSet::new(); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2105 set.insert(HgPathBuf::from_bytes(b"subdir")); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2106 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2107 matcher.visit_children_set(HgPath::new(b"dir")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2108 VisitChildrenSet::Set(set) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2109 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2110 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2111 matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2112 VisitChildrenSet::Recursive |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2113 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2114 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2115 matcher.visit_children_set(HgPath::new(b"dir/foo")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2116 VisitChildrenSet::Empty |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2117 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2118 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2119 matcher.visit_children_set(HgPath::new(b"folder")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2120 VisitChildrenSet::Empty |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2121 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2122 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2123 matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2124 VisitChildrenSet::This |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2125 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2126 assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2127 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2128 VisitChildrenSet::This |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2129 ); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49408
diff
changeset
|
2130 } |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2131 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2132 mod invariants { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2133 pub mod visit_children_set { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2134 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2135 use crate::{ |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2136 matchers::{tests::Tree, Matcher, VisitChildrenSet}, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2137 utils::hg_path::HgPath, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2138 }; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2139 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2140 #[allow(dead_code)] |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2141 #[derive(Debug)] |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2142 struct Error<'a, M> { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2143 matcher: &'a M, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2144 path: &'a HgPath, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2145 matching: &'a Tree, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2146 visit_children_set: &'a VisitChildrenSet, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2147 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2148 |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2149 fn holds( |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2150 matching: &Tree, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2151 not_matching: &Tree, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2152 vcs: &VisitChildrenSet, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2153 ) -> bool { |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2154 match vcs { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2155 VisitChildrenSet::Empty => matching.is_empty(), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2156 VisitChildrenSet::This => { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2157 // `This` does not come with any obligations. |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2158 true |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2159 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2160 VisitChildrenSet::Recursive => { |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2161 // `Recursive` requires that *everything* in the |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2162 // subtree matches. This |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2163 // requirement is relied on for example in |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2164 // DifferenceMatcher implementation. |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2165 not_matching.is_empty() |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2166 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2167 VisitChildrenSet::Set(allowed_children) => { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2168 // `allowed_children` does not distinguish between |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2169 // files and directories: if it's not included, it |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2170 // must not be matched. |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2171 for k in matching.dirs.keys() { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2172 if !(allowed_children.contains(k)) { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2173 return false; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2174 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2175 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2176 for k in matching.files.iter() { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2177 if !(allowed_children.contains(k)) { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2178 return false; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2179 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2180 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2181 true |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2182 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2183 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2184 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2185 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2186 pub fn check<M: Matcher + std::fmt::Debug>( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2187 matcher: &M, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2188 path: &HgPath, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2189 matching: &Tree, |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2190 not_matching: &Tree, |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2191 visit_children_set: &VisitChildrenSet, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2192 ) { |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2193 if !holds(matching, not_matching, visit_children_set) { |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2194 panic!( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2195 "{:#?}", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2196 Error { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2197 matcher, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2198 path, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2199 visit_children_set, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2200 matching |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2201 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2202 ) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2203 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2204 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2205 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2206 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2207 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2208 #[derive(Debug, Clone)] |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2209 pub struct Tree { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2210 files: BTreeSet<HgPathBuf>, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2211 dirs: BTreeMap<HgPathBuf, Tree>, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2212 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2213 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2214 impl Tree { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2215 fn len(&self) -> usize { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2216 let mut n = 0; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2217 n += self.files.len(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2218 for d in self.dirs.values() { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2219 n += d.len(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2220 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2221 n |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2222 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2223 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2224 fn is_empty(&self) -> bool { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2225 self.files.is_empty() && self.dirs.is_empty() |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2226 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2227 |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2228 fn make( |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2229 files: BTreeSet<HgPathBuf>, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2230 dirs: BTreeMap<HgPathBuf, Tree>, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2231 ) -> Self { |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2232 Self { |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2233 files, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2234 dirs: dirs |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2235 .into_iter() |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2236 .filter(|(_k, v)| (!(v.is_empty()))) |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2237 .collect(), |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2238 } |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2239 } |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2240 |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2241 fn filter_and_check<M: Matcher + Debug>( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2242 &self, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2243 m: &M, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2244 path: &HgPath, |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2245 ) -> (Self, Self) { |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2246 let (files1, files2): (BTreeSet<HgPathBuf>, BTreeSet<HgPathBuf>) = |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2247 self.files |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2248 .iter() |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2249 .map(|v| v.to_owned()) |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2250 .partition(|v| m.matches(&path.join(v))); |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2251 let (dirs1, dirs2): ( |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2252 BTreeMap<HgPathBuf, Tree>, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2253 BTreeMap<HgPathBuf, Tree>, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2254 ) = self |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2255 .dirs |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2256 .iter() |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2257 .map(|(k, v)| { |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2258 let path = path.join(k); |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2259 let (t1, t2) = v.filter_and_check(m, &path); |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2260 ((k.clone(), t1), (k.clone(), t2)) |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2261 }) |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2262 .unzip(); |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2263 let matching = Self::make(files1, dirs1); |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2264 let not_matching = Self::make(files2, dirs2); |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2265 let vcs = m.visit_children_set(path); |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2266 invariants::visit_children_set::check( |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2267 m, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2268 path, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2269 &matching, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2270 ¬_matching, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2271 &vcs, |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2272 ); |
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2273 (matching, not_matching) |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2274 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2275 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2276 fn check_matcher<M: Matcher + Debug>( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2277 &self, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2278 m: &M, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2279 expect_count: usize, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2280 ) { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2281 let res = self.filter_and_check(m, &HgPathBuf::new()); |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2282 if expect_count != res.0.len() { |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2283 eprintln!( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2284 "warning: expected {} matches, got {} for {:#?}", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2285 expect_count, |
51482
74230abb2504
match: strengthen visit_children_set invariant, Recursive means "all files"
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51481
diff
changeset
|
2286 res.0.len(), |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2287 m |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2288 ); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2289 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2290 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2291 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2292 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2293 fn mkdir(children: &[(&[u8], &Tree)]) -> Tree { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2294 let p = HgPathBuf::from_bytes; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2295 let names = [ |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2296 p(b"a"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2297 p(b"b.txt"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2298 p(b"file.txt"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2299 p(b"c.c"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2300 p(b"c.h"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2301 p(b"dir1"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2302 p(b"dir2"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2303 p(b"subdir"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2304 ]; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2305 let files: BTreeSet<HgPathBuf> = BTreeSet::from(names); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2306 let dirs = children |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2307 .iter() |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2308 .map(|(name, t)| (p(name), (*t).clone())) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2309 .collect(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2310 Tree { files, dirs } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2311 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2312 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2313 fn make_example_tree() -> Tree { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2314 let leaf = mkdir(&[]); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2315 let abc = mkdir(&[(b"d", &leaf)]); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2316 let ab = mkdir(&[(b"c", &abc)]); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2317 let a = mkdir(&[(b"b", &ab)]); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2318 let dir = mkdir(&[(b"subdir", &leaf), (b"subdir.c", &leaf)]); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2319 mkdir(&[(b"dir", &dir), (b"dir1", &dir), (b"dir2", &dir), (b"a", &a)]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2320 } |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2321 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2322 #[test] |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2323 fn test_pattern_matcher_visit_children_set() { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2324 let tree = make_example_tree(); |
51477
529a655874fb
matchers: fix the bug in rust PatternMatcher that made it cut off early
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51475
diff
changeset
|
2325 let pattern_dir1_glob_c = |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2326 PatternMatcher::new(vec![IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2327 PatternSyntax::Glob, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2328 b"dir1/*.c", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2329 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2330 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2331 .unwrap(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2332 let pattern_dir1 = || { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2333 PatternMatcher::new(vec![IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2334 PatternSyntax::Path, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2335 b"dir1", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2336 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2337 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2338 .unwrap() |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2339 }; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2340 let pattern_dir1_a = PatternMatcher::new(vec![IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2341 PatternSyntax::Glob, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2342 b"dir1/a", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2343 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2344 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2345 .unwrap(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2346 let pattern_relglob_c = || { |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2347 PatternMatcher::new(vec![IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2348 PatternSyntax::RelGlob, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2349 b"*.c", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2350 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2351 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2352 .unwrap() |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2353 }; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2354 let files = vec![HgPathBuf::from_bytes(b"dir/subdir/b.txt")]; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2355 let file_dir_subdir_b = FileMatcher::new(files).unwrap(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2356 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2357 let files = vec![ |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2358 HgPathBuf::from_bytes(b"file.txt"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2359 HgPathBuf::from_bytes(b"a/file.txt"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2360 HgPathBuf::from_bytes(b"a/b/file.txt"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2361 // No file in a/b/c |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2362 HgPathBuf::from_bytes(b"a/b/c/d/file.txt"), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2363 ]; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2364 let file_abcdfile = FileMatcher::new(files).unwrap(); |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
2365 let rootfilesin_dir = PatternMatcher::new(vec![IgnorePattern::new( |
51479
2a89d2f6336f
match: rename RootFiles to RootFilesIn for more consistency
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51478
diff
changeset
|
2366 PatternSyntax::RootFilesIn, |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2367 b"dir", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2368 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2369 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2370 .unwrap(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2371 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2372 let pattern_filepath_dir_subdir = |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2373 PatternMatcher::new(vec![IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2374 PatternSyntax::FilePath, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2375 b"dir/subdir", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2376 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2377 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2378 .unwrap(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2379 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2380 let include_dir_subdir = |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2381 IncludeMatcher::new(vec![IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2382 PatternSyntax::RelPath, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2383 b"dir/subdir", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2384 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2385 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2386 .unwrap(); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2387 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2388 let more_includematchers = [ |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2389 IncludeMatcher::new(vec![IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2390 PatternSyntax::Glob, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2391 b"dir/s*", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2392 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2393 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2394 .unwrap(), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2395 // Test multiple patterns |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2396 IncludeMatcher::new(vec![ |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2397 IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2398 PatternSyntax::RelPath, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2399 b"dir", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2400 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2401 ), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2402 IgnorePattern::new(PatternSyntax::Glob, b"s*", Path::new("")), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2403 ]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2404 .unwrap(), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2405 // Test multiple patterns |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2406 IncludeMatcher::new(vec![IgnorePattern::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2407 PatternSyntax::Glob, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2408 b"**/*.c", |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2409 Path::new(""), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2410 )]) |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2411 .unwrap(), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2412 ]; |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2413 |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2414 tree.check_matcher(&pattern_dir1(), 25); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2415 tree.check_matcher(&pattern_dir1_a, 1); |
51477
529a655874fb
matchers: fix the bug in rust PatternMatcher that made it cut off early
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51475
diff
changeset
|
2416 tree.check_matcher(&pattern_dir1_glob_c, 2); |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2417 tree.check_matcher(&pattern_relglob_c(), 14); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2418 tree.check_matcher(&AlwaysMatcher, 112); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2419 tree.check_matcher(&NeverMatcher, 0); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2420 tree.check_matcher( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2421 &IntersectionMatcher::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2422 Box::new(pattern_relglob_c()), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2423 Box::new(pattern_dir1()), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2424 ), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2425 3, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2426 ); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2427 tree.check_matcher( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2428 &UnionMatcher::new(vec![ |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2429 Box::new(pattern_relglob_c()), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2430 Box::new(pattern_dir1()), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2431 ]), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2432 36, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2433 ); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2434 tree.check_matcher( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2435 &DifferenceMatcher::new( |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2436 Box::new(pattern_relglob_c()), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2437 Box::new(pattern_dir1()), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2438 ), |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2439 11, |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2440 ); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2441 tree.check_matcher(&file_dir_subdir_b, 1); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2442 tree.check_matcher(&file_abcdfile, 4); |
51481
b39057b713b1
match: fix the rust-side bug in visit_children_set for rootfilesin matchers
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51479
diff
changeset
|
2443 tree.check_matcher(&rootfilesin_dir, 8); |
51475
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2444 tree.check_matcher(&pattern_filepath_dir_subdir, 1); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2445 tree.check_matcher(&include_dir_subdir, 9); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2446 tree.check_matcher(&more_includematchers[0], 17); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2447 tree.check_matcher(&more_includematchers[1], 25); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2448 tree.check_matcher(&more_includematchers[2], 35); |
f5c367dc6541
tests: add tests and document expectations from visit_children_set in rust
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51447
diff
changeset
|
2449 } |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44009
diff
changeset
|
2450 } |