summaryrefslogtreecommitdiffstats
path: root/vendor/gix-glob/src/parse.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/gix-glob/src/parse.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-glob/src/parse.rs')
-rw-r--r--vendor/gix-glob/src/parse.rs43
1 files changed, 4 insertions, 39 deletions
diff --git a/vendor/gix-glob/src/parse.rs b/vendor/gix-glob/src/parse.rs
index 3693f88ef..665f459b9 100644
--- a/vendor/gix-glob/src/parse.rs
+++ b/vendor/gix-glob/src/parse.rs
@@ -1,4 +1,4 @@
-use bstr::{BString, ByteSlice};
+use bstr::ByteSlice;
use crate::{pattern, pattern::Mode};
@@ -7,7 +7,7 @@ use crate::{pattern, pattern::Mode};
/// using `pattern::Mode` flags.
///
/// Returns `(pattern, mode, no_wildcard_len)`
-pub fn pattern(mut pat: &[u8]) -> Option<(BString, pattern::Mode, Option<usize>)> {
+pub fn pattern(mut pat: &[u8]) -> Option<(&[u8], pattern::Mode, Option<usize>)> {
let mut mode = Mode::empty();
if pat.is_empty() {
return None;
@@ -28,10 +28,9 @@ pub fn pattern(mut pat: &[u8]) -> Option<(BString, pattern::Mode, Option<usize>)
mode |= Mode::ABSOLUTE;
pat = &pat[1..];
}
- let mut pat = truncate_non_escaped_trailing_spaces(pat);
if pat.last() == Some(&b'/') {
mode |= Mode::MUST_BE_DIR;
- pat.pop();
+ pat = &pat[..pat.len() - 1];
}
if !pat.contains(&b'/') {
@@ -41,7 +40,7 @@ pub fn pattern(mut pat: &[u8]) -> Option<(BString, pattern::Mode, Option<usize>)
mode |= Mode::ENDS_WITH;
}
- let pos_of_first_wildcard = first_wildcard_pos(&pat);
+ let pos_of_first_wildcard = first_wildcard_pos(pat);
Some((pat, mode, pos_of_first_wildcard))
}
@@ -50,37 +49,3 @@ fn first_wildcard_pos(pat: &[u8]) -> Option<usize> {
}
pub(crate) const GLOB_CHARACTERS: &[u8] = br"*?[\";
-
-/// We always copy just because that's ultimately needed anyway, not because we always have to.
-fn truncate_non_escaped_trailing_spaces(buf: &[u8]) -> BString {
- match buf.rfind_not_byteset(br"\ ") {
- Some(pos) if pos + 1 == buf.len() => buf.into(), // does not end in (escaped) whitespace
- None => buf.into(),
- Some(start_of_non_space) => {
- // This seems a bit strange but attempts to recreate the git implementation while
- // actually removing the escape characters before spaces. We leave other backslashes
- // for escapes to be handled by `glob/globset`.
- let mut res: BString = buf[..start_of_non_space + 1].into();
-
- let mut trailing_bytes = buf[start_of_non_space + 1..].iter();
- let mut bare_spaces = 0;
- while let Some(b) = trailing_bytes.next() {
- match b {
- b' ' => {
- bare_spaces += 1;
- }
- b'\\' => {
- res.extend(std::iter::repeat(b' ').take(bare_spaces));
- bare_spaces = 0;
- // Skip what follows, like git does, but keep spaces if possible.
- if trailing_bytes.next() == Some(&b' ') {
- res.push(b' ');
- }
- }
- _ => unreachable!("BUG: this must be either backslash or space"),
- }
- }
- res
- }
- }
-}