Skip to content

Commit 1eac372

Browse files
committed
feat: add Search::pop_pattern_list().
Also, improve method documentation.
1 parent 27157ae commit 1eac372

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

gix-attributes/src/search/attributes.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ use crate::{
1111

1212
/// Instantiation and initialization.
1313
impl Search {
14-
/// Create a search instance preloaded with *built-ins* as well as attribute `files` from various global locations.
14+
/// Create a search instance preloaded with *built-ins* followed by attribute `files` from various global locations.
15+
///
1516
/// See [`Source`][crate::Source] for a way to obtain these paths.
17+
///
1618
/// Note that parsing is lenient and errors are logged.
17-
/// `buf` is used to read `files` from disk which will be ignored if they do not exist.
18-
/// `collection` will be updated with information necessary to perform lookups later.
19+
///
20+
/// * `buf` is used to read `files` from disk which will be ignored if they do not exist.
21+
/// * `collection` will be updated with information necessary to perform lookups later.
1922
pub fn new_globals(
2023
files: impl IntoIterator<Item = impl Into<PathBuf>>,
2124
buf: &mut Vec<u8>,
@@ -36,7 +39,7 @@ impl Search {
3639
/// Add the given file at `source` to our patterns if it exists, otherwise do nothing.
3740
/// Update `collection` with newly added attribute names.
3841
/// If a `root` is provided, it's not considered a global file anymore.
39-
/// Returns true if the file was added, or false if it didn't exist.
42+
/// Returns `true` if the file was added, or `false` if it didn't exist.
4043
pub fn add_patterns_file(
4144
&mut self,
4245
source: impl Into<PathBuf>,
@@ -63,12 +66,17 @@ impl Search {
6366
self.patterns.push(pattern::List::from_bytes(bytes, source, root));
6467
collection.update_from_list(self.patterns.last_mut().expect("just added"));
6568
}
69+
70+
/// Pop the last attribute patterns list from our queue.
71+
pub fn pop_pattern_list(&mut self) -> Option<gix_glob::search::pattern::List<Attributes>> {
72+
self.patterns.pop()
73+
}
6674
}
6775

6876
/// Access and matching
6977
impl Search {
7078
/// Match `relative_path`, a path relative to the repository, while respective `case`-sensitivity and write them to `out`
71-
/// Return true if at least one pattern matched.
79+
/// Return `true` if at least one pattern matched.
7280
pub fn pattern_matching_relative_path<'a, 'b>(
7381
&'a self,
7482
relative_path: impl Into<&'b BStr>,

gix-attributes/src/search/outcome.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
/// Initialization
1616
impl<'pattern> Outcome<'pattern> {
1717
/// Initialize this instance to collect outcomes for all names in `collection`, which represents all possible attributes
18-
/// or macros we may visit.
18+
/// or macros we may visit, and [`reset`][Self::reset()] it unconditionally.
1919
///
2020
/// This must be called after each time `collection` changes.
2121
pub fn initialize(&mut self, collection: &MetadataCollection) {
@@ -125,6 +125,11 @@ impl<'pattern> Outcome<'pattern> {
125125
pub fn match_by_id(&self, id: AttributeId) -> Option<&Match<'pattern>> {
126126
self.matches_by_id.get(id.0).and_then(|m| m.r#match.as_ref())
127127
}
128+
129+
/// Return `true` if there is nothing more to be done as all attributes were filled.
130+
pub fn is_done(&self) -> bool {
131+
self.remaining() == 0
132+
}
128133
}
129134

130135
/// Mutation
@@ -201,11 +206,6 @@ impl<'attr> Outcome<'attr> {
201206
.expect("BUG: instance must be initialized for each search set")
202207
}
203208

204-
/// Return true if there is nothing more to be done as all attributes were filled.
205-
pub(crate) fn is_done(&self) -> bool {
206-
self.remaining() == 0
207-
}
208-
209209
fn reduce_and_check_if_done(&mut self, attr: AttributeId) -> bool {
210210
if self.selected.is_empty()
211211
|| self

gix-attributes/tests/search/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ fn assignments<'a>(
258258

259259
mod baseline {
260260
use bstr::{BStr, ByteSlice};
261+
use gix_attributes::{search::MetadataCollection, AssignmentRef, StateRef};
262+
use std::path::PathBuf;
261263

262264
/// Read user-attributes and baseline in one go.
263265
pub fn user_attributes_named_baseline(
@@ -274,9 +276,6 @@ mod baseline {
274276

275277
Ok((group, collection, base, input))
276278
}
277-
use std::path::PathBuf;
278-
279-
use gix_attributes::{search::MetadataCollection, AssignmentRef, StateRef};
280279

281280
/// Read user-attributes and baseline in one go.
282281
pub fn user_attributes(

0 commit comments

Comments
 (0)