1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//! Parse [path specifications](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) and
//! see if a path matches.
//!
//! ## Examples
//!
//! ```
//! # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! use std::path::Path;
//!
//! fn no_attrs(
//! _path: &bstr::BStr,
//! _case: gix_pathspec::attributes::glob::pattern::Case,
//! _is_dir: bool,
//! _out: &mut gix_pathspec::attributes::search::Outcome,
//! ) -> bool {
//! false
//! }
//!
//! let specs = ["src/**", ":!src/generated/**"]
//! .into_iter()
//! .map(|spec| gix_pathspec::parse(spec.as_bytes(), Default::default()).unwrap());
//! let mut search = gix_pathspec::Search::from_specs(specs, None, Path::new(""))?;
//!
//! assert!(search.can_match_relative_path("src".into(), Some(true)));
//!
//! let matched = search
//! .pattern_matching_relative_path("src/lib.rs".into(), Some(false), &mut no_attrs)
//! .unwrap();
//! assert_eq!(matched.pattern.path(), "src/**");
//! assert!(!matched.pattern.is_excluded());
//!
//! let excluded = search
//! .pattern_matching_relative_path("src/generated/lib.rs".into(), Some(false), &mut no_attrs)
//! .unwrap();
//! assert_eq!(excluded.pattern.to_bstring(), ":(exclude)src/generated/**");
//! assert!(excluded.pattern.is_excluded());
//! # Ok(()) }
//! ```
use Result;
use PathBuf;
use bitflags;
use BString;
/// `gix-glob` types are available through [`attributes::glob`].
pub use gix_attributes as attributes;
///
///
/// Default settings for some fields of a [`Pattern`].
///
/// These can be used to represent `GIT_*_PATHSPECS` environment variables, for example.
///
/// A lists of pathspec patterns, possibly from a file.
///
/// Pathspecs are generally relative to the root of the repository.
/// The output of a pathspec [parsing][parse()] operation. It can be used to match against a one or more paths.
bitflags!
/// Parts of [magic signatures][MagicSignature] which don't stack as they all configure
/// the way path specs are matched.
/// Parse a git-style pathspec into a [`Pattern`],
/// setting the given `default` values in case these aren't specified in `input`.
///
/// Note that empty [paths](Pattern::path) are allowed here, and generally some processing has to be performed.