annotate rust/hg-core/src/matchers.rs @ 51471:5633de951d34 stable

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