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§
source§impl Search
impl Search
Lifecycle
sourcepub fn from_specs(
pathspecs: impl IntoIterator<Item = Pattern>,
prefix: Option<&Path>,
root: &Path
) -> Result<Self, Error>
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.
sourcepub fn into_patterns(self) -> impl Iterator<Item = Pattern>
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
impl Search
sourcepub 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<'_>>
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
impl Search
Access
sourcepub fn patterns(&self) -> impl Iterator<Item = &Pattern> + '_
pub fn patterns(&self) -> impl Iterator<Item = &Pattern> + '_
Return an iterator over the patterns that participate in the search.
sourcepub fn common_prefix(&self) -> &BStr
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.