Skip to main content

IgnorePatternList

Struct IgnorePatternList 

Source
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

Source

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.

Source

pub fn is_empty(&self) -> bool

Whether the list has no patterns.

Source

pub fn len(&self) -> usize

Number of patterns in the list.

Source

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

Source

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.

Trait Implementations§

Source§

impl Clone for IgnorePatternList

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IgnorePatternList

Source§

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

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

impl Default for IgnorePatternList

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.