annotate rust/hg-core/src/matchers.rs @ 49175:34decbaf4da3

node: manually implement Debug I got too irritated today with the default Debug implementation of hg::revlog::Node while playing with a new parser. This isn't quite what I wanted, but it wasn't much code and it at least gives you output that's easy to visually compare to a node.hex()ed identifier from the Python side of things. Sadly, this doesn't influence the output in lldb or the VSCode debugger extension that uses lldb under the covers, but it at least means debug prints are a little more useful. Differential Revision: https://phab.mercurial-scm.org/D12608
author Augie Fackler <augie@google.com>
date Thu, 05 May 2022 14:47:26 -0400
parents 6d4daf51283c
children 137d6bb71937
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,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
18 hg_path::{HgPath, HgPathBuf},
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 },
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
21 DirsMultiset, DirstateMapError, FastHashMap, IgnorePattern, PatternError,
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
22 PatternSyntax,
44519
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44353
diff changeset
23 };
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
24
48354
2009e3c64a53 rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48311
diff changeset
25 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
26 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
27 use std::borrow::ToOwned;
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
28 use std::collections::HashSet;
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
29 use std::fmt::{Display, Error, Formatter};
43914
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
30 use std::iter::FromIterator;
44353
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
31 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
32 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
33
44784
83c97c0bd319 rust-matchers: add timing tracing to regex compilation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44597
diff changeset
34 use micro_timer::timed;
83c97c0bd319 rust-matchers: add timing tracing to regex compilation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44597
diff changeset
35
44353
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
36 #[derive(Debug, PartialEq)]
43832
1bb4e9b02984 rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43611
diff changeset
37 pub enum VisitChildrenSet<'a> {
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
38 /// Don't visit anything
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
39 Empty,
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
40 /// Only visit this directory
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
41 This,
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
42 /// 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
43 /// TODO Should we implement a `NonEmptyHashSet`?
43832
1bb4e9b02984 rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43611
diff changeset
44 Set(HashSet<&'a HgPath>),
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
45 /// 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
46 Recursive,
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
47 }
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
48
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
49 pub trait Matcher {
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
50 /// Explicitly listed files
43832
1bb4e9b02984 rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43611
diff changeset
51 fn file_set(&self) -> Option<&HashSet<&HgPath>>;
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
52 /// Returns whether `filename` is in `file_set`
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
53 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
54 /// 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
55 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
56 /// Decides whether a directory should be visited based on whether it
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
57 /// has potential matches in it or one of its subdirectories, and
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
58 /// potentially lists which subdirectories of that directory should be
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
59 /// visited. This is based on the match's primary, included, and excluded
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
60 /// patterns.
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
61 ///
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
62 /// # Example
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
63 ///
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
64 /// Assume matchers `['path:foo/bar', 'rootfilesin:qux']`, we would
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
65 /// return the following values (assuming the implementation of
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
66 /// visit_children_set is capable of recognizing this; some implementations
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
67 /// are not).
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
68 ///
44006
72bced4f2936 rust-matchers: fixing cargo doc
Georges Racinet <georges.racinet@octobus.net>
parents: 43914
diff changeset
69 /// ```text
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
70 /// ```ignore
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
71 /// '' -> {'foo', 'qux'}
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
72 /// 'baz' -> set()
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
73 /// 'foo' -> {'bar'}
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
74 /// // Ideally this would be `Recursive`, but since the prefix nature of
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
75 /// // matchers is applied to the entire matcher, we have to downgrade this
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
76 /// // to `This` due to the (yet to be implemented in Rust) non-prefix
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
77 /// // `RootFilesIn'-kind matcher being mixed in.
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
78 /// 'foo/bar' -> 'this'
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
79 /// 'qux' -> 'this'
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
80 /// ```
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
81 /// # Important
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
82 ///
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
83 /// Most matchers do not know if they're representing files or
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
84 /// directories. They see `['path:dir/f']` and don't know whether `f` is a
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
85 /// file or a directory, so `visit_children_set('dir')` for most matchers
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
86 /// will return `HashSet{ HgPath { "f" } }`, but if the matcher knows it's
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
87 /// a file (like the yet to be implemented in Rust `ExactMatcher` does),
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
88 /// it may return `VisitChildrenSet::This`.
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
89 /// Do not rely on the return being a `HashSet` indicating that there are
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
90 /// no files in this dir to investigate (or equivalently that if there are
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
91 /// files to investigate in 'dir' that it will always return
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
92 /// `VisitChildrenSet::This`).
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
93 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
94 /// Matcher will match everything and `files_set()` will be empty:
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
95 /// optimization might be possible.
43611
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
96 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
97 /// Matcher will match exactly the files in `files_set()`: optimization
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
98 /// might be possible.
43611
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
99 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
100 }
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
101
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
102 /// Matches everything.
43834
542c8b277261 rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43832
diff changeset
103 ///```
542c8b277261 rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43832
diff changeset
104 /// 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
105 ///
542c8b277261 rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43832
diff changeset
106 /// let matcher = AlwaysMatcher;
542c8b277261 rust-matchers: add doctests for `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43832
diff changeset
107 ///
43914
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
108 /// assert_eq!(matcher.matches(HgPath::new(b"whatever")), true);
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
109 /// assert_eq!(matcher.matches(HgPath::new(b"b.txt")), true);
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
110 /// assert_eq!(matcher.matches(HgPath::new(b"main.c")), true);
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
111 /// 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
112 /// ```
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
113 #[derive(Debug)]
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
114 pub struct AlwaysMatcher;
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
115
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
116 impl Matcher for AlwaysMatcher {
43832
1bb4e9b02984 rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43611
diff changeset
117 fn file_set(&self) -> Option<&HashSet<&HgPath>> {
1bb4e9b02984 rust-matchers: improve `Matcher` trait ergonomics
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43611
diff changeset
118 None
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
119 }
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
120 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
121 false
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
122 }
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
123 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
124 true
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
125 }
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
126 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
127 VisitChildrenSet::Recursive
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
128 }
43611
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
129 fn matches_everything(&self) -> bool {
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
130 true
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
131 }
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
132 fn is_exact(&self) -> bool {
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
133 false
27c25c0dc967 rust-matchers: remove default implementations for `Matcher` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43438
diff changeset
134 }
43438
a77d4fe347a4 rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
135 }
43914
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
136
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
137 /// 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
138 /// patterns.
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
139 ///
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
140 ///```
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
141 /// 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
142 ///
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
143 /// let files = [HgPathBuf::from_bytes(b"a.txt"), HgPathBuf::from_bytes(br"re:.*\.c$")];
43914
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
144 /// let matcher = FileMatcher::new(&files).unwrap();
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
145 ///
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
146 /// 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
147 /// 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
148 /// 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
149 /// 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
150 /// ```
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
151 #[derive(Debug)]
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
152 pub struct FileMatcher<'a> {
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
153 files: HashSet<&'a HgPath>,
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
154 dirs: DirsMultiset,
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
155 }
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
156
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
157 impl<'a> FileMatcher<'a> {
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
158 pub fn new(files: &'a [HgPathBuf]) -> Result<Self, DirstateMapError> {
43914
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
159 Ok(Self {
44973
26114bd6ec60 rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44870
diff changeset
160 files: HashSet::from_iter(files.iter().map(AsRef::as_ref)),
43914
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
161 dirs: DirsMultiset::from_manifest(files)?,
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
162 })
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
163 }
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
164 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
165 self.files.contains(filename.as_ref())
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 }
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
168
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
169 impl<'a> Matcher for FileMatcher<'a> {
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
170 fn file_set(&self) -> Option<&HashSet<&HgPath>> {
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
171 Some(&self.files)
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
172 }
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
173 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
174 self.inner_matches(filename)
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
175 }
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
176 fn matches(&self, filename: &HgPath) -> bool {
43914
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
177 self.inner_matches(filename)
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
178 }
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
179 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
180 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
181 return VisitChildrenSet::Empty;
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
182 }
44973
26114bd6ec60 rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44870
diff changeset
183 let dirs_as_set = self.dirs.iter().map(Deref::deref).collect();
44353
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
184
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
185 let mut candidates: HashSet<&HgPath> =
44973
26114bd6ec60 rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44870
diff changeset
186 self.files.union(&dirs_as_set).cloned().collect();
44353
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
187 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
188
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
189 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
190 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
191 candidates = candidates
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
192 .iter()
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
193 .filter_map(|c| {
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
194 if c.as_bytes().starts_with(&directory) {
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
195 Some(HgPath::new(&c.as_bytes()[directory.len()..]))
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
196 } else {
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
197 None
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
198 }
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
199 })
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
200 .collect();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
201 }
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
202
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
203 // `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
204 // 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
205 // '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
206 // '/' 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
207 // 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
208 VisitChildrenSet::Set(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
209 candidates
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
210 .iter()
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
211 .filter_map(|c| {
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
212 if c.bytes().all(|b| *b != b'/') {
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
213 Some(*c)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
214 } else {
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
215 None
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
216 }
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
217 })
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
218 .collect(),
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
219 )
43914
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
220 }
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
221 fn matches_everything(&self) -> bool {
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
222 false
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
223 }
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
224 fn is_exact(&self) -> bool {
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
225 true
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
226 }
69c4f3cf2cdf rust-matchers: add `FileMatcher` implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43863
diff changeset
227 }
44519
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44353
diff changeset
228
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
229 /// 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
230 /// ```
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
231 /// use hg::{
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
232 /// matchers::{IncludeMatcher, Matcher},
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
233 /// IgnorePattern,
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
234 /// PatternSyntax,
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
235 /// utils::hg_path::HgPath
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
236 /// };
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
237 /// use std::path::Path;
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
238 /// ///
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
239 /// let ignore_patterns =
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
240 /// 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
241 /// 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
242 /// ///
9f96beb9bafe rust: remove support for `re2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44852
diff changeset
243 /// 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
244 /// 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
245 /// 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
246 /// 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
247 /// ```
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
248 pub struct IncludeMatcher<'a> {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
249 patterns: Vec<u8>,
48354
2009e3c64a53 rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48311
diff changeset
250 match_fn: IgnoreFnType<'a>,
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
251 /// 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
252 prefix: bool,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
253 roots: HashSet<HgPathBuf>,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
254 dirs: HashSet<HgPathBuf>,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
255 parents: HashSet<HgPathBuf>,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
256 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
257
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
258 impl<'a> Matcher for IncludeMatcher<'a> {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
259 fn file_set(&self) -> Option<&HashSet<&HgPath>> {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
260 None
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
261 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
262
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
263 fn exact_match(&self, _filename: &HgPath) -> bool {
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
264 false
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
265 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
266
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
267 fn matches(&self, filename: &HgPath) -> bool {
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
268 (self.match_fn)(filename.as_ref())
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
269 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
270
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
271 fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet {
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
272 let dir = directory.as_ref();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
273 if self.prefix && self.roots.contains(dir) {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
274 return VisitChildrenSet::Recursive;
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
275 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
276 if self.roots.contains(HgPath::new(b""))
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
277 || self.roots.contains(dir)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
278 || self.dirs.contains(dir)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
279 || 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
280 {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
281 return VisitChildrenSet::This;
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
282 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
283
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
284 if self.parents.contains(directory.as_ref()) {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
285 let multiset = self.get_all_parents_children();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
286 if let Some(children) = multiset.get(dir) {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
287 return VisitChildrenSet::Set(children.to_owned());
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
288 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
289 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
290 VisitChildrenSet::Empty
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
291 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
292
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
293 fn matches_everything(&self) -> bool {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
294 false
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
295 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
296
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
297 fn is_exact(&self) -> bool {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
298 false
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
299 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
300 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
301
44593
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
302 /// 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
303 /// pattern.
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
304 ///
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
305 /// 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
306 /// 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
307 /// back-references.
44784
83c97c0bd319 rust-matchers: add timing tracing to regex compilation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44597
diff changeset
308 #[timed]
44593
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
309 fn re_matcher(
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
310 pattern: &[u8],
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
311 ) -> PatternResult<impl Fn(&HgPath) -> bool + Sync> {
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
312 use std::io::Write;
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
313
44832
ad1ec40975aa rust-regex: fix issues with regex anchoring and performance
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44803
diff changeset
314 // 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
315 // 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
316 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
317 for byte in pattern {
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
318 if *byte > 127 {
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
319 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
320 } else {
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
321 escaped_bytes.push(*byte);
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
322 }
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
323 }
44832
ad1ec40975aa rust-regex: fix issues with regex anchoring and performance
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44803
diff changeset
324 escaped_bytes.push(b')');
44593
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
325
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
326 // Avoid the cost of UTF8 checking
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
327 //
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
328 // # Safety
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
329 // 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
330 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
331 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
332 .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
333 // 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
334 // 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
335 // 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
336 .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
337 .build()
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
338 .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
339
496868f1030c rust-matchers: use the `regex` crate
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44541
diff changeset
340 Ok(move |path: &HgPath| re.is_match(path.as_bytes()))
44519
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44353
diff changeset
341 }
52d40f8fb82d rust-matchers: add function to generate a regex matcher function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44353
diff changeset
342
44521
a21881b40942 rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44520
diff changeset
343 /// 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
344 /// 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
345 fn build_regex_match<'a, 'b>(
2009e3c64a53 rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48311
diff changeset
346 ignore_patterns: &'a [IgnorePattern],
2009e3c64a53 rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48311
diff changeset
347 ) -> 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
348 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
349 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
350
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
351 for pattern in ignore_patterns {
e0414fcd35e0 rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44784
diff changeset
352 if let Some(re) = build_single_regex(pattern)? {
e0414fcd35e0 rust-filepatterns: match exact `rootglob`s with a `HashSet`, not in the regex
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44784
diff changeset
353 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
354 } 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
355 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
356 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
357 }
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
358 }
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
359
44521
a21881b40942 rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44520
diff changeset
360 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
361
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
362 // 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
363 // (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
364 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
365 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
366 let func = move |filename: &HgPath| {
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
367 exact_set.contains(filename) || matcher(filename)
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
368 };
48354
2009e3c64a53 rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48311
diff changeset
369 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
370 } 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
371 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
372 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
373 };
44521
a21881b40942 rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44520
diff changeset
374
a21881b40942 rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44520
diff changeset
375 Ok((full_regex, func))
a21881b40942 rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44520
diff changeset
376 }
a21881b40942 rust-matchers: add `build_regex_match` function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44520
diff changeset
377
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
378 /// 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
379 ///
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
380 /// 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
381 /// 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
382 /// 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
383 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
384 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
385 ) -> (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
386 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
387 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
388
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
389 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
390 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
391 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
392 } = 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
393 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
394 PatternSyntax::RootGlob | PatternSyntax::Glob => {
48311
6d69e83e6b6e rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 47409
diff changeset
395 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
396 for p in pattern.split(|c| *c == b'/') {
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
397 if p.iter().any(|c| match *c {
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
398 b'[' | b'{' | b'*' | b'?' => true,
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
399 _ => false,
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
400 }) {
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
401 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
402 }
48311
6d69e83e6b6e rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 47409
diff changeset
403 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
404 }
48311
6d69e83e6b6e rhg: more efficient `HgPath::join`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 47409
diff changeset
405 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
406 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
407 PatternSyntax::Path | PatternSyntax::RelPath => {
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
408 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
409 &[] 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
410 } 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
411 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
412 });
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
413 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
414 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
415 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
416 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
417 &[] 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
418 } 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
419 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
420 };
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
421 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
422 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
423 _ => {
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
424 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
425 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
426 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
427 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
428 (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
429 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
430
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
431 /// 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
432 #[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
433 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
434 /// 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
435 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
436 /// 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
437 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
438 /// 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
439 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
440 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
441
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
442 /// 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
443 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
444 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
445 ) -> 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
446 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
447
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
448 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
449
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
450 parents.extend(
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
451 DirsMultiset::from_manifest(&dirs)
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
452 .map_err(|e| match e {
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
453 DirstateMapError::InvalidPath(e) => e,
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
454 _ => unreachable!(),
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
455 })?
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
456 .iter()
44973
26114bd6ec60 rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44870
diff changeset
457 .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
458 );
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
459 parents.extend(
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
460 DirsMultiset::from_manifest(&roots)
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
461 .map_err(|e| match e {
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
462 DirstateMapError::InvalidPath(e) => e,
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
463 _ => unreachable!(),
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
464 })?
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
465 .iter()
44973
26114bd6ec60 rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44870
diff changeset
466 .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
467 );
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
468
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
469 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
470 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
471 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
472 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
473 })
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
474 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
475
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
476 /// 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
477 /// should be matched.
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
478 fn build_match<'a, 'b>(
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
479 ignore_patterns: Vec<IgnorePattern>,
48354
2009e3c64a53 rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48311
diff changeset
480 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'b>)> {
2009e3c64a53 rhg: refactor to use IgnoreFnType alias more widely
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48311
diff changeset
481 let mut match_funcs: Vec<IgnoreFnType<'b>> = vec![];
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
482 // For debugging and printing
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
483 let mut patterns = vec![];
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
484
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
485 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
486
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
487 if !subincludes.is_empty() {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
488 // Build prefix-based matcher functions for subincludes
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
489 let mut submatchers = FastHashMap::default();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
490 let mut prefixes = vec![];
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
491
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
492 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
493 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
494 let match_fn =
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
495 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
496 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
497 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
498 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
499
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
500 let match_subinclude = move |filename: &HgPath| {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
501 for prefix in prefixes.iter() {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
502 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
503 if (submatchers[prefix])(rel) {
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
504 return true;
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
505 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
506 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
507 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
508 false
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
509 };
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
510
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
511 match_funcs.push(Box::new(match_subinclude));
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
512 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
513
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
514 if !ignore_patterns.is_empty() {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
515 // 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
516 // with a regex.
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
517 if ignore_patterns
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
518 .iter()
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
519 .all(|k| k.syntax == PatternSyntax::RootFiles)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
520 {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
521 let dirs: HashSet<_> = ignore_patterns
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
522 .iter()
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
523 .map(|k| k.pattern.to_owned())
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
524 .collect();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
525 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
526
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
527 let match_func = move |path: &HgPath| -> bool {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
528 let path = path.as_bytes();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
529 let i = path.iter().rfind(|a| **a == b'/');
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
530 let dir = if let Some(i) = i {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
531 &path[..*i as usize]
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
532 } else {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
533 b"."
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
534 };
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
535 dirs.contains(dir.deref())
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
536 };
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
537 match_funcs.push(Box::new(match_func));
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
538
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
539 patterns.extend(b"rootfilesin: ");
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
540 dirs_vec.sort();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
541 patterns.extend(dirs_vec.escaped_bytes());
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
542 } else {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
543 let (new_re, match_func) = build_regex_match(&ignore_patterns)?;
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
544 patterns = new_re;
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
545 match_funcs.push(match_func)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
546 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
547 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
548
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
549 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
550 (patterns, match_funcs.remove(0))
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
551 } else {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
552 (
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
553 patterns,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
554 Box::new(move |f: &HgPath| -> bool {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
555 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
556 }),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
557 )
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
558 })
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
559 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
560
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
561 /// 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
562 /// 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
563 /// ignored.
48355
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
564 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
565 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
566 root_dir: &Path,
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47379
diff changeset
567 inspect_pattern_bytes: &mut impl FnMut(&[u8]),
48355
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
568 ) -> PatternResult<(IncludeMatcher<'a>, Vec<PatternFileWarning>)> {
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
569 let mut all_patterns = vec![];
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
570 let mut all_warnings = vec![];
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
571
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47379
diff changeset
572 // 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
573 // 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
574 // 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
575 // 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
576 // (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
577 all_pattern_files
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47379
diff changeset
578 .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
579
47378
777c3d231913 rust: Make some file path parameters less generic
Simon Sapin <simon.sapin@octobus.net>
parents: 45607
diff changeset
580 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
581 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
582 pattern_file,
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47379
diff changeset
583 root_dir,
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47379
diff changeset
584 inspect_pattern_bytes,
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47379
diff changeset
585 )?;
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
586
44597
e62052d0f377 rust-status: only involve ignore mechanism when needed
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44593
diff changeset
587 all_patterns.extend(patterns.to_owned());
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
588 all_warnings.extend(warnings);
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
589 }
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
590 let matcher = IncludeMatcher::new(all_patterns)?;
48355
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
591 Ok((matcher, all_warnings))
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
592 }
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
593
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
594 /// 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
595 /// 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
596 /// ignored.
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
597 pub fn get_ignore_function<'a>(
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
598 all_pattern_files: Vec<PathBuf>,
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
599 root_dir: &Path,
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
600 inspect_pattern_bytes: &mut impl FnMut(&[u8]),
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
601 ) -> PatternResult<(IgnoreFnType<'a>, Vec<PatternFileWarning>)> {
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
602 let res =
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
603 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
604 res.map(|(matcher, all_warnings)| {
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
605 let res: IgnoreFnType<'a> =
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
606 Box::new(move |path: &HgPath| matcher.matches(path));
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
607
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
608 (res, all_warnings)
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
609 })
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
610 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
611
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
612 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
613 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
614 let RootsDirsAndParents {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
615 roots,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
616 dirs,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
617 parents,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
618 } = roots_dirs_and_parents(&ignore_patterns)?;
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
619 let prefix = ignore_patterns.iter().any(|k| match k.syntax {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
620 PatternSyntax::Path | PatternSyntax::RelPath => true,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
621 _ => false,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
622 });
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
623 let (patterns, match_fn) = build_match(ignore_patterns)?;
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
624
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
625 Ok(Self {
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
626 patterns,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
627 match_fn,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
628 prefix,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
629 roots,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
630 dirs,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
631 parents,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
632 })
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
633 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
634
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
635 fn get_all_parents_children(&self) -> DirsChildrenMultiset {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
636 // TODO cache
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
637 let thing = self
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
638 .dirs
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
639 .iter()
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
640 .chain(self.roots.iter())
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
641 .chain(self.parents.iter());
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
642 DirsChildrenMultiset::new(thing, Some(&self.parents))
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
643 }
48355
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
644
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
645 pub fn debug_get_patterns(&self) -> &[u8] {
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
646 self.patterns.as_ref()
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48354
diff changeset
647 }
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
648 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
649
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
650 impl<'a> Display for IncludeMatcher<'a> {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
651 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
652 // 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
653 // 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
654 // 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
655 // 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
656 // 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
657 // (on purpose) missing from the `includes`.
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
658 write!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
659 f,
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
660 "IncludeMatcher(includes='{}')",
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
661 String::from_utf8_lossy(&self.patterns.escaped_bytes())
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
662 )
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
663 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
664 }
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
665
44353
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
666 #[cfg(test)]
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
667 mod tests {
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
668 use super::*;
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
669 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
670 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
671
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
672 #[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
673 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
674 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
675 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
676 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
677 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
678 ];
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
679 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
680
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
681 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
682 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
683 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
684 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
685 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
686 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
687 ),
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
688 );
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
689 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
690 }
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
691
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
692 #[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
693 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
694 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
695 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
696 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
697 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
698 ];
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
699
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
700 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
701 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
702 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
703
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
704 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
705
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
706 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
707 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
708 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
709
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
710 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
711 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
712 RootsDirsAndParents {
483fce658e43 rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44522
diff changeset
713 roots,
483fce658e43 rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44522
diff changeset
714 dirs,
483fce658e43 rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44522
diff changeset
715 parents
483fce658e43 rust-status: refactor options into a `StatusOptions` struct
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44522
diff changeset
716 }
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
717 );
d4e8cfcde012 rust-matchers: add functions to get roots, dirs and parents from patterns
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44519
diff changeset
718 }
44353
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
719
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
720 #[test]
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
721 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
722 // Visitchildrenset
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
723 let files = vec![HgPathBuf::from_bytes(b"dir/subdir/foo.txt")];
44353
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
724 let matcher = FileMatcher::new(&files).unwrap();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
725
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
726 let mut set = HashSet::new();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
727 set.insert(HgPath::new(b"dir"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
728 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
729 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
730 VisitChildrenSet::Set(set)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
731 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
732
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
733 let mut set = HashSet::new();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
734 set.insert(HgPath::new(b"subdir"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
735 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
736 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
737 VisitChildrenSet::Set(set)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
738 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
739
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
740 let mut set = HashSet::new();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
741 set.insert(HgPath::new(b"foo.txt"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
742 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
743 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
744 VisitChildrenSet::Set(set)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
745 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
746
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
747 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
748 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
749 VisitChildrenSet::Empty
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
750 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
751 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
752 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
753 VisitChildrenSet::Empty
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
754 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
755 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
756 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
757 VisitChildrenSet::Empty
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
758 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
759 }
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
760
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
761 #[test]
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
762 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
763 let files = vec![
45607
75f785888a7b rust-matchers: make `Matcher` trait object-safe
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44973
diff changeset
764 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
765 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
766 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
767 // 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
768 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
769 ];
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
770 let matcher = FileMatcher::new(&files).unwrap();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
771
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
772 let mut set = HashSet::new();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
773 set.insert(HgPath::new(b"a"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
774 set.insert(HgPath::new(b"rootfile.txt"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
775 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
776 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
777 VisitChildrenSet::Set(set)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
778 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
779
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
780 let mut set = HashSet::new();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
781 set.insert(HgPath::new(b"b"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
782 set.insert(HgPath::new(b"file1.txt"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
783 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
784 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
785 VisitChildrenSet::Set(set)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
786 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
787
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
788 let mut set = HashSet::new();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
789 set.insert(HgPath::new(b"c"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
790 set.insert(HgPath::new(b"file2.txt"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
791 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
792 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
793 VisitChildrenSet::Set(set)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
794 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
795
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
796 let mut set = HashSet::new();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
797 set.insert(HgPath::new(b"d"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
798 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
799 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
800 VisitChildrenSet::Set(set)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
801 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
802 let mut set = HashSet::new();
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
803 set.insert(HgPath::new(b"file4.txt"));
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
804 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
805 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
806 VisitChildrenSet::Set(set)
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
807 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
808
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
809 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
810 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
811 VisitChildrenSet::Empty
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
812 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
813 assert_eq!(
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
814 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
815 VisitChildrenSet::Empty
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
816 );
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
817 }
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
818
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
819 #[test]
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
820 fn test_includematcher() {
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
821 // VisitchildrensetPrefix
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
822 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
823 PatternSyntax::RelPath,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
824 b"dir/subdir",
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
825 Path::new(""),
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
826 )])
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
827 .unwrap();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
828
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
829 let mut set = HashSet::new();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
830 set.insert(HgPath::new(b"dir"));
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
831 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
832 matcher.visit_children_set(HgPath::new(b"")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
833 VisitChildrenSet::Set(set)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
834 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
835
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
836 let mut set = HashSet::new();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
837 set.insert(HgPath::new(b"subdir"));
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
838 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
839 matcher.visit_children_set(HgPath::new(b"dir")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
840 VisitChildrenSet::Set(set)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
841 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
842 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
843 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
844 VisitChildrenSet::Recursive
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
845 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
846 // 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
847 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
848 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
849 VisitChildrenSet::This
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
850 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
851 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
852 matcher.visit_children_set(HgPath::new(b"folder")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
853 VisitChildrenSet::Empty
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
854 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
855
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
856 // VisitchildrensetRootfilesin
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
857 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
858 PatternSyntax::RootFiles,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
859 b"dir/subdir",
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
860 Path::new(""),
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
861 )])
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
862 .unwrap();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
863
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
864 let mut set = HashSet::new();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
865 set.insert(HgPath::new(b"dir"));
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
866 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
867 matcher.visit_children_set(HgPath::new(b"")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
868 VisitChildrenSet::Set(set)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
869 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
870
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
871 let mut set = HashSet::new();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
872 set.insert(HgPath::new(b"subdir"));
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
873 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
874 matcher.visit_children_set(HgPath::new(b"dir")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
875 VisitChildrenSet::Set(set)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
876 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
877
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
878 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
879 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
880 VisitChildrenSet::This
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
881 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
882 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
883 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
884 VisitChildrenSet::Empty
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
885 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
886 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
887 matcher.visit_children_set(HgPath::new(b"folder")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
888 VisitChildrenSet::Empty
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
889 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
890
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
891 // VisitchildrensetGlob
47379
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
892 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
893 PatternSyntax::Glob,
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
894 b"dir/z*",
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
895 Path::new(""),
f6bb181c75f8 rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents: 47378
diff changeset
896 )])
44522
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
897 .unwrap();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
898
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
899 let mut set = HashSet::new();
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
900 set.insert(HgPath::new(b"dir"));
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
901 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
902 matcher.visit_children_set(HgPath::new(b"")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
903 VisitChildrenSet::Set(set)
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
904 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
905 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
906 matcher.visit_children_set(HgPath::new(b"folder")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
907 VisitChildrenSet::Empty
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
908 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
909 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
910 matcher.visit_children_set(HgPath::new(b"dir")),
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
911 VisitChildrenSet::This
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
912 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
913 // OPT: these should probably be set().
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
914 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
915 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
916 VisitChildrenSet::This
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
917 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
918 assert_eq!(
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
919 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
920 VisitChildrenSet::This
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
921 );
c697638e0e91 rust-matchers: add `IgnoreMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44521
diff changeset
922 }
44353
54d185eb24b5 rust-matchers: implement `visit_children_set` for `FileMatcher`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44006
diff changeset
923 }