Struct gix_pathspec::Pattern

source ·
pub struct Pattern {
    pub signature: MagicSignature,
    pub search_mode: SearchMode,
    pub attributes: Vec<Assignment>,
    /* private fields */
}
Expand description

The output of a pathspec parsing operation. It can be used to match against a one or more paths.

Fields§

§signature: MagicSignature

All magic signatures that were included in the pathspec.

§search_mode: SearchMode

The search mode of the pathspec.

§attributes: Vec<Assignment>

All attributes that were included in the ATTR part of the pathspec, if present.

:(attr:a=one b=):path would yield attribute a and b.

Implementations§

source§

impl Pattern

Access

source

pub fn is_nil(&self) -> bool

Returns true if this seems to be a pathspec that indicates that ‘there is no pathspec’.

Note that such a spec is :.

source

pub fn prefix_directory(&self) -> &BStr

Return the prefix-portion of the path of this spec, which is a directory. It can be empty if there is no prefix.

A prefix is effectively the CWD seen as relative to the working tree, and it’s assumed to match case-sensitively. This makes it useful for skipping over large portions of input by directly comparing them.

source

pub fn path(&self) -> &BStr

Return the path of this spec, typically used for matching.

source§

impl Pattern

Mutation

source

pub fn normalize( &mut self, prefix: &Path, root: &Path, ) -> Result<&mut Self, Error>

Normalize the pattern’s path by assuring it’s relative to the root of the working tree, and contains no relative path components. Further, it assures that / are used as path separator.

If self.path is a relative path, it will be put in front of the pattern path if self.signature isn’t indicating TOP already. If self.path is an absolute path, we will use root to make it worktree relative if possible.

prefix can be empty, we will still normalize this pathspec to resolve relative path components, and it is assumed not to contain any relative path components, e.g. ‘’, ‘a’, ‘a/b’ are valid. root is the absolute path to the root of either the worktree or the repository’s git_dir.

source§

impl Pattern

Access

source

pub fn is_excluded(&self) -> bool

Return true if this pathspec is negated, which means it will exclude an item from the result set instead of including it.

source

pub fn always_matches(&self) -> bool

Returns true is this pattern is supposed to always match, as it’s either empty or designated nil. Note that technically the pattern might still be excluded.

source

pub fn to_bstring(&self) -> BString

Translate ourselves to a long display format, that when parsed back will yield the same pattern.

Note that the

source§

impl Pattern

source

pub fn from_bytes(input: &[u8], _: Defaults) -> Result<Self, Error>

Try to parse a path-spec pattern from the given input bytes.

source

pub fn from_literal(input: &[u8], default_signature: MagicSignature) -> Self

Take input literally without parsing anything. This will also set our mode to literal to allow this pathspec to match input verbatim, and use default_signature as magic signature.

Trait Implementations§

source§

impl Clone for Pattern

source§

fn clone(&self) -> Pattern

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§

impl Debug for Pattern

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Pattern

source§

fn default() -> Pattern

Returns the “default value” for a type. Read more
source§

impl Display for Pattern

source§

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

Formats the value using the given formatter. Read more
source§

impl Hash for Pattern

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Pattern

source§

fn cmp(&self, other: &Pattern) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Pattern

source§

fn eq(&self, other: &Pattern) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Pattern

source§

fn partial_cmp(&self, other: &Pattern) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Pattern

source§

impl StructuralPartialEq for Pattern

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> CloneToUninit for T
where T: Clone,

source§

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> 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.