author | Raphaël Gomès <rgomes@octobus.net> |
Mon, 14 Nov 2022 15:20:48 +0100 | |
changeset 49749 | c7fb9b74e753 |
parent 49564 | 04f1dba53c96 |
child 49986 | c15b415d1bff |
permissions | -rw-r--r-- |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 |
// matchers.rs |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 |
// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 |
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 |
// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 |
// This software may be used and distributed according to the terms of the |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 |
// GNU General Public License version 2 or any later version. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
|
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 |
//! Structs and types for matching files and directories. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 |
|
44529
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44387
diff
changeset
|
10 |
use crate::{ |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
11 |
dirstate::dirs_multiset::DirsChildrenMultiset, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
12 |
filepatterns::{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
13 |
build_single_regex, filter_subincludes, get_patterns_from_file, |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
14 |
PatternFileWarning, PatternResult, |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
15 |
}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
16 |
utils::{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
17 |
files::find_dirs, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
18 |
hg_path::{HgPath, HgPathBuf}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
19 |
Escaped, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
20 |
}, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
21 |
DirsMultiset, DirstateMapError, FastHashMap, IgnorePattern, PatternError, |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
22 |
PatternSyntax, |
44529
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44387
diff
changeset
|
23 |
}; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
24 |
|
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
25 |
use crate::dirstate::status::IgnoreFnType; |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
26 |
use crate::filepatterns::normalize_path_bytes; |
44604
e62052d0f377
rust-status: only involve ignore mechanism when needed
Raphaël Gomès <rgomes@octobus.net>
parents:
44601
diff
changeset
|
27 |
use std::borrow::ToOwned; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
use std::collections::HashSet; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
29 |
use std::fmt::{Display, Error, Formatter}; |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
30 |
use std::ops::Deref; |
44604
e62052d0f377
rust-status: only involve ignore mechanism when needed
Raphaël Gomès <rgomes@octobus.net>
parents:
44601
diff
changeset
|
31 |
use std::path::{Path, PathBuf}; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
|
44861
83c97c0bd319
rust-matchers: add timing tracing to regex compilation
Raphaël Gomès <rgomes@octobus.net>
parents:
44604
diff
changeset
|
33 |
use micro_timer::timed; |
83c97c0bd319
rust-matchers: add timing tracing to regex compilation
Raphaël Gomès <rgomes@octobus.net>
parents:
44604
diff
changeset
|
34 |
|
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
35 |
#[derive(Debug, PartialEq)] |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
36 |
pub enum VisitChildrenSet { |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
/// Don't visit anything |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 |
Empty, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
/// Only visit this directory |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
This, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 |
/// Visit this directory and these subdirectories |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
/// TODO Should we implement a `NonEmptyHashSet`? |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
43 |
Set(HashSet<HgPathBuf>), |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
/// Visit this directory and all subdirectories |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 |
Recursive, |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
|
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
48 |
pub trait Matcher: core::fmt::Debug { |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 |
/// Explicitly listed files |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
50 |
fn file_set(&self) -> Option<&HashSet<HgPathBuf>>; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
/// Returns whether `filename` is in `file_set` |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
52 |
fn exact_match(&self, filename: &HgPath) -> bool; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 |
/// Returns whether `filename` is matched by this matcher |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
54 |
fn matches(&self, filename: &HgPath) -> bool; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
/// 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
|
56 |
/// 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
|
57 |
/// 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
|
58 |
/// 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
|
59 |
/// patterns. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 |
/// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
/// # Example |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 |
/// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 |
/// 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
|
64 |
/// 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
|
65 |
/// 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
|
66 |
/// are not). |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 |
/// |
44009
72bced4f2936
rust-matchers: fixing cargo doc
Georges Racinet <georges.racinet@octobus.net>
parents:
43920
diff
changeset
|
68 |
/// ```text |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
69 |
/// ```ignore |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
70 |
/// '' -> {'foo', 'qux'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
/// 'baz' -> set() |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
/// 'foo' -> {'bar'} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 |
/// // 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
|
74 |
/// // 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
|
75 |
/// // 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
|
76 |
/// // `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
|
77 |
/// 'foo/bar' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
/// 'qux' -> 'this' |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
/// ``` |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 |
/// # Important |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 |
/// |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 |
/// 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
|
83 |
/// 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
|
84 |
/// 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
|
85 |
/// 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
|
86 |
/// 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
|
87 |
/// it may return `VisitChildrenSet::This`. |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 |
/// 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
|
89 |
/// 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
|
90 |
/// 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
|
91 |
/// `VisitChildrenSet::This`). |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
92 |
fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
93 |
/// 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
|
94 |
/// optimization might be possible. |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
95 |
fn matches_everything(&self) -> bool; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
/// 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
|
97 |
/// might be possible. |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
98 |
fn is_exact(&self) -> bool; |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 |
} |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 |
|
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 |
/// Matches everything. |
43852
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43850
diff
changeset
|
102 |
///``` |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43850
diff
changeset
|
103 |
/// use hg::{ matchers::{Matcher, AlwaysMatcher}, utils::hg_path::HgPath }; |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43850
diff
changeset
|
104 |
/// |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43850
diff
changeset
|
105 |
/// let matcher = AlwaysMatcher; |
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43850
diff
changeset
|
106 |
/// |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
107 |
/// assert_eq!(matcher.matches(HgPath::new(b"whatever")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
108 |
/// assert_eq!(matcher.matches(HgPath::new(b"b.txt")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
109 |
/// assert_eq!(matcher.matches(HgPath::new(b"main.c")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
110 |
/// assert_eq!(matcher.matches(HgPath::new(br"re:.*\.c$")), true); |
43852
542c8b277261
rust-matchers: add doctests for `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
43850
diff
changeset
|
111 |
/// ``` |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 |
#[derive(Debug)] |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 |
pub struct AlwaysMatcher; |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 |
|
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 |
impl Matcher for AlwaysMatcher { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
116 |
fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
43850
1bb4e9b02984
rust-matchers: improve `Matcher` trait ergonomics
Raphaël Gomès <rgomes@octobus.net>
parents:
43655
diff
changeset
|
117 |
None |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 |
} |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
119 |
fn exact_match(&self, _filename: &HgPath) -> bool { |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
120 |
false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
121 |
} |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
122 |
fn matches(&self, _filename: &HgPath) -> bool { |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
123 |
true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
124 |
} |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
125 |
fn visit_children_set(&self, _directory: &HgPath) -> VisitChildrenSet { |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 |
VisitChildrenSet::Recursive |
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
} |
43655
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
128 |
fn matches_everything(&self) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
129 |
true |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
130 |
} |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
131 |
fn is_exact(&self) -> bool { |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
132 |
false |
27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43490
diff
changeset
|
133 |
} |
43490
a77d4fe347a4
rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 |
} |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
135 |
|
49355
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
136 |
/// Matches nothing. |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
137 |
#[derive(Debug)] |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
138 |
pub struct NeverMatcher; |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
139 |
|
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
140 |
impl Matcher for NeverMatcher { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
141 |
fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
142 |
None |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
143 |
} |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
144 |
fn exact_match(&self, _filename: &HgPath) -> bool { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
145 |
false |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
146 |
} |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
147 |
fn matches(&self, _filename: &HgPath) -> bool { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
148 |
false |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
149 |
} |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
150 |
fn visit_children_set(&self, _directory: &HgPath) -> VisitChildrenSet { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
151 |
VisitChildrenSet::Empty |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
152 |
} |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
153 |
fn matches_everything(&self) -> bool { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
154 |
false |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
155 |
} |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
156 |
fn is_exact(&self) -> bool { |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
157 |
true |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
158 |
} |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
159 |
} |
97dcd6906e6f
rust-dirstate: add support for nevermatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49353
diff
changeset
|
160 |
|
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
161 |
/// Matches the input files exactly. They are interpreted as paths, not |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
162 |
/// patterns. |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
163 |
/// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
164 |
///``` |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
165 |
/// use hg::{ matchers::{Matcher, FileMatcher}, utils::hg_path::{HgPath, HgPathBuf} }; |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
166 |
/// |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
167 |
/// let files = vec![HgPathBuf::from_bytes(b"a.txt"), HgPathBuf::from_bytes(br"re:.*\.c$")]; |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
168 |
/// let matcher = FileMatcher::new(files).unwrap(); |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
169 |
/// |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
170 |
/// assert_eq!(matcher.matches(HgPath::new(b"a.txt")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
171 |
/// assert_eq!(matcher.matches(HgPath::new(b"b.txt")), false); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
172 |
/// assert_eq!(matcher.matches(HgPath::new(b"main.c")), false); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
173 |
/// assert_eq!(matcher.matches(HgPath::new(br"re:.*\.c$")), true); |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
174 |
/// ``` |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
175 |
#[derive(Debug)] |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
176 |
pub struct FileMatcher { |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
177 |
files: HashSet<HgPathBuf>, |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
178 |
dirs: DirsMultiset, |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
179 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
180 |
|
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
181 |
impl FileMatcher { |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
182 |
pub fn new(files: Vec<HgPathBuf>) -> Result<Self, DirstateMapError> { |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
183 |
let dirs = DirsMultiset::from_manifest(&files)?; |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
184 |
Ok(Self { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
185 |
files: HashSet::from_iter(files.into_iter()), |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
186 |
dirs, |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
187 |
}) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
188 |
} |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
189 |
fn inner_matches(&self, filename: &HgPath) -> bool { |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
190 |
self.files.contains(filename.as_ref()) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
191 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
192 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
193 |
|
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
194 |
impl Matcher for FileMatcher { |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
195 |
fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
196 |
Some(&self.files) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
197 |
} |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
198 |
fn exact_match(&self, filename: &HgPath) -> bool { |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
199 |
self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
200 |
} |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
201 |
fn matches(&self, filename: &HgPath) -> bool { |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
202 |
self.inner_matches(filename) |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
203 |
} |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
204 |
fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
205 |
if self.files.is_empty() || !self.dirs.contains(&directory) { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
206 |
return VisitChildrenSet::Empty; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
207 |
} |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
208 |
let mut candidates: HashSet<HgPathBuf> = |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
209 |
self.dirs.iter().cloned().collect(); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
210 |
|
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
211 |
candidates.extend(self.files.iter().cloned()); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
212 |
candidates.remove(HgPath::new(b"")); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
213 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
214 |
if !directory.as_ref().is_empty() { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
215 |
let directory = [directory.as_ref().as_bytes(), b"/"].concat(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
216 |
candidates = candidates |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
217 |
.iter() |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
218 |
.filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
219 |
if c.as_bytes().starts_with(&directory) { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
220 |
Some(HgPathBuf::from_bytes( |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
221 |
&c.as_bytes()[directory.len()..], |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
222 |
)) |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
223 |
} else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
224 |
None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
225 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
226 |
}) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
227 |
.collect(); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
228 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
229 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
230 |
// `self.dirs` includes all of the directories, recursively, so if |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
231 |
// we're attempting to match 'foo/bar/baz.txt', it'll have '', 'foo', |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
232 |
// 'foo/bar' in it. Thus we can safely ignore a candidate that has a |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
233 |
// '/' in it, indicating it's for a subdir-of-a-subdir; the immediate |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
234 |
// subdir will be in there without a slash. |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
235 |
VisitChildrenSet::Set( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
236 |
candidates |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
237 |
.into_iter() |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
238 |
.filter_map(|c| { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
239 |
if c.bytes().all(|b| *b != b'/') { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
240 |
Some(c) |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
241 |
} else { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
242 |
None |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
243 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
244 |
}) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
245 |
.collect(), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
246 |
) |
43920
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
247 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
248 |
fn matches_everything(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
249 |
false |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
250 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
251 |
fn is_exact(&self) -> bool { |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
252 |
true |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
253 |
} |
69c4f3cf2cdf
rust-matchers: add `FileMatcher` implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
43874
diff
changeset
|
254 |
} |
44529
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44387
diff
changeset
|
255 |
|
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
256 |
/// Matches files that are included in the ignore rules. |
44929
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
257 |
/// ``` |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
258 |
/// use hg::{ |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
259 |
/// matchers::{IncludeMatcher, Matcher}, |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
260 |
/// IgnorePattern, |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
261 |
/// PatternSyntax, |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
262 |
/// utils::hg_path::HgPath |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
263 |
/// }; |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
264 |
/// use std::path::Path; |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
265 |
/// /// |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
266 |
/// let ignore_patterns = |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
267 |
/// vec![IgnorePattern::new(PatternSyntax::RootGlob, b"this*", Path::new(""))]; |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
268 |
/// let matcher = IncludeMatcher::new(ignore_patterns).unwrap(); |
44929
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
269 |
/// /// |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
270 |
/// assert_eq!(matcher.matches(HgPath::new(b"testing")), false); |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
271 |
/// assert_eq!(matcher.matches(HgPath::new(b"this should work")), true); |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
272 |
/// assert_eq!(matcher.matches(HgPath::new(b"this also")), true); |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
273 |
/// assert_eq!(matcher.matches(HgPath::new(b"but not this")), false); |
9f96beb9bafe
rust: remove support for `re2`
Raphaël Gomès <rgomes@octobus.net>
parents:
44911
diff
changeset
|
274 |
/// ``` |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
275 |
pub struct IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
276 |
patterns: Vec<u8>, |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
277 |
match_fn: IgnoreFnType<'a>, |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
278 |
/// Whether all the patterns match a prefix (i.e. recursively) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
279 |
prefix: bool, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
280 |
roots: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
281 |
dirs: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
282 |
parents: HashSet<HgPathBuf>, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
283 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
284 |
|
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
285 |
impl core::fmt::Debug for IncludeMatcher<'_> { |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
286 |
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
287 |
f.debug_struct("IncludeMatcher") |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
288 |
.field("patterns", &String::from_utf8_lossy(&self.patterns)) |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
289 |
.field("prefix", &self.prefix) |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
290 |
.field("roots", &self.roots) |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
291 |
.field("dirs", &self.dirs) |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
292 |
.field("parents", &self.parents) |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
293 |
.finish() |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
294 |
} |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
295 |
} |
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
296 |
|
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
297 |
impl<'a> Matcher for IncludeMatcher<'a> { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
298 |
fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
299 |
None |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
300 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
301 |
|
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
302 |
fn exact_match(&self, _filename: &HgPath) -> bool { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
303 |
false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
304 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
305 |
|
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
306 |
fn matches(&self, filename: &HgPath) -> bool { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
307 |
(self.match_fn)(filename.as_ref()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
308 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
309 |
|
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
310 |
fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
311 |
let dir = directory.as_ref(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
312 |
if self.prefix && self.roots.contains(dir) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
313 |
return VisitChildrenSet::Recursive; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
314 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
315 |
if self.roots.contains(HgPath::new(b"")) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
316 |
|| self.roots.contains(dir) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
317 |
|| self.dirs.contains(dir) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
318 |
|| find_dirs(dir).any(|parent_dir| self.roots.contains(parent_dir)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
319 |
{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
320 |
return VisitChildrenSet::This; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
321 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
322 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
323 |
if self.parents.contains(directory.as_ref()) { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
324 |
let multiset = self.get_all_parents_children(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
325 |
if let Some(children) = multiset.get(dir) { |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
326 |
return VisitChildrenSet::Set( |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
327 |
children.into_iter().map(HgPathBuf::from).collect(), |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
328 |
); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
329 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
330 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
331 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
332 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
333 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
334 |
fn matches_everything(&self) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
335 |
false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
336 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
337 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
338 |
fn is_exact(&self) -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
339 |
false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
340 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
341 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
342 |
|
49351
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
343 |
/// The union of multiple matchers. Will match if any of the matchers match. |
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
344 |
#[derive(Debug)] |
49351
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
345 |
pub struct UnionMatcher { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
346 |
matchers: Vec<Box<dyn Matcher + Sync>>, |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
347 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
348 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
349 |
impl Matcher for UnionMatcher { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
350 |
fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
351 |
None |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
352 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
353 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
354 |
fn exact_match(&self, _filename: &HgPath) -> bool { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
355 |
false |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
356 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
357 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
358 |
fn matches(&self, filename: &HgPath) -> bool { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
359 |
self.matchers.iter().any(|m| m.matches(filename)) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
360 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
361 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
362 |
fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
363 |
let mut result = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
364 |
let mut this = false; |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
365 |
for matcher in self.matchers.iter() { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
366 |
let visit = matcher.visit_children_set(directory); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
367 |
match visit { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
368 |
VisitChildrenSet::Empty => continue, |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
369 |
VisitChildrenSet::This => { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
370 |
this = true; |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
371 |
// Don't break, we might have an 'all' in here. |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
372 |
continue; |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
373 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
374 |
VisitChildrenSet::Set(set) => { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
375 |
result.extend(set); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
376 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
377 |
VisitChildrenSet::Recursive => { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
378 |
return visit; |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
379 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
380 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
381 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
382 |
if this { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
383 |
return VisitChildrenSet::This; |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
384 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
385 |
if result.is_empty() { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
386 |
VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
387 |
} else { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
388 |
VisitChildrenSet::Set(result) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
389 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
390 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
391 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
392 |
fn matches_everything(&self) -> bool { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
393 |
// TODO Maybe if all are AlwaysMatcher? |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
394 |
false |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
395 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
396 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
397 |
fn is_exact(&self) -> bool { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
398 |
false |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
399 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
400 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
401 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
402 |
impl UnionMatcher { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
403 |
pub fn new(matchers: Vec<Box<dyn Matcher + Sync>>) -> Self { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
404 |
Self { matchers } |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
405 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
406 |
} |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
407 |
|
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
408 |
#[derive(Debug)] |
49353
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
409 |
pub struct IntersectionMatcher { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
410 |
m1: Box<dyn Matcher + Sync>, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
411 |
m2: Box<dyn Matcher + Sync>, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
412 |
files: Option<HashSet<HgPathBuf>>, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
413 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
414 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
415 |
impl Matcher for IntersectionMatcher { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
416 |
fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
417 |
self.files.as_ref() |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
418 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
419 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
420 |
fn exact_match(&self, filename: &HgPath) -> bool { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
421 |
self.files.as_ref().map_or(false, |f| f.contains(filename)) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
422 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
423 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
424 |
fn matches(&self, filename: &HgPath) -> bool { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
425 |
self.m1.matches(filename) && self.m2.matches(filename) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
426 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
427 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
428 |
fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
429 |
let m1_set = self.m1.visit_children_set(directory); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
430 |
if m1_set == VisitChildrenSet::Empty { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
431 |
return VisitChildrenSet::Empty; |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
432 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
433 |
let m2_set = self.m2.visit_children_set(directory); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
434 |
if m2_set == VisitChildrenSet::Empty { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
435 |
return VisitChildrenSet::Empty; |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
436 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
437 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
438 |
if m1_set == VisitChildrenSet::Recursive { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
439 |
return m2_set; |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
440 |
} else if m2_set == VisitChildrenSet::Recursive { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
441 |
return m1_set; |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
442 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
443 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
444 |
match (&m1_set, &m2_set) { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
445 |
(VisitChildrenSet::Recursive, _) => m2_set, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
446 |
(_, VisitChildrenSet::Recursive) => m1_set, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
447 |
(VisitChildrenSet::This, _) | (_, VisitChildrenSet::This) => { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
448 |
VisitChildrenSet::This |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
449 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
450 |
(VisitChildrenSet::Set(m1), VisitChildrenSet::Set(m2)) => { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
451 |
let set: HashSet<_> = m1.intersection(&m2).cloned().collect(); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
452 |
if set.is_empty() { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
453 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
454 |
} else { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
455 |
VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
456 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
457 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
458 |
_ => unreachable!(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
459 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
460 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
461 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
462 |
fn matches_everything(&self) -> bool { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
463 |
self.m1.matches_everything() && self.m2.matches_everything() |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
464 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
465 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
466 |
fn is_exact(&self) -> bool { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
467 |
self.m1.is_exact() || self.m2.is_exact() |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
468 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
469 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
470 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
471 |
impl IntersectionMatcher { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
472 |
pub fn new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
473 |
mut m1: Box<dyn Matcher + Sync>, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
474 |
mut m2: Box<dyn Matcher + Sync>, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
475 |
) -> Self { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
476 |
let files = if m1.is_exact() || m2.is_exact() { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
477 |
if !m1.is_exact() { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
478 |
std::mem::swap(&mut m1, &mut m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
479 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
480 |
m1.file_set().map(|m1_files| { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
481 |
m1_files.iter().cloned().filter(|f| m2.matches(f)).collect() |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
482 |
}) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
483 |
} else { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
484 |
None |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
485 |
}; |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
486 |
Self { m1, m2, files } |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
487 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
488 |
} |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
489 |
|
49500
e8481625c582
rust: add Debug constraint to Matcher trait
Raphaël Gomès <rgomes@octobus.net>
parents:
49492
diff
changeset
|
490 |
#[derive(Debug)] |
49492
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
491 |
pub struct DifferenceMatcher { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
492 |
base: Box<dyn Matcher + Sync>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
493 |
excluded: Box<dyn Matcher + Sync>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
494 |
files: Option<HashSet<HgPathBuf>>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
495 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
496 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
497 |
impl Matcher for DifferenceMatcher { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
498 |
fn file_set(&self) -> Option<&HashSet<HgPathBuf>> { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
499 |
self.files.as_ref() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
500 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
501 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
502 |
fn exact_match(&self, filename: &HgPath) -> bool { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
503 |
self.files.as_ref().map_or(false, |f| f.contains(filename)) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
504 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
505 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
506 |
fn matches(&self, filename: &HgPath) -> bool { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
507 |
self.base.matches(filename) && !self.excluded.matches(filename) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
508 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
509 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
510 |
fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
511 |
let excluded_set = self.excluded.visit_children_set(directory); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
512 |
if excluded_set == VisitChildrenSet::Recursive { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
513 |
return VisitChildrenSet::Empty; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
514 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
515 |
let base_set = self.base.visit_children_set(directory); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
516 |
// Possible values for base: 'recursive', 'this', set(...), set() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
517 |
// Possible values for excluded: 'this', set(...), set() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
518 |
// If excluded has nothing under here that we care about, return base, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
519 |
// even if it's 'recursive'. |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
520 |
if excluded_set == VisitChildrenSet::Empty { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
521 |
return base_set; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
522 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
523 |
match base_set { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
524 |
VisitChildrenSet::This | VisitChildrenSet::Recursive => { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
525 |
// Never return 'recursive' here if excluded_set is any kind of |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
526 |
// non-empty (either 'this' or set(foo)), since excluded might |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
527 |
// return set() for a subdirectory. |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
528 |
VisitChildrenSet::This |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
529 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
530 |
set => { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
531 |
// Possible values for base: set(...), set() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
532 |
// Possible values for excluded: 'this', set(...) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
533 |
// We ignore excluded set results. They're possibly incorrect: |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
534 |
// base = path:dir/subdir |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
535 |
// excluded=rootfilesin:dir, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
536 |
// visit_children_set(''): |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
537 |
// base returns {'dir'}, excluded returns {'dir'}, if we |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
538 |
// subtracted we'd return set(), which is *not* correct, we |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
539 |
// still need to visit 'dir'! |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
540 |
set |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
541 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
542 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
543 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
544 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
545 |
fn matches_everything(&self) -> bool { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
546 |
false |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
547 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
548 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
549 |
fn is_exact(&self) -> bool { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
550 |
self.base.is_exact() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
551 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
552 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
553 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
554 |
impl DifferenceMatcher { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
555 |
pub fn new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
556 |
base: Box<dyn Matcher + Sync>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
557 |
excluded: Box<dyn Matcher + Sync>, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
558 |
) -> Self { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
559 |
let base_is_exact = base.is_exact(); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
560 |
let base_files = base.file_set().map(ToOwned::to_owned); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
561 |
let mut new = Self { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
562 |
base, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
563 |
excluded, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
564 |
files: None, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
565 |
}; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
566 |
if base_is_exact { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
567 |
new.files = base_files.map(|files| { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
568 |
files.iter().cloned().filter(|f| new.matches(f)).collect() |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
569 |
}); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
570 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
571 |
new |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
572 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
573 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
574 |
|
49564
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
575 |
/// Wraps [`regex::bytes::Regex`] to improve performance in multithreaded |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
576 |
/// contexts. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
577 |
/// |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
578 |
/// The `status` algorithm makes heavy use of threads, and calling `is_match` |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
579 |
/// from many threads at once is prone to contention, probably within the |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
580 |
/// scratch space needed as the regex DFA is built lazily. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
581 |
/// |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
582 |
/// We are in the process of raising the issue upstream, but for now |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
583 |
/// the workaround used here is to store the `Regex` in a lazily populated |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
584 |
/// thread-local variable, sharing the initial read-only compilation, but |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
585 |
/// not the lazy dfa scratch space mentioned above. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
586 |
/// |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
587 |
/// This reduces the contention observed with 16+ threads, but does not |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
588 |
/// completely remove it. Hopefully this can be addressed upstream. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
589 |
struct RegexMatcher { |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
590 |
/// Compiled at the start of the status algorithm, used as a base for |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
591 |
/// cloning in each thread-local `self.local`, thus sharing the expensive |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
592 |
/// first compilation. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
593 |
base: regex::bytes::Regex, |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
594 |
/// Thread-local variable that holds the `Regex` that is actually queried |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
595 |
/// from each thread. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
596 |
local: thread_local::ThreadLocal<regex::bytes::Regex>, |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
597 |
} |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
598 |
|
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
599 |
impl RegexMatcher { |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
600 |
/// Returns whether the path matches the stored `Regex`. |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
601 |
pub fn is_match(&self, path: &HgPath) -> bool { |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
602 |
self.local |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
603 |
.get_or(|| self.base.clone()) |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
604 |
.is_match(path.as_bytes()) |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
605 |
} |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
606 |
} |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
607 |
|
44601
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
608 |
/// Returns a function that matches an `HgPath` against the given regex |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
609 |
/// pattern. |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
610 |
/// |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
611 |
/// This can fail when the pattern is invalid or not supported by the |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
612 |
/// underlying engine (the `regex` crate), for instance anything with |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
613 |
/// back-references. |
44861
83c97c0bd319
rust-matchers: add timing tracing to regex compilation
Raphaël Gomès <rgomes@octobus.net>
parents:
44604
diff
changeset
|
614 |
#[timed] |
49564
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
615 |
fn re_matcher(pattern: &[u8]) -> PatternResult<RegexMatcher> { |
44601
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
616 |
use std::io::Write; |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
617 |
|
44891
ad1ec40975aa
rust-regex: fix issues with regex anchoring and performance
Raphaël Gomès <rgomes@octobus.net>
parents:
44880
diff
changeset
|
618 |
// The `regex` crate adds `.*` to the start and end of expressions if there |
ad1ec40975aa
rust-regex: fix issues with regex anchoring and performance
Raphaël Gomès <rgomes@octobus.net>
parents:
44880
diff
changeset
|
619 |
// are no anchors, so add the start anchor. |
ad1ec40975aa
rust-regex: fix issues with regex anchoring and performance
Raphaël Gomès <rgomes@octobus.net>
parents:
44880
diff
changeset
|
620 |
let mut escaped_bytes = vec![b'^', b'(', b'?', b':']; |
44601
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
621 |
for byte in pattern { |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
622 |
if *byte > 127 { |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
623 |
write!(escaped_bytes, "\\x{:x}", *byte).unwrap(); |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
624 |
} else { |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
625 |
escaped_bytes.push(*byte); |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
626 |
} |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
627 |
} |
44891
ad1ec40975aa
rust-regex: fix issues with regex anchoring and performance
Raphaël Gomès <rgomes@octobus.net>
parents:
44880
diff
changeset
|
628 |
escaped_bytes.push(b')'); |
44601
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
629 |
|
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
630 |
// Avoid the cost of UTF8 checking |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
631 |
// |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
632 |
// # Safety |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
633 |
// This is safe because we escaped all non-ASCII bytes. |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
634 |
let pattern_string = unsafe { String::from_utf8_unchecked(escaped_bytes) }; |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
635 |
let re = regex::bytes::RegexBuilder::new(&pattern_string) |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
636 |
.unicode(false) |
44762
b15a37d85dbe
rust-regex: increase the DFA size limit for the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44604
diff
changeset
|
637 |
// Big repos with big `.hgignore` will hit the default limit and |
b15a37d85dbe
rust-regex: increase the DFA size limit for the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44604
diff
changeset
|
638 |
// incur a significant performance hit. One repo's `hg status` hit |
b15a37d85dbe
rust-regex: increase the DFA size limit for the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44604
diff
changeset
|
639 |
// multiple *minutes*. |
b15a37d85dbe
rust-regex: increase the DFA size limit for the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44604
diff
changeset
|
640 |
.dfa_size_limit(50 * (1 << 20)) |
44601
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
641 |
.build() |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
642 |
.map_err(|e| PatternError::UnsupportedSyntax(e.to_string()))?; |
496868f1030c
rust-matchers: use the `regex` crate
Raphaël Gomès <rgomes@octobus.net>
parents:
44551
diff
changeset
|
643 |
|
49564
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
644 |
Ok(RegexMatcher { |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
645 |
base: re, |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
646 |
local: Default::default(), |
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
647 |
}) |
44529
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44387
diff
changeset
|
648 |
} |
52d40f8fb82d
rust-matchers: add function to generate a regex matcher function
Raphaël Gomès <rgomes@octobus.net>
parents:
44387
diff
changeset
|
649 |
|
44531
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44530
diff
changeset
|
650 |
/// Returns the regex pattern and a function that matches an `HgPath` against |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44530
diff
changeset
|
651 |
/// said regex formed by the given ignore patterns. |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
652 |
fn build_regex_match<'a, 'b>( |
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
653 |
ignore_patterns: &'a [IgnorePattern], |
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
654 |
) -> PatternResult<(Vec<u8>, IgnoreFnType<'b>)> { |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
655 |
let mut regexps = vec![]; |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
656 |
let mut exact_set = HashSet::new(); |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
657 |
|
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
658 |
for pattern in ignore_patterns { |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
659 |
if let Some(re) = build_single_regex(pattern)? { |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
660 |
regexps.push(re); |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
661 |
} else { |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
662 |
let exact = normalize_path_bytes(&pattern.pattern); |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
663 |
exact_set.insert(HgPathBuf::from_bytes(&exact)); |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
664 |
} |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
665 |
} |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
666 |
|
44531
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44530
diff
changeset
|
667 |
let full_regex = regexps.join(&b'|'); |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44530
diff
changeset
|
668 |
|
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
669 |
// An empty pattern would cause the regex engine to incorrectly match the |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
670 |
// (empty) root directory |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
671 |
let func = if !(regexps.is_empty()) { |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
672 |
let matcher = re_matcher(&full_regex)?; |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
673 |
let func = move |filename: &HgPath| { |
49564
04f1dba53c96
rust: create wrapper struct to reduce `regex` contention issues
Raphaël Gomès <rgomes@octobus.net>
parents:
49550
diff
changeset
|
674 |
exact_set.contains(filename) || matcher.is_match(filename) |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
675 |
}; |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
676 |
Box::new(func) as IgnoreFnType |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
677 |
} else { |
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
678 |
let func = move |filename: &HgPath| exact_set.contains(filename); |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
679 |
Box::new(func) as IgnoreFnType |
44879
e0414fcd35e0
rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Raphaël Gomès <rgomes@octobus.net>
parents:
44861
diff
changeset
|
680 |
}; |
44531
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44530
diff
changeset
|
681 |
|
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44530
diff
changeset
|
682 |
Ok((full_regex, func)) |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44530
diff
changeset
|
683 |
} |
a21881b40942
rust-matchers: add `build_regex_match` function
Raphaël Gomès <rgomes@octobus.net>
parents:
44530
diff
changeset
|
684 |
|
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
685 |
/// Returns roots and directories corresponding to each pattern. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
686 |
/// |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
687 |
/// This calculates the roots and directories exactly matching the patterns and |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
688 |
/// returns a tuple of (roots, dirs). It does not return other directories |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
689 |
/// which may also need to be considered, like the parent directories. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
690 |
fn roots_and_dirs( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
691 |
ignore_patterns: &[IgnorePattern], |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
692 |
) -> (Vec<HgPathBuf>, Vec<HgPathBuf>) { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
693 |
let mut roots = Vec::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
694 |
let mut dirs = Vec::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
695 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
696 |
for ignore_pattern in ignore_patterns { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
697 |
let IgnorePattern { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
698 |
syntax, pattern, .. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
699 |
} = ignore_pattern; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
700 |
match syntax { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
701 |
PatternSyntax::RootGlob | PatternSyntax::Glob => { |
48311
6d69e83e6b6e
rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
47415
diff
changeset
|
702 |
let mut root = HgPathBuf::new(); |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
703 |
for p in pattern.split(|c| *c == b'/') { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
704 |
if p.iter().any(|c| match *c { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
705 |
b'[' | b'{' | b'*' | b'?' => true, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
706 |
_ => false, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
707 |
}) { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
708 |
break; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
709 |
} |
48311
6d69e83e6b6e
rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
47415
diff
changeset
|
710 |
root.push(HgPathBuf::from_bytes(p).as_ref()); |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
711 |
} |
48311
6d69e83e6b6e
rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
47415
diff
changeset
|
712 |
roots.push(root); |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
713 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
714 |
PatternSyntax::Path | PatternSyntax::RelPath => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
715 |
let pat = HgPath::new(if pattern == b"." { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
716 |
&[] as &[u8] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
717 |
} else { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
718 |
pattern |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
719 |
}); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
720 |
roots.push(pat.to_owned()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
721 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
722 |
PatternSyntax::RootFiles => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
723 |
let pat = if pattern == b"." { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
724 |
&[] as &[u8] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
725 |
} else { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
726 |
pattern |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
727 |
}; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
728 |
dirs.push(HgPathBuf::from_bytes(pat)); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
729 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
730 |
_ => { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
731 |
roots.push(HgPathBuf::new()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
732 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
733 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
734 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
735 |
(roots, dirs) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
736 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
737 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
738 |
/// Paths extracted from patterns |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
739 |
#[derive(Debug, PartialEq)] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
740 |
struct RootsDirsAndParents { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
741 |
/// Directories to match recursively |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
742 |
pub roots: HashSet<HgPathBuf>, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
743 |
/// Directories to match non-recursively |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
744 |
pub dirs: HashSet<HgPathBuf>, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
745 |
/// Implicitly required directories to go to items in either roots or dirs |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
746 |
pub parents: HashSet<HgPathBuf>, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
747 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
748 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
749 |
/// Extract roots, dirs and parents from patterns. |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
750 |
fn roots_dirs_and_parents( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
751 |
ignore_patterns: &[IgnorePattern], |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
752 |
) -> PatternResult<RootsDirsAndParents> { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
753 |
let (roots, dirs) = roots_and_dirs(ignore_patterns); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
754 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
755 |
let mut parents = HashSet::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
756 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
757 |
parents.extend( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
758 |
DirsMultiset::from_manifest(&dirs) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
759 |
.map_err(|e| match e { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
760 |
DirstateMapError::InvalidPath(e) => e, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
761 |
_ => unreachable!(), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
762 |
})? |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
763 |
.iter() |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44929
diff
changeset
|
764 |
.map(ToOwned::to_owned), |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
765 |
); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
766 |
parents.extend( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
767 |
DirsMultiset::from_manifest(&roots) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
768 |
.map_err(|e| match e { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
769 |
DirstateMapError::InvalidPath(e) => e, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
770 |
_ => unreachable!(), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
771 |
})? |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
772 |
.iter() |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44929
diff
changeset
|
773 |
.map(ToOwned::to_owned), |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
774 |
); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
775 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
776 |
Ok(RootsDirsAndParents { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
777 |
roots: HashSet::from_iter(roots), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
778 |
dirs: HashSet::from_iter(dirs), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
779 |
parents, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
780 |
}) |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
781 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
782 |
|
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
783 |
/// Returns a function that checks whether a given file (in the general sense) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
784 |
/// should be matched. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
785 |
fn build_match<'a, 'b>( |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
786 |
ignore_patterns: Vec<IgnorePattern>, |
48402
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
787 |
) -> PatternResult<(Vec<u8>, IgnoreFnType<'b>)> { |
2009e3c64a53
rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48311
diff
changeset
|
788 |
let mut match_funcs: Vec<IgnoreFnType<'b>> = vec![]; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
789 |
// For debugging and printing |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
790 |
let mut patterns = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
791 |
|
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
792 |
let (subincludes, ignore_patterns) = filter_subincludes(ignore_patterns)?; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
793 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
794 |
if !subincludes.is_empty() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
795 |
// Build prefix-based matcher functions for subincludes |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
796 |
let mut submatchers = FastHashMap::default(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
797 |
let mut prefixes = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
798 |
|
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
799 |
for sub_include in subincludes { |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
800 |
let matcher = IncludeMatcher::new(sub_include.included_patterns)?; |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
801 |
let match_fn = |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
802 |
Box::new(move |path: &HgPath| matcher.matches(path)); |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
803 |
prefixes.push(sub_include.prefix.clone()); |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
804 |
submatchers.insert(sub_include.prefix.clone(), match_fn); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
805 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
806 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
807 |
let match_subinclude = move |filename: &HgPath| { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
808 |
for prefix in prefixes.iter() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
809 |
if let Some(rel) = filename.relative_to(prefix) { |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44929
diff
changeset
|
810 |
if (submatchers[prefix])(rel) { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
811 |
return true; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
812 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
813 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
814 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
815 |
false |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
816 |
}; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
817 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
818 |
match_funcs.push(Box::new(match_subinclude)); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
819 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
820 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
821 |
if !ignore_patterns.is_empty() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
822 |
// Either do dumb matching if all patterns are rootfiles, or match |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
823 |
// with a regex. |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
824 |
if ignore_patterns |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
825 |
.iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
826 |
.all(|k| k.syntax == PatternSyntax::RootFiles) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
827 |
{ |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
828 |
let dirs: HashSet<_> = ignore_patterns |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
829 |
.iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
830 |
.map(|k| k.pattern.to_owned()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
831 |
.collect(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
832 |
let mut dirs_vec: Vec<_> = dirs.iter().cloned().collect(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
833 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
834 |
let match_func = move |path: &HgPath| -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
835 |
let path = path.as_bytes(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
836 |
let i = path.iter().rfind(|a| **a == b'/'); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
837 |
let dir = if let Some(i) = i { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
838 |
&path[..*i as usize] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
839 |
} else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
840 |
b"." |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
841 |
}; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
842 |
dirs.contains(dir.deref()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
843 |
}; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
844 |
match_funcs.push(Box::new(match_func)); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
845 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
846 |
patterns.extend(b"rootfilesin: "); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
847 |
dirs_vec.sort(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
848 |
patterns.extend(dirs_vec.escaped_bytes()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
849 |
} else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
850 |
let (new_re, match_func) = build_regex_match(&ignore_patterns)?; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
851 |
patterns = new_re; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
852 |
match_funcs.push(match_func) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
853 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
854 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
855 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
856 |
Ok(if match_funcs.len() == 1 { |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
857 |
(patterns, match_funcs.remove(0)) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
858 |
} else { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
859 |
( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
860 |
patterns, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
861 |
Box::new(move |f: &HgPath| -> bool { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
862 |
match_funcs.iter().any(|match_func| match_func(f)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
863 |
}), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
864 |
) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
865 |
}) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
866 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
867 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
868 |
/// Parses all "ignore" files with their recursive includes and returns a |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
869 |
/// function that checks whether a given file (in the general sense) should be |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
870 |
/// ignored. |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
871 |
pub fn get_ignore_matcher<'a>( |
47415
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
872 |
mut all_pattern_files: Vec<PathBuf>, |
47384
777c3d231913
rust: Make some file path parameters less generic
Simon Sapin <simon.sapin@octobus.net>
parents:
45610
diff
changeset
|
873 |
root_dir: &Path, |
49550
363923bd51cd
dirstate-v2: hash the source of the ignore patterns as well
Raphaël Gomès <rgomes@octobus.net>
parents:
49500
diff
changeset
|
874 |
inspect_pattern_bytes: &mut impl FnMut(&Path, &[u8]), |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
875 |
) -> PatternResult<(IncludeMatcher<'a>, Vec<PatternFileWarning>)> { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
876 |
let mut all_patterns = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
877 |
let mut all_warnings = vec![]; |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
878 |
|
47415
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
879 |
// Sort to make the ordering of calls to `inspect_pattern_bytes` |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
880 |
// deterministic even if the ordering of `all_pattern_files` is not (such |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
881 |
// as when a iteration order of a Python dict or Rust HashMap is involved). |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
882 |
// Sort by "string" representation instead of the default by component |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
883 |
// (with a Rust-specific definition of a component) |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
884 |
all_pattern_files |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
885 |
.sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str())); |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
886 |
|
47384
777c3d231913
rust: Make some file path parameters less generic
Simon Sapin <simon.sapin@octobus.net>
parents:
45610
diff
changeset
|
887 |
for pattern_file in &all_pattern_files { |
47415
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
888 |
let (patterns, warnings) = get_patterns_from_file( |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
889 |
pattern_file, |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
890 |
root_dir, |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
891 |
inspect_pattern_bytes, |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47385
diff
changeset
|
892 |
)?; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
893 |
|
44604
e62052d0f377
rust-status: only involve ignore mechanism when needed
Raphaël Gomès <rgomes@octobus.net>
parents:
44601
diff
changeset
|
894 |
all_patterns.extend(patterns.to_owned()); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
895 |
all_warnings.extend(warnings); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
896 |
} |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
897 |
let matcher = IncludeMatcher::new(all_patterns)?; |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
898 |
Ok((matcher, all_warnings)) |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
899 |
} |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
900 |
|
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
901 |
/// Parses all "ignore" files with their recursive includes and returns a |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
902 |
/// function that checks whether a given file (in the general sense) should be |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
903 |
/// ignored. |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
904 |
pub fn get_ignore_function<'a>( |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
905 |
all_pattern_files: Vec<PathBuf>, |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
906 |
root_dir: &Path, |
49550
363923bd51cd
dirstate-v2: hash the source of the ignore patterns as well
Raphaël Gomès <rgomes@octobus.net>
parents:
49500
diff
changeset
|
907 |
inspect_pattern_bytes: &mut impl FnMut(&Path, &[u8]), |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
908 |
) -> PatternResult<(IgnoreFnType<'a>, Vec<PatternFileWarning>)> { |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
909 |
let res = |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
910 |
get_ignore_matcher(all_pattern_files, root_dir, inspect_pattern_bytes); |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
911 |
res.map(|(matcher, all_warnings)| { |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
912 |
let res: IgnoreFnType<'a> = |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
913 |
Box::new(move |path: &HgPath| matcher.matches(path)); |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
914 |
|
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
915 |
(res, all_warnings) |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
916 |
}) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
917 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
918 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
919 |
impl<'a> IncludeMatcher<'a> { |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
920 |
pub fn new(ignore_patterns: Vec<IgnorePattern>) -> PatternResult<Self> { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
921 |
let RootsDirsAndParents { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
922 |
roots, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
923 |
dirs, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
924 |
parents, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
925 |
} = roots_dirs_and_parents(&ignore_patterns)?; |
49408
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
926 |
let prefix = ignore_patterns.iter().all(|k| match k.syntax { |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
927 |
PatternSyntax::Path | PatternSyntax::RelPath => true, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
928 |
_ => false, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
929 |
}); |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
930 |
let (patterns, match_fn) = build_match(ignore_patterns)?; |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
931 |
|
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
932 |
Ok(Self { |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
933 |
patterns, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
934 |
match_fn, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
935 |
prefix, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
936 |
roots, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
937 |
dirs, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
938 |
parents, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
939 |
}) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
940 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
941 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
942 |
fn get_all_parents_children(&self) -> DirsChildrenMultiset { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
943 |
// TODO cache |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
944 |
let thing = self |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
945 |
.dirs |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
946 |
.iter() |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
947 |
.chain(self.roots.iter()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
948 |
.chain(self.parents.iter()); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
949 |
DirsChildrenMultiset::new(thing, Some(&self.parents)) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
950 |
} |
48403
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
951 |
|
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
952 |
pub fn debug_get_patterns(&self) -> &[u8] { |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
953 |
self.patterns.as_ref() |
6d4daf51283c
rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48402
diff
changeset
|
954 |
} |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
955 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
956 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
957 |
impl<'a> Display for IncludeMatcher<'a> { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
958 |
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { |
44880
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44879
diff
changeset
|
959 |
// XXX What about exact matches? |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44879
diff
changeset
|
960 |
// I'm not sure it's worth it to clone the HashSet and keep it |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44879
diff
changeset
|
961 |
// around just in case someone wants to display the matcher, plus |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44879
diff
changeset
|
962 |
// it's going to be unreadable after a few entries, but we need to |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44879
diff
changeset
|
963 |
// inform in this display that exact matches are being used and are |
de0fb4463a3d
rust-matchers: add TODO about incomplete `Display` for `IncludeMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44879
diff
changeset
|
964 |
// (on purpose) missing from the `includes`. |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
965 |
write!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
966 |
f, |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
967 |
"IncludeMatcher(includes='{}')", |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
968 |
String::from_utf8_lossy(&self.patterns.escaped_bytes()) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
969 |
) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
970 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
971 |
} |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
972 |
|
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
973 |
#[cfg(test)] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
974 |
mod tests { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
975 |
use super::*; |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
976 |
use pretty_assertions::assert_eq; |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
977 |
use std::path::Path; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
978 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
979 |
#[test] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
980 |
fn test_roots_and_dirs() { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
981 |
let pats = vec![ |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
982 |
IgnorePattern::new(PatternSyntax::Glob, b"g/h/*", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
983 |
IgnorePattern::new(PatternSyntax::Glob, b"g/h", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
984 |
IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
985 |
]; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
986 |
let (roots, dirs) = roots_and_dirs(&pats); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
987 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
988 |
assert_eq!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
989 |
roots, |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
990 |
vec!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
991 |
HgPathBuf::from_bytes(b"g/h"), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
992 |
HgPathBuf::from_bytes(b"g/h"), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
993 |
HgPathBuf::new() |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
994 |
), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
995 |
); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
996 |
assert_eq!(dirs, vec!()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
997 |
} |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
998 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
999 |
#[test] |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1000 |
fn test_roots_dirs_and_parents() { |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1001 |
let pats = vec![ |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1002 |
IgnorePattern::new(PatternSyntax::Glob, b"g/h/*", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1003 |
IgnorePattern::new(PatternSyntax::Glob, b"g/h", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1004 |
IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")), |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1005 |
]; |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1006 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1007 |
let mut roots = HashSet::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1008 |
roots.insert(HgPathBuf::from_bytes(b"g/h")); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1009 |
roots.insert(HgPathBuf::new()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1010 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1011 |
let dirs = HashSet::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1012 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1013 |
let mut parents = HashSet::new(); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1014 |
parents.insert(HgPathBuf::new()); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1015 |
parents.insert(HgPathBuf::from_bytes(b"g")); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1016 |
|
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1017 |
assert_eq!( |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1018 |
roots_dirs_and_parents(&pats).unwrap(), |
44534
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1019 |
RootsDirsAndParents { |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1020 |
roots, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1021 |
dirs, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1022 |
parents |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44532
diff
changeset
|
1023 |
} |
44530
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1024 |
); |
d4e8cfcde012
rust-matchers: add functions to get roots, dirs and parents from patterns
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
1025 |
} |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1026 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1027 |
#[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1028 |
fn test_filematcher_visit_children_set() { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1029 |
// Visitchildrenset |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1030 |
let files = vec![HgPathBuf::from_bytes(b"dir/subdir/foo.txt")]; |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1031 |
let matcher = FileMatcher::new(files).unwrap(); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1032 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1033 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1034 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1035 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1036 |
matcher.visit_children_set(HgPath::new(b"")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1037 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1038 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1039 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1040 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1041 |
set.insert(HgPathBuf::from_bytes(b"subdir")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1042 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1043 |
matcher.visit_children_set(HgPath::new(b"dir")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1044 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1045 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1046 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1047 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1048 |
set.insert(HgPathBuf::from_bytes(b"foo.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1049 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1050 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1051 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1052 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1053 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1054 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1055 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1056 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1057 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1058 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1059 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/foo.txt")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1060 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1061 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1062 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1063 |
matcher.visit_children_set(HgPath::new(b"folder")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1064 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1065 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1066 |
} |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1067 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1068 |
#[test] |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1069 |
fn test_filematcher_visit_children_set_files_and_dirs() { |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1070 |
let files = vec![ |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1071 |
HgPathBuf::from_bytes(b"rootfile.txt"), |
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1072 |
HgPathBuf::from_bytes(b"a/file1.txt"), |
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1073 |
HgPathBuf::from_bytes(b"a/b/file2.txt"), |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1074 |
// No file in a/b/c |
45610
75f785888a7b
rust-matchers: make `Matcher` trait object-safe
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
1075 |
HgPathBuf::from_bytes(b"a/b/c/d/file4.txt"), |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1076 |
]; |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1077 |
let matcher = FileMatcher::new(files).unwrap(); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1078 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1079 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1080 |
set.insert(HgPathBuf::from_bytes(b"a")); |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1081 |
set.insert(HgPathBuf::from_bytes(b"rootfile.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1082 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1083 |
matcher.visit_children_set(HgPath::new(b"")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1084 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1085 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1086 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1087 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1088 |
set.insert(HgPathBuf::from_bytes(b"b")); |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1089 |
set.insert(HgPathBuf::from_bytes(b"file1.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1090 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1091 |
matcher.visit_children_set(HgPath::new(b"a")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1092 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1093 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1094 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1095 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1096 |
set.insert(HgPathBuf::from_bytes(b"c")); |
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1097 |
set.insert(HgPathBuf::from_bytes(b"file2.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1098 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1099 |
matcher.visit_children_set(HgPath::new(b"a/b")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1100 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1101 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1102 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1103 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1104 |
set.insert(HgPathBuf::from_bytes(b"d")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1105 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1106 |
matcher.visit_children_set(HgPath::new(b"a/b/c")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1107 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1108 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1109 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1110 |
set.insert(HgPathBuf::from_bytes(b"file4.txt")); |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1111 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1112 |
matcher.visit_children_set(HgPath::new(b"a/b/c/d")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1113 |
VisitChildrenSet::Set(set) |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1114 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1115 |
|
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1116 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1117 |
matcher.visit_children_set(HgPath::new(b"a/b/c/d/e")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1118 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1119 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1120 |
assert_eq!( |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1121 |
matcher.visit_children_set(HgPath::new(b"folder")), |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1122 |
VisitChildrenSet::Empty |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1123 |
); |
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1124 |
} |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1125 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1126 |
#[test] |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1127 |
fn test_includematcher() { |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1128 |
// VisitchildrensetPrefix |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1129 |
let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1130 |
PatternSyntax::RelPath, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1131 |
b"dir/subdir", |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1132 |
Path::new(""), |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1133 |
)]) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1134 |
.unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1135 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1136 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1137 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1138 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1139 |
matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1140 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1141 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1142 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1143 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1144 |
set.insert(HgPathBuf::from_bytes(b"subdir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1145 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1146 |
matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1147 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1148 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1149 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1150 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1151 |
VisitChildrenSet::Recursive |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1152 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1153 |
// OPT: This should probably be 'all' if its parent is? |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1154 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1155 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1156 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1157 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1158 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1159 |
matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1160 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1161 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1162 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1163 |
// VisitchildrensetRootfilesin |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1164 |
let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1165 |
PatternSyntax::RootFiles, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1166 |
b"dir/subdir", |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1167 |
Path::new(""), |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1168 |
)]) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1169 |
.unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1170 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1171 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1172 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1173 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1174 |
matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1175 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1176 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1177 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1178 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1179 |
set.insert(HgPathBuf::from_bytes(b"subdir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1180 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1181 |
matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1182 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1183 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1184 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1185 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1186 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1187 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1188 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1189 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1190 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1191 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1192 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1193 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1194 |
matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1195 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1196 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1197 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1198 |
// VisitchildrensetGlob |
47385
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1199 |
let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1200 |
PatternSyntax::Glob, |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1201 |
b"dir/z*", |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1202 |
Path::new(""), |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47384
diff
changeset
|
1203 |
)]) |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1204 |
.unwrap(); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1205 |
|
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1206 |
let mut set = HashSet::new(); |
49349
137d6bb71937
rust: use owned types in `Matcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
48403
diff
changeset
|
1207 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1208 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1209 |
matcher.visit_children_set(HgPath::new(b"")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1210 |
VisitChildrenSet::Set(set) |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1211 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1212 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1213 |
matcher.visit_children_set(HgPath::new(b"folder")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1214 |
VisitChildrenSet::Empty |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1215 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1216 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1217 |
matcher.visit_children_set(HgPath::new(b"dir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1218 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1219 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1220 |
// OPT: these should probably be set(). |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1221 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1222 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1223 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1224 |
); |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1225 |
assert_eq!( |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1226 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1227 |
VisitChildrenSet::This |
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1228 |
); |
49408
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1229 |
|
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1230 |
// Test multiple patterns |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1231 |
let matcher = IncludeMatcher::new(vec![ |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1232 |
IgnorePattern::new(PatternSyntax::RelPath, b"foo", Path::new("")), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1233 |
IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1234 |
]) |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1235 |
.unwrap(); |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1236 |
|
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1237 |
assert_eq!( |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1238 |
matcher.visit_children_set(HgPath::new(b"")), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1239 |
VisitChildrenSet::This |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1240 |
); |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1241 |
|
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1242 |
// Test multiple patterns |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1243 |
let matcher = IncludeMatcher::new(vec![IgnorePattern::new( |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1244 |
PatternSyntax::Glob, |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1245 |
b"**/*.exe", |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1246 |
Path::new(""), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1247 |
)]) |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1248 |
.unwrap(); |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1249 |
|
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1250 |
assert_eq!( |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1251 |
matcher.visit_children_set(HgPath::new(b"")), |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1252 |
VisitChildrenSet::This |
90512ca6a255
rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
Raphaël Gomès <rgomes@octobus.net>
parents:
49355
diff
changeset
|
1253 |
); |
44532
c697638e0e91
rust-matchers: add `IgnoreMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44531
diff
changeset
|
1254 |
} |
49351
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1255 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1256 |
#[test] |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1257 |
fn test_unionmatcher() { |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1258 |
// Path + Rootfiles |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1259 |
let m1 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1260 |
PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1261 |
b"dir/subdir", |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1262 |
Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1263 |
)]) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1264 |
.unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1265 |
let m2 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1266 |
PatternSyntax::RootFiles, |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1267 |
b"dir", |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1268 |
Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1269 |
)]) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1270 |
.unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1271 |
let matcher = UnionMatcher::new(vec![Box::new(m1), Box::new(m2)]); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1272 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1273 |
let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1274 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1275 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1276 |
matcher.visit_children_set(HgPath::new(b"")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1277 |
VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1278 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1279 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1280 |
matcher.visit_children_set(HgPath::new(b"dir")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1281 |
VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1282 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1283 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1284 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1285 |
VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1286 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1287 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1288 |
matcher.visit_children_set(HgPath::new(b"dir/foo")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1289 |
VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1290 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1291 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1292 |
matcher.visit_children_set(HgPath::new(b"folder")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1293 |
VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1294 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1295 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1296 |
matcher.visit_children_set(HgPath::new(b"folder")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1297 |
VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1298 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1299 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1300 |
// OPT: These next two could be 'all' instead of 'this'. |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1301 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1302 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1303 |
VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1304 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1305 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1306 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1307 |
VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1308 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1309 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1310 |
// Path + unrelated Path |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1311 |
let m1 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1312 |
PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1313 |
b"dir/subdir", |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1314 |
Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1315 |
)]) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1316 |
.unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1317 |
let m2 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1318 |
PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1319 |
b"folder", |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1320 |
Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1321 |
)]) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1322 |
.unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1323 |
let matcher = UnionMatcher::new(vec![Box::new(m1), Box::new(m2)]); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1324 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1325 |
let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1326 |
set.insert(HgPathBuf::from_bytes(b"folder")); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1327 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1328 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1329 |
matcher.visit_children_set(HgPath::new(b"")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1330 |
VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1331 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1332 |
let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1333 |
set.insert(HgPathBuf::from_bytes(b"subdir")); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1334 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1335 |
matcher.visit_children_set(HgPath::new(b"dir")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1336 |
VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1337 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1338 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1339 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1340 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1341 |
VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1342 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1343 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1344 |
matcher.visit_children_set(HgPath::new(b"dir/foo")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1345 |
VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1346 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1347 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1348 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1349 |
matcher.visit_children_set(HgPath::new(b"folder")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1350 |
VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1351 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1352 |
// OPT: These next two could be 'all' instead of 'this'. |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1353 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1354 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1355 |
VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1356 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1357 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1358 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1359 |
VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1360 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1361 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1362 |
// Path + subpath |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1363 |
let m1 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1364 |
PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1365 |
b"dir/subdir/x", |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1366 |
Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1367 |
)]) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1368 |
.unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1369 |
let m2 = IncludeMatcher::new(vec![IgnorePattern::new( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1370 |
PatternSyntax::RelPath, |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1371 |
b"dir/subdir", |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1372 |
Path::new(""), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1373 |
)]) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1374 |
.unwrap(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1375 |
let matcher = UnionMatcher::new(vec![Box::new(m1), Box::new(m2)]); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1376 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1377 |
let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1378 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1379 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1380 |
matcher.visit_children_set(HgPath::new(b"")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1381 |
VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1382 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1383 |
let mut set = HashSet::new(); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1384 |
set.insert(HgPathBuf::from_bytes(b"subdir")); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1385 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1386 |
matcher.visit_children_set(HgPath::new(b"dir")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1387 |
VisitChildrenSet::Set(set) |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1388 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1389 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1390 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1391 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1392 |
VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1393 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1394 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1395 |
matcher.visit_children_set(HgPath::new(b"dir/foo")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1396 |
VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1397 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1398 |
|
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1399 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1400 |
matcher.visit_children_set(HgPath::new(b"folder")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1401 |
VisitChildrenSet::Empty |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1402 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1403 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1404 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1405 |
VisitChildrenSet::Recursive |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1406 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1407 |
// OPT: this should probably be 'all' not 'this'. |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1408 |
assert_eq!( |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1409 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1410 |
VisitChildrenSet::This |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1411 |
); |
b508cffd3c04
rust: add UnionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49349
diff
changeset
|
1412 |
} |
49353
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1413 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1414 |
#[test] |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1415 |
fn test_intersectionmatcher() { |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1416 |
// Include path + Include rootfiles |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1417 |
let m1 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1418 |
IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1419 |
PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1420 |
b"dir/subdir", |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1421 |
Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1422 |
)]) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1423 |
.unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1424 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1425 |
let m2 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1426 |
IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1427 |
PatternSyntax::RootFiles, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1428 |
b"dir", |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1429 |
Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1430 |
)]) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1431 |
.unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1432 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1433 |
let matcher = IntersectionMatcher::new(m1, m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1434 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1435 |
let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1436 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1437 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1438 |
matcher.visit_children_set(HgPath::new(b"")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1439 |
VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1440 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1441 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1442 |
matcher.visit_children_set(HgPath::new(b"dir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1443 |
VisitChildrenSet::This |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1444 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1445 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1446 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1447 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1448 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1449 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1450 |
matcher.visit_children_set(HgPath::new(b"dir/foo")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1451 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1452 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1453 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1454 |
matcher.visit_children_set(HgPath::new(b"folder")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1455 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1456 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1457 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1458 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1459 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1460 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1461 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1462 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1463 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1464 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1465 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1466 |
// Non intersecting paths |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1467 |
let m1 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1468 |
IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1469 |
PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1470 |
b"dir/subdir", |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1471 |
Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1472 |
)]) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1473 |
.unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1474 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1475 |
let m2 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1476 |
IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1477 |
PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1478 |
b"folder", |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1479 |
Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1480 |
)]) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1481 |
.unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1482 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1483 |
let matcher = IntersectionMatcher::new(m1, m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1484 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1485 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1486 |
matcher.visit_children_set(HgPath::new(b"")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1487 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1488 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1489 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1490 |
matcher.visit_children_set(HgPath::new(b"dir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1491 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1492 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1493 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1494 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1495 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1496 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1497 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1498 |
matcher.visit_children_set(HgPath::new(b"dir/foo")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1499 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1500 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1501 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1502 |
matcher.visit_children_set(HgPath::new(b"folder")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1503 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1504 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1505 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1506 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1507 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1508 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1509 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1510 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1511 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1512 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1513 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1514 |
// Nested paths |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1515 |
let m1 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1516 |
IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1517 |
PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1518 |
b"dir/subdir/x", |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1519 |
Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1520 |
)]) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1521 |
.unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1522 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1523 |
let m2 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1524 |
IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1525 |
PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1526 |
b"dir/subdir", |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1527 |
Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1528 |
)]) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1529 |
.unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1530 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1531 |
let matcher = IntersectionMatcher::new(m1, m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1532 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1533 |
let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1534 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1535 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1536 |
matcher.visit_children_set(HgPath::new(b"")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1537 |
VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1538 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1539 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1540 |
let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1541 |
set.insert(HgPathBuf::from_bytes(b"subdir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1542 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1543 |
matcher.visit_children_set(HgPath::new(b"dir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1544 |
VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1545 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1546 |
let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1547 |
set.insert(HgPathBuf::from_bytes(b"x")); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1548 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1549 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1550 |
VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1551 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1552 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1553 |
matcher.visit_children_set(HgPath::new(b"dir/foo")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1554 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1555 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1556 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1557 |
matcher.visit_children_set(HgPath::new(b"folder")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1558 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1559 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1560 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1561 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1562 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1563 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1564 |
// OPT: this should probably be 'all' not 'this'. |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1565 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1566 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1567 |
VisitChildrenSet::This |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1568 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1569 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1570 |
// Diverging paths |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1571 |
let m1 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1572 |
IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1573 |
PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1574 |
b"dir/subdir/x", |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1575 |
Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1576 |
)]) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1577 |
.unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1578 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1579 |
let m2 = Box::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1580 |
IncludeMatcher::new(vec![IgnorePattern::new( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1581 |
PatternSyntax::RelPath, |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1582 |
b"dir/subdir/z", |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1583 |
Path::new(""), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1584 |
)]) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1585 |
.unwrap(), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1586 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1587 |
let matcher = IntersectionMatcher::new(m1, m2); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1588 |
|
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1589 |
// OPT: these next two could probably be Empty as well. |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1590 |
let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1591 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1592 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1593 |
matcher.visit_children_set(HgPath::new(b"")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1594 |
VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1595 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1596 |
// OPT: these next two could probably be Empty as well. |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1597 |
let mut set = HashSet::new(); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1598 |
set.insert(HgPathBuf::from_bytes(b"subdir")); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1599 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1600 |
matcher.visit_children_set(HgPath::new(b"dir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1601 |
VisitChildrenSet::Set(set) |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1602 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1603 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1604 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1605 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1606 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1607 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1608 |
matcher.visit_children_set(HgPath::new(b"dir/foo")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1609 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1610 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1611 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1612 |
matcher.visit_children_set(HgPath::new(b"folder")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1613 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1614 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1615 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1616 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1617 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1618 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1619 |
assert_eq!( |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1620 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1621 |
VisitChildrenSet::Empty |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1622 |
); |
5e53ecbc308f
rust: add IntersectionMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49351
diff
changeset
|
1623 |
} |
49492
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1624 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1625 |
#[test] |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1626 |
fn test_differencematcher() { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1627 |
// Two alwaysmatchers should function like a nevermatcher |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1628 |
let m1 = AlwaysMatcher; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1629 |
let m2 = AlwaysMatcher; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1630 |
let matcher = DifferenceMatcher::new(Box::new(m1), Box::new(m2)); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1631 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1632 |
for case in &[ |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1633 |
&b""[..], |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1634 |
b"dir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1635 |
b"dir/subdir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1636 |
b"dir/subdir/z", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1637 |
b"dir/foo", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1638 |
b"dir/subdir/x", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1639 |
b"folder", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1640 |
] { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1641 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1642 |
matcher.visit_children_set(HgPath::new(case)), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1643 |
VisitChildrenSet::Empty |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1644 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1645 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1646 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1647 |
// One always and one never should behave the same as an always |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1648 |
let m1 = AlwaysMatcher; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1649 |
let m2 = NeverMatcher; |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1650 |
let matcher = DifferenceMatcher::new(Box::new(m1), Box::new(m2)); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1651 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1652 |
for case in &[ |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1653 |
&b""[..], |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1654 |
b"dir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1655 |
b"dir/subdir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1656 |
b"dir/subdir/z", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1657 |
b"dir/foo", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1658 |
b"dir/subdir/x", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1659 |
b"folder", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1660 |
] { |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1661 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1662 |
matcher.visit_children_set(HgPath::new(case)), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1663 |
VisitChildrenSet::Recursive |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1664 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1665 |
} |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1666 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1667 |
// Two include matchers |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1668 |
let m1 = Box::new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1669 |
IncludeMatcher::new(vec![IgnorePattern::new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1670 |
PatternSyntax::RelPath, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1671 |
b"dir/subdir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1672 |
Path::new("/repo"), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1673 |
)]) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1674 |
.unwrap(), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1675 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1676 |
let m2 = Box::new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1677 |
IncludeMatcher::new(vec![IgnorePattern::new( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1678 |
PatternSyntax::RootFiles, |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1679 |
b"dir", |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1680 |
Path::new("/repo"), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1681 |
)]) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1682 |
.unwrap(), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1683 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1684 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1685 |
let matcher = DifferenceMatcher::new(m1, m2); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1686 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1687 |
let mut set = HashSet::new(); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1688 |
set.insert(HgPathBuf::from_bytes(b"dir")); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1689 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1690 |
matcher.visit_children_set(HgPath::new(b"")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1691 |
VisitChildrenSet::Set(set) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1692 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1693 |
|
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1694 |
let mut set = HashSet::new(); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1695 |
set.insert(HgPathBuf::from_bytes(b"subdir")); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1696 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1697 |
matcher.visit_children_set(HgPath::new(b"dir")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1698 |
VisitChildrenSet::Set(set) |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1699 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1700 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1701 |
matcher.visit_children_set(HgPath::new(b"dir/subdir")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1702 |
VisitChildrenSet::Recursive |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1703 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1704 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1705 |
matcher.visit_children_set(HgPath::new(b"dir/foo")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1706 |
VisitChildrenSet::Empty |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1707 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1708 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1709 |
matcher.visit_children_set(HgPath::new(b"folder")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1710 |
VisitChildrenSet::Empty |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1711 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1712 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1713 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/z")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1714 |
VisitChildrenSet::This |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1715 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1716 |
assert_eq!( |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1717 |
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1718 |
VisitChildrenSet::This |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1719 |
); |
d8ce883ff1f4
rust-matchers: implement DifferenceMatcher
Raphaël Gomès <rgomes@octobus.net>
parents:
49408
diff
changeset
|
1720 |
} |
44387
54d185eb24b5
rust-matchers: implement `visit_children_set` for `FileMatcher`
Raphaël Gomès <rgomes@octobus.net>
parents:
44009
diff
changeset
|
1721 |
} |