summaryrefslogtreecommitdiffstats
path: root/vendor/gix-attributes/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
commita0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch)
treefc451898ccaf445814e26b46664d78702178101d /vendor/gix-attributes/src
parentAdding debian version 1.71.1+dfsg1-2. (diff)
downloadrustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz
rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-attributes/src')
-rw-r--r--vendor/gix-attributes/src/assignment.rs6
-rw-r--r--vendor/gix-attributes/src/parse.rs4
-rw-r--r--vendor/gix-attributes/src/search/attributes.rs30
-rw-r--r--vendor/gix-attributes/src/search/outcome.rs5
-rw-r--r--vendor/gix-attributes/src/search/refmap.rs8
-rw-r--r--vendor/gix-attributes/src/state.rs10
6 files changed, 48 insertions, 15 deletions
diff --git a/vendor/gix-attributes/src/assignment.rs b/vendor/gix-attributes/src/assignment.rs
index 87689d443..bf77e4341 100644
--- a/vendor/gix-attributes/src/assignment.rs
+++ b/vendor/gix-attributes/src/assignment.rs
@@ -1,7 +1,9 @@
-use crate::{Assignment, AssignmentRef, NameRef, StateRef};
-use bstr::ByteSlice;
use std::fmt::Write;
+use bstr::ByteSlice;
+
+use crate::{Assignment, AssignmentRef, NameRef, StateRef};
+
impl<'a> AssignmentRef<'a> {
pub(crate) fn new(name: NameRef<'a>, state: StateRef<'a>) -> AssignmentRef<'a> {
AssignmentRef { name, state }
diff --git a/vendor/gix-attributes/src/parse.rs b/vendor/gix-attributes/src/parse.rs
index 0b70cb306..2d90a006d 100644
--- a/vendor/gix-attributes/src/parse.rs
+++ b/vendor/gix-attributes/src/parse.rs
@@ -59,7 +59,7 @@ impl<'a> Iter<'a> {
} else if attr.first() == Some(&b'!') {
(&attr[1..], StateRef::Unspecified)
} else {
- (attr, possibly_value.map(StateRef::from_bytes).unwrap_or(StateRef::Set))
+ (attr, possibly_value.map_or(StateRef::Set, StateRef::from_bytes))
};
Ok(AssignmentRef::new(check_attr(attr)?, state))
}
@@ -106,7 +106,7 @@ impl<'a> Iterator for Lines<'a> {
fn next(&mut self) -> Option<Self::Item> {
fn skip_blanks(line: &BStr) -> &BStr {
- line.find_not_byteset(BLANKS).map(|pos| &line[pos..]).unwrap_or(line)
+ line.find_not_byteset(BLANKS).map_or(line, |pos| &line[pos..])
}
for line in self.lines.by_ref() {
self.line_no += 1;
diff --git a/vendor/gix-attributes/src/search/attributes.rs b/vendor/gix-attributes/src/search/attributes.rs
index a34ae8b3e..078c187bb 100644
--- a/vendor/gix-attributes/src/search/attributes.rs
+++ b/vendor/gix-attributes/src/search/attributes.rs
@@ -25,10 +25,16 @@ impl Search {
collection: &mut MetadataCollection,
) -> std::io::Result<Self> {
let mut group = Self::default();
- group.add_patterns_buffer(b"[attr]binary -diff -merge -text", "[builtin]", None, collection);
+ group.add_patterns_buffer(
+ b"[attr]binary -diff -merge -text",
+ "[builtin]",
+ None,
+ collection,
+ true, /* allow macros */
+ );
for path in files.into_iter() {
- group.add_patterns_file(path, true, None, buf, collection)?;
+ group.add_patterns_file(path, true, None, buf, collection, true /* allow macros */)?;
}
Ok(group)
}
@@ -39,6 +45,7 @@ impl Search {
/// Add the given file at `source` to our patterns if it exists, otherwise do nothing.
/// Update `collection` with newly added attribute names.
/// If a `root` is provided, it's not considered a global file anymore.
+ /// If `allow_macros` is `true`, macros will be processed like normal, otherwise they will be skipped entirely.
/// Returns `true` if the file was added, or `false` if it didn't exist.
pub fn add_patterns_file(
&mut self,
@@ -47,24 +54,39 @@ impl Search {
root: Option<&Path>,
buf: &mut Vec<u8>,
collection: &mut MetadataCollection,
+ allow_macros: bool,
) -> std::io::Result<bool> {
+ // TODO: should `Pattern` trait use an instance as first argument to carry this information
+ // (so no `retain` later, it's slower than skipping)
let was_added = gix_glob::search::add_patterns_file(&mut self.patterns, source, follow_symlinks, root, buf)?;
if was_added {
- collection.update_from_list(self.patterns.last_mut().expect("just added"));
+ let last = self.patterns.last_mut().expect("just added");
+ if !allow_macros {
+ last.patterns
+ .retain(|p| !matches!(p.value, Value::MacroAssignments { .. }))
+ }
+ collection.update_from_list(last);
}
Ok(was_added)
}
/// Add patterns as parsed from `bytes`, providing their `source` path and possibly their `root` path, the path they
/// are relative to. This also means that `source` is contained within `root` if `root` is provided.
+ /// If `allow_macros` is `true`, macros will be processed like normal, otherwise they will be skipped entirely.
pub fn add_patterns_buffer(
&mut self,
bytes: &[u8],
source: impl Into<PathBuf>,
root: Option<&Path>,
collection: &mut MetadataCollection,
+ allow_macros: bool,
) {
self.patterns.push(pattern::List::from_bytes(bytes, source, root));
- collection.update_from_list(self.patterns.last_mut().expect("just added"));
+ let last = self.patterns.last_mut().expect("just added");
+ if !allow_macros {
+ last.patterns
+ .retain(|p| !matches!(p.value, Value::MacroAssignments { .. }))
+ }
+ collection.update_from_list(last);
}
/// Pop the last attribute patterns list from our queue.
diff --git a/vendor/gix-attributes/src/search/outcome.rs b/vendor/gix-attributes/src/search/outcome.rs
index 5d5a26b44..469cae154 100644
--- a/vendor/gix-attributes/src/search/outcome.rs
+++ b/vendor/gix-attributes/src/search/outcome.rs
@@ -2,11 +2,10 @@ use bstr::{BString, ByteSlice};
use gix_glob::Pattern;
use kstring::{KString, KStringRef};
-use crate::search::refmap::RefMapKey;
use crate::{
search::{
- Assignments, AttributeId, Attributes, MatchKind, Metadata, MetadataCollection, Outcome, TrackedAssignment,
- Value,
+ refmap::RefMapKey, Assignments, AttributeId, Attributes, MatchKind, Metadata, MetadataCollection, Outcome,
+ TrackedAssignment, Value,
},
AssignmentRef, NameRef, StateRef,
};
diff --git a/vendor/gix-attributes/src/search/refmap.rs b/vendor/gix-attributes/src/search/refmap.rs
index 3dc51265c..aa9dee84b 100644
--- a/vendor/gix-attributes/src/search/refmap.rs
+++ b/vendor/gix-attributes/src/search/refmap.rs
@@ -2,10 +2,10 @@
//!
//! We chose to use hashing/identity over pointers as it's possible that different objects end up in the same memory location,
//! which would create obscure bugs. The same could happen with hash collisions, but they these are designed to be less likely.
-use std::collections::btree_map::Entry;
-use std::collections::hash_map::DefaultHasher;
-use std::collections::BTreeMap;
-use std::hash::{Hash, Hasher};
+use std::{
+ collections::{btree_map::Entry, hash_map::DefaultHasher, BTreeMap},
+ hash::{Hash, Hasher},
+};
pub(crate) type RefMapKey = u64;
pub(crate) struct RefMap<T>(BTreeMap<RefMapKey, T>);
diff --git a/vendor/gix-attributes/src/state.rs b/vendor/gix-attributes/src/state.rs
index 27ce2a247..ffc0bce41 100644
--- a/vendor/gix-attributes/src/state.rs
+++ b/vendor/gix-attributes/src/state.rs
@@ -69,6 +69,16 @@ impl StateRef<'_> {
pub fn is_unspecified(&self) -> bool {
matches!(self, StateRef::Unspecified)
}
+
+ /// Return `true` if the associated attribute was set with `attr`. Note that this will also be `true` if a value is assigned.
+ pub fn is_set(&self) -> bool {
+ matches!(self, StateRef::Set | StateRef::Value(_))
+ }
+
+ /// Return `true` if the associated attribute was set with `-attr` to specifically remove it.
+ pub fn is_unset(&self) -> bool {
+ matches!(self, StateRef::Unset)
+ }
}
/// Initialization