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