summaryrefslogtreecommitdiffstats
path: root/vendor/gix-glob/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix-glob/src
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-glob/src')
-rw-r--r--vendor/gix-glob/src/parse.rs20
-rw-r--r--vendor/gix-glob/src/pattern.rs47
-rw-r--r--vendor/gix-glob/src/search/mod.rs12
-rw-r--r--vendor/gix-glob/src/search/pattern.rs14
4 files changed, 54 insertions, 39 deletions
diff --git a/vendor/gix-glob/src/parse.rs b/vendor/gix-glob/src/parse.rs
index 665f459b9..368cf77c5 100644
--- a/vendor/gix-glob/src/parse.rs
+++ b/vendor/gix-glob/src/parse.rs
@@ -6,22 +6,26 @@ use crate::{pattern, pattern::Mode};
/// A sloppy parser that performs only the most basic checks, providing additional information
/// using `pattern::Mode` flags.
///
+/// If `may_alter` is `false`, we won't parse leading `!` or its escaped form.
+///
/// Returns `(pattern, mode, no_wildcard_len)`
-pub fn pattern(mut pat: &[u8]) -> Option<(&[u8], pattern::Mode, Option<usize>)> {
+pub fn pattern(mut pat: &[u8], may_alter: bool) -> Option<(&[u8], pattern::Mode, Option<usize>)> {
let mut mode = Mode::empty();
if pat.is_empty() {
return None;
};
- if pat.first() == Some(&b'!') {
- mode |= Mode::NEGATIVE;
- pat = &pat[1..];
- } else if pat.first() == Some(&b'\\') {
- let second = pat.get(1);
- if second == Some(&b'!') || second == Some(&b'#') {
+ if may_alter {
+ if pat.first() == Some(&b'!') {
+ mode |= Mode::NEGATIVE;
pat = &pat[1..];
+ } else if pat.first() == Some(&b'\\') {
+ let second = pat.get(1);
+ if second == Some(&b'!') || second == Some(&b'#') {
+ pat = &pat[1..];
+ }
}
}
- if pat.iter().all(|b| b.is_ascii_whitespace()) {
+ if pat.iter().all(u8::is_ascii_whitespace) {
return None;
}
if pat.first() == Some(&b'/') {
diff --git a/vendor/gix-glob/src/pattern.rs b/vendor/gix-glob/src/pattern.rs
index 3c0dbfea2..475b912b0 100644
--- a/vendor/gix-glob/src/pattern.rs
+++ b/vendor/gix-glob/src/pattern.rs
@@ -44,7 +44,18 @@ pub enum Case {
impl Pattern {
/// Parse the given `text` as pattern, or return `None` if `text` was empty.
pub fn from_bytes(text: &[u8]) -> Option<Self> {
- crate::parse::pattern(text).map(|(text, mode, first_wildcard_pos)| Pattern {
+ crate::parse::pattern(text, true).map(|(text, mode, first_wildcard_pos)| Pattern {
+ text: text.into(),
+ mode,
+ first_wildcard_pos,
+ })
+ }
+
+ /// Parse the given `text` as pattern without supporting leading `!` or `\\!` , or return `None` if `text` was empty.
+ ///
+ /// This assures that `text` remains entirely unaltered, but removes built-in support for negation as well.
+ pub fn from_bytes_without_negation(text: &[u8]) -> Option<Self> {
+ crate::parse::pattern(text, false).map(|(text, mode, first_wildcard_pos)| Pattern {
text: text.into(),
mode,
first_wildcard_pos,
@@ -65,30 +76,36 @@ impl Pattern {
/// We may take various shortcuts which is when `basename_start_pos` and `is_dir` come into play.
/// `basename_start_pos` is the index at which the `path`'s basename starts.
///
- /// Lastly, `case` folding can be configured as well.
- pub fn matches_repo_relative_path<'a>(
+ /// `case` folding can be configured as well.
+ /// `mode` is used to control how [`crate::wildmatch()`] should operate.
+ pub fn matches_repo_relative_path(
&self,
- path: impl Into<&'a BStr>,
+ path: &BStr,
basename_start_pos: Option<usize>,
is_dir: Option<bool>,
case: Case,
+ mode: wildmatch::Mode,
) -> bool {
let is_dir = is_dir.unwrap_or(false);
if !is_dir && self.mode.contains(pattern::Mode::MUST_BE_DIR) {
return false;
}
- let flags = wildmatch::Mode::NO_MATCH_SLASH_LITERAL
+ let flags = mode
| match case {
Case::Fold => wildmatch::Mode::IGNORE_CASE,
Case::Sensitive => wildmatch::Mode::empty(),
};
- let path = path.into();
- debug_assert_eq!(
- basename_start_pos,
- path.rfind_byte(b'/').map(|p| p + 1),
- "BUG: invalid cached basename_start_pos provided"
- );
+ #[cfg(debug_assertions)]
+ {
+ if basename_start_pos.is_some() {
+ debug_assert_eq!(
+ basename_start_pos,
+ path.rfind_byte(b'/').map(|p| p + 1),
+ "BUG: invalid cached basename_start_pos provided"
+ );
+ }
+ }
debug_assert!(!path.starts_with(b"/"), "input path must be relative");
if self.mode.contains(pattern::Mode::NO_SUB_DIR) && !self.mode.contains(pattern::Mode::ABSOLUTE) {
@@ -106,11 +123,13 @@ impl Pattern {
///
/// Note that this method uses some shortcuts to accelerate simple patterns, but falls back to
/// [wildmatch()][crate::wildmatch()] if these fail.
- pub fn matches<'a>(&self, value: impl Into<&'a BStr>, mode: wildmatch::Mode) -> bool {
- let value = value.into();
+ pub fn matches(&self, value: &BStr, mode: wildmatch::Mode) -> bool {
match self.first_wildcard_pos {
// "*literal" case, overrides starts-with
- Some(pos) if self.mode.contains(pattern::Mode::ENDS_WITH) && !value.contains(&b'/') => {
+ Some(pos)
+ if self.mode.contains(pattern::Mode::ENDS_WITH)
+ && (!mode.contains(wildmatch::Mode::NO_MATCH_SLASH_LITERAL) || !value.contains(&b'/')) =>
+ {
let text = &self.text[pos + 1..];
if mode.contains(wildmatch::Mode::IGNORE_CASE) {
value
diff --git a/vendor/gix-glob/src/search/mod.rs b/vendor/gix-glob/src/search/mod.rs
index a31e2af37..b6fb2a490 100644
--- a/vendor/gix-glob/src/search/mod.rs
+++ b/vendor/gix-glob/src/search/mod.rs
@@ -16,9 +16,6 @@ pub trait Pattern: Clone + PartialEq + Eq + std::fmt::Debug + std::hash::Hash +
/// Parse all patterns in `bytes` line by line, ignoring lines with errors, and collect them.
fn bytes_to_patterns(bytes: &[u8], source: &Path) -> Vec<pattern::Mapping<Self::Value>>;
-
- /// Returns true if the given pattern may be used for matching.
- fn may_use_glob_pattern(pattern: &crate::Pattern) -> bool;
}
/// Add the given file at `source` if it exists, otherwise do nothing.
@@ -26,17 +23,12 @@ pub trait Pattern: Clone + PartialEq + Eq + std::fmt::Debug + std::hash::Hash +
/// Returns `true` if the file was added, or `false` if it didn't exist.
pub fn add_patterns_file<T: Pattern>(
patterns: &mut Vec<pattern::List<T>>,
- source: impl Into<PathBuf>,
+ source: PathBuf,
follow_symlinks: bool,
root: Option<&Path>,
buf: &mut Vec<u8>,
) -> std::io::Result<bool> {
let previous_len = patterns.len();
- patterns.extend(pattern::List::<T>::from_file(
- source.into(),
- root,
- follow_symlinks,
- buf,
- )?);
+ patterns.extend(pattern::List::<T>::from_file(source, root, follow_symlinks, buf)?);
Ok(patterns.len() != previous_len)
}
diff --git a/vendor/gix-glob/src/search/pattern.rs b/vendor/gix-glob/src/search/pattern.rs
index 8bb195757..828e59df3 100644
--- a/vendor/gix-glob/src/search/pattern.rs
+++ b/vendor/gix-glob/src/search/pattern.rs
@@ -51,7 +51,9 @@ fn read_in_full_ignore_missing(path: &Path, follow_symlinks: bool, buf: &mut Vec
file.read_to_end(buf)?;
true
}
- Err(err) if err.kind() == std::io::ErrorKind::NotFound => false,
+ Err(err) if err.kind() == std::io::ErrorKind::NotFound ||
+ // TODO: use the enum variant NotADirectory for this once stabilized
+ err.raw_os_error() == Some(20) /* Not a directory */ => false,
Err(err) => return Err(err),
})
}
@@ -64,12 +66,10 @@ where
/// `source_file` is the location of the `bytes` which represents a list of patterns, one pattern per line.
/// If `root` is `Some(…)` it's used to see `source_file` as relative to itself, if `source_file` is absolute.
/// If source is relative and should be treated as base, set `root` to `Some("")`.
- pub fn from_bytes(bytes: &[u8], source_file: impl Into<PathBuf>, root: Option<&Path>) -> Self {
- let source = source_file.into();
- let patterns = T::bytes_to_patterns(bytes, source.as_path());
-
+ pub fn from_bytes(bytes: &[u8], source_file: PathBuf, root: Option<&Path>) -> Self {
+ let patterns = T::bytes_to_patterns(bytes, source_file.as_path());
let base = root
- .and_then(|root| source.parent().expect("file").strip_prefix(root).ok())
+ .and_then(|root| source_file.parent().expect("file").strip_prefix(root).ok())
.and_then(|base| {
(!base.as_os_str().is_empty()).then(|| {
let mut base: BString =
@@ -81,7 +81,7 @@ where
});
List {
patterns,
- source: Some(source),
+ source: Some(source_file),
base,
}
}