diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
commit | e02c5b5930c2c9ba3e5423fe12e2ef0155017297 (patch) | |
tree | fd60ebbbb5299e16e5fca8c773ddb74f764760db /vendor/gix-ignore/src/search.rs | |
parent | Adding debian version 1.73.0+dfsg1-1. (diff) | |
download | rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.tar.xz rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-ignore/src/search.rs')
-rw-r--r-- | vendor/gix-ignore/src/search.rs | 84 |
1 files changed, 40 insertions, 44 deletions
diff --git a/vendor/gix-ignore/src/search.rs b/vendor/gix-ignore/src/search.rs index e5310b35c..9ffad9d63 100644 --- a/vendor/gix-ignore/src/search.rs +++ b/vendor/gix-ignore/src/search.rs @@ -35,10 +35,6 @@ impl Pattern for Ignore { }) .collect() } - - fn may_use_glob_pattern(_pattern: &gix_glob::Pattern) -> bool { - true - } } /// Instantiation of a search for ignore patterns. @@ -46,11 +42,7 @@ impl Search { /// Given `git_dir`, a `.git` repository, load static ignore patterns from `info/exclude` /// and from `excludes_file` if it is provided. /// Note that it's not considered an error if the provided `excludes_file` does not exist. - pub fn from_git_dir( - git_dir: impl AsRef<Path>, - excludes_file: Option<PathBuf>, - buf: &mut Vec<u8>, - ) -> std::io::Result<Self> { + pub fn from_git_dir(git_dir: &Path, excludes_file: Option<PathBuf>, buf: &mut Vec<u8>) -> std::io::Result<Self> { let mut group = Self::default(); let follow_symlinks = true; @@ -61,7 +53,7 @@ impl Search { .transpose()?, ); group.patterns.extend(pattern::List::<Ignore>::from_file( - git_dir.as_ref().join("info").join("exclude"), + &git_dir.join("info").join("exclude"), None, follow_symlinks, buf, @@ -71,11 +63,13 @@ impl Search { /// Parse a list of patterns, using slashes as path separators pub fn from_overrides(patterns: impl IntoIterator<Item = impl Into<OsString>>) -> Self { + Self::from_overrides_inner(&mut patterns.into_iter().map(Into::into)) + } + + fn from_overrides_inner(patterns: &mut dyn Iterator<Item = OsString>) -> Self { Search { patterns: vec![pattern::List { patterns: patterns - .into_iter() - .map(Into::into) .enumerate() .filter_map(|(seq_id, pattern)| { let pattern = gix_path::try_into_bstr(PathBuf::from(pattern)).ok()?; @@ -115,25 +109,27 @@ pub fn pattern_matching_relative_path<'a>( ) -> Option<Match<'a>> { let (relative_path, basename_start_pos) = list.strip_base_handle_recompute_basename_pos(relative_path, basename_pos, case)?; - list.patterns - .iter() - .rev() - .filter(|pm| Ignore::may_use_glob_pattern(&pm.pattern)) - .find_map( - |pattern::Mapping { - pattern, - value: (), - sequence_number, - }| { - pattern - .matches_repo_relative_path(relative_path, basename_start_pos, is_dir, case) - .then_some(Match { - pattern, - source: list.source.as_deref(), - sequence_number: *sequence_number, - }) - }, - ) + list.patterns.iter().rev().find_map( + |pattern::Mapping { + pattern, + value: (), + sequence_number, + }| { + pattern + .matches_repo_relative_path( + relative_path, + basename_start_pos, + is_dir, + case, + gix_glob::wildmatch::Mode::NO_MATCH_SLASH_LITERAL, + ) + .then_some(Match { + pattern, + source: list.source.as_deref(), + sequence_number: *sequence_number, + }) + }, + ) } /// Like [`pattern_matching_relative_path()`], but returns an index to the pattern @@ -147,16 +143,17 @@ pub fn pattern_idx_matching_relative_path( ) -> Option<usize> { let (relative_path, basename_start_pos) = list.strip_base_handle_recompute_basename_pos(relative_path, basename_pos, case)?; - list.patterns - .iter() - .enumerate() - .rev() - .filter(|(_, pm)| Ignore::may_use_glob_pattern(&pm.pattern)) - .find_map(|(idx, pm)| { - pm.pattern - .matches_repo_relative_path(relative_path, basename_start_pos, is_dir, case) - .then_some(idx) - }) + list.patterns.iter().enumerate().rev().find_map(|(idx, pm)| { + pm.pattern + .matches_repo_relative_path( + relative_path, + basename_start_pos, + is_dir, + case, + gix_glob::wildmatch::Mode::NO_MATCH_SLASH_LITERAL, + ) + .then_some(idx) + }) } /// Matching of ignore patterns. @@ -164,13 +161,12 @@ impl Search { /// Match `relative_path` and return the first match if found. /// `is_dir` is true if `relative_path` is a directory. /// `case` specifies whether cases should be folded during matching or not. - pub fn pattern_matching_relative_path<'a>( + pub fn pattern_matching_relative_path( &self, - relative_path: impl Into<&'a BStr>, + relative_path: &BStr, is_dir: Option<bool>, case: gix_glob::pattern::Case, ) -> Option<Match<'_>> { - let relative_path = relative_path.into(); let basename_pos = relative_path.rfind(b"/").map(|p| p + 1); self.patterns .iter() |