pub struct Pathspec<'repo> { /* private fields */ }
attributes
only.Expand description
A utility to make matching against pathspecs simple.
Note that to perform pathspec matching, attribute access might need to be provided. For that, we use our own and argue that the implementation is only going to incur costs for it when a pathspec matches and has attributes. Should this potential duplication of effort to maintain attribute state be unacceptable, the user may fall back to the underlying plumbing.
Implementations§
source§impl<'repo> Pathspec<'repo>
impl<'repo> Pathspec<'repo>
Lifecycle
sourcepub fn new(
repo: &'repo Repository,
empty_patterns_match_prefix: bool,
patterns: impl IntoIterator<Item = impl AsRef<BStr>>,
inherit_ignore_case: bool,
make_attributes: impl FnOnce() -> Result<Stack, Box<dyn Error + Send + Sync + 'static>>,
) -> Result<Self, Error>
pub fn new( repo: &'repo Repository, empty_patterns_match_prefix: bool, patterns: impl IntoIterator<Item = impl AsRef<BStr>>, inherit_ignore_case: bool, make_attributes: impl FnOnce() -> Result<Stack, Box<dyn Error + Send + Sync + 'static>>, ) -> Result<Self, Error>
Create a new instance by parsing patterns
into Pathspecs
to make them usable for searches.
make_attribute
may be called if one of the patterns has a (attr:a)
element which requires attribute matching. It should
be used to control where attributes are coming from.
If inherit_ignore_case
is true
, the pathspecs may have their ignore-case default overridden to be case-insensitive by default.
This only works towards turning ignore-case for pathspecs on, but won’t ever turn that setting off if.
If empty_patterns_match_prefix
is true
, then even empty patterns will match only what’s inside of the prefix. Otherwise
they will match everything.
§Deviation
Pathspecs can declare to be case-insensitive as part of their elements, which is a setting that is now respected for attribute queries as well.
sourcepub fn into_parts(self) -> (Search, Option<AttributeStack<'repo>>)
pub fn into_parts(self) -> (Search, Option<AttributeStack<'repo>>)
Turn ourselves into the functional parts for direct usage.
Note that the cache
is only set if one of the search
patterns
is specifying attributes to match for.
sourcepub fn detach(self) -> Result<PathspecDetached>
pub fn detach(self) -> Result<PathspecDetached>
Turn ourselves into an implementation that works without a repository instance and that is rather minimal.
source§impl<'repo> Pathspec<'repo>
impl<'repo> Pathspec<'repo>
Access
sourcepub fn attributes(&self) -> Option<&Stack>
pub fn attributes(&self) -> Option<&Stack>
Return the attributes cache which is used when matching attributes in pathspecs, or None
if none of the pathspecs require that.
sourcepub fn search(&self) -> &Search
pub fn search(&self) -> &Search
Return the search itself which can be used for matching paths or accessing the actual patterns that will be used.
sourcepub fn pattern_matching_relative_path<'a>(
&mut self,
relative_path: impl Into<&'a BStr>,
is_dir: Option<bool>,
) -> Option<Match<'_>>
pub fn pattern_matching_relative_path<'a>( &mut self, relative_path: impl Into<&'a BStr>, is_dir: Option<bool>, ) -> Option<Match<'_>>
Return the first Match
of relative_path
, or None
.
Note that the match might be excluded.
is_dir
is true if relative_path
is a directory.
sourcepub fn is_included<'a>(
&mut self,
relative_path: impl Into<&'a BStr>,
is_dir: Option<bool>,
) -> bool
pub fn is_included<'a>( &mut self, relative_path: impl Into<&'a BStr>, is_dir: Option<bool>, ) -> bool
The simplified version of pattern_matching_relative_path()
which returns
true
if relative_path
is included in the set of positive pathspecs, while not being excluded.
sourcepub fn index_entries_with_paths<'s: 'repo, 'a: 'repo>(
&'s mut self,
index: &'a State,
) -> Option<impl Iterator<Item = (&'a BStr, &'a Entry)> + 'repo + 's>
pub fn index_entries_with_paths<'s: 'repo, 'a: 'repo>( &'s mut self, index: &'a State, ) -> Option<impl Iterator<Item = (&'a BStr, &'a Entry)> + 'repo + 's>
Return an iterator over all entries along with their path if the path matches the pathspec, or None
if the pathspec is
known to match no entry.
Trait Implementations§
Auto Trait Implementations§
impl<'repo> Freeze for Pathspec<'repo>
impl<'repo> !RefUnwindSafe for Pathspec<'repo>
impl<'repo> !Send for Pathspec<'repo>
impl<'repo> !Sync for Pathspec<'repo>
impl<'repo> Unpin for Pathspec<'repo>
impl<'repo> !UnwindSafe for Pathspec<'repo>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)