pub struct IgnorePatternList { /* private fields */ }Expand description
Patterns parsed from one exclude file (such as a .gitignore), for matching single paths.
Unlike IgnoreMatcher, a list is not tied to a repository: the caller decides which
files apply to a path and in what order, as tools that layer their own ignore handling on
top of Git’s file format need to. Matching follows Git’s last_matching_pattern_from_list
for one path: patterns without a slash match the path’s last component, other patterns match
the whole path relative to the list’s base directory, and directory-only patterns (foo/)
match only when the path is a directory. Parent directories are not consulted; callers that
walk a tree stop descending into ignored directories, as Git does.
§Examples
use grit_lib::worktree::ignore::IgnorePatternList;
let list = IgnorePatternList::parse(b"*.log\n!keep.log\nbuild/\n", "");
assert!(list.is_ignored("debug.log", false, false).unwrap());
assert!(!list.is_ignored("keep.log", false, false).unwrap());
assert!(list.is_ignored("build", true, false).unwrap());
assert_eq!(list.is_ignored("build", false, false), None);Implementations§
Source§impl IgnorePatternList
impl IgnorePatternList
Sourcepub fn parse(content: &[u8], base_dir: &str) -> Self
pub fn parse(content: &[u8], base_dir: &str) -> Self
Parse exclude-file content whose patterns are relative to base_dir.
base_dir is the slash-separated directory holding the file, relative to the root
paths are matched against ("" for the root). Blank lines and comments are skipped,
a UTF-8 byte order mark on the first line is dropped, and invalid UTF-8 is replaced
as in String::from_utf8_lossy.
Sourcepub fn last_match(
&self,
path: &str,
is_dir: bool,
ignore_case: bool,
) -> Option<IgnorePatternMatch>
pub fn last_match( &self, path: &str, is_dir: bool, ignore_case: bool, ) -> Option<IgnorePatternMatch>
The last pattern matching path, if any.
path is slash-separated and relative to the root the list’s base directory is
relative to. Paths outside the base directory never match. With ignore_case,
patterns compare without regard to ASCII case (core.ignorecase).
Sourcepub fn is_ignored(
&self,
path: &str,
is_dir: bool,
ignore_case: bool,
) -> Option<bool>
pub fn is_ignored( &self, path: &str, is_dir: bool, ignore_case: bool, ) -> Option<bool>
Whether the last matching pattern ignores path (Some(false) when it re-includes
it), or None when no pattern matches. See Self::last_match.