Struct gix_pathspec::Search

source ·
pub struct Search {
    pub source: Option<PathBuf>,
    /* private fields */
}
Expand description

A lists of pathspec patterns, possibly from a file.

Pathspecs are generally relative to the root of the repository.

Fields§

§source: Option<PathBuf>

The path from which the patterns were read, or None if the patterns don’t originate in a file on disk.

Implementations§

Lifecycle

source

pub fn from_specs( pathspecs: impl IntoIterator<Item = Pattern>, prefix: Option<&Path>, root: &Path ) -> Result<Self, Error>

Create a search from ready-made pathspecs, and normalize them with prefix and root. root is the absolute path to the worktree root, if available, or the git_dir in case of bare repositories. If pathspecs doesn’t yield any pattern, we will match everything automatically. If prefix is also provided and not empty, an artificial pattern will be added to yield all.

source

pub fn into_patterns(self) -> impl Iterator<Item = Pattern>

Obtain ownership of the normalized pathspec patterns that were used for the search.

source§

impl Search

source

pub fn pattern_matching_relative_path( &mut self, relative_path: &BStr, is_dir: Option<bool>, attributes: &mut dyn FnMut(&BStr, Case, bool, &mut Outcome) -> bool ) -> Option<Match<'_>>

Return the first Match of relative_path, or None. is_dir is true if relative_path is a directory. attributes is called as attributes(relative_path, case, is_dir, outcome) -> has_match to obtain for attributes for relative_path, if the underlying pathspec defined an attribute filter, to be stored in outcome, returning true if there was a match. All attributes of the pathspec have to be present in the defined value for the pathspec to match.

Note that relative_path is expected to be starting at the same root as is assumed for this pattern, see Pattern::normalize(). Further, empty searches match everything, as if : was provided.

Deviation

The case-sensivity of the attribute match is controlled by the sensitivity of the pathspec, instead of being based on the case folding settings of the repository. That way we assure that the matching is consistent. Higher-level crates should control this default case folding of pathspecs when instantiating them, which is when they can set it to match the repository setting for more natural behaviour when, for instance, adding files to a repository: as it stands, on a case-insensitive file system, touch File && git add file will not add the file, but also not error.

source§

impl Search

Access

source

pub fn patterns(&self) -> impl Iterator<Item = &Pattern> + '_

Return an iterator over the patterns that participate in the search.

source

pub fn common_prefix(&self) -> &BStr

Return the portion of the prefix among all of the pathspecs involved in this search, or an empty string if there is none. It doesn’t have to end at a directory boundary though, nor does it denote a directory.

Note that the common_prefix is always matched case-sensitively, and it is useful to skip large portions of input. Further, excluded pathspecs don’t participate which makes this common prefix inclusive. To work correctly though, one will have to additionally match paths that have the common prefix with that pathspec itself to assure it is not excluded.

Trait Implementations§

source§

fn clone(&self) -> Search

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
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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> 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.