annotate rust/hg-core/src/matchers.rs @ 50865:f874342fa568

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