Struct gix::Pathspec

source ·
pub struct Pathspec<'repo> { /* private fields */ }
Available on crate feature 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>

Lifecycle

source

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.

source

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.

source

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>

Access

source

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.

source

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.

source

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.

source

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.

source

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§

source§

impl<'repo> Clone for Pathspec<'repo>

source§

fn clone(&self) -> Pathspec<'repo>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.