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
impl Pattern
Access
sourcepub fn is_nil(&self) -> bool
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 :
.
sourcepub fn prefix_directory(&self) -> &BStr
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§impl Pattern
impl Pattern
Mutation
sourcepub fn normalize(
&mut self,
prefix: &Path,
root: &Path,
) -> Result<&mut Self, Error>
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
impl Pattern
Access
sourcepub fn is_excluded(&self) -> bool
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.
sourcepub fn always_matches(&self) -> bool
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.
sourcepub fn to_bstring(&self) -> BString
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
impl Pattern
sourcepub fn from_bytes(input: &[u8], _: Defaults) -> Result<Self, Error>
pub fn from_bytes(input: &[u8], _: Defaults) -> Result<Self, Error>
Try to parse a path-spec pattern from the given input
bytes.
sourcepub fn from_literal(input: &[u8], default_signature: MagicSignature) -> Self
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 Ord for Pattern
impl Ord for Pattern
source§impl PartialOrd for Pattern
impl PartialOrd for Pattern
impl Eq for Pattern
impl StructuralPartialEq for Pattern
Auto Trait Implementations§
impl Freeze for Pattern
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnwindSafe for Pattern
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)