summaryrefslogtreecommitdiffstats
path: root/vendor/gix-ignore
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-ignore
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-ignore')
-rw-r--r--vendor/gix-ignore/.cargo-checksum.json1
-rw-r--r--vendor/gix-ignore/CHANGELOG.md71
-rw-r--r--vendor/gix-ignore/Cargo.toml71
-rw-r--r--vendor/gix-ignore/src/lib.rs34
-rw-r--r--vendor/gix-ignore/src/parse.rs63
-rw-r--r--vendor/gix-ignore/src/search.rs183
6 files changed, 423 insertions, 0 deletions
diff --git a/vendor/gix-ignore/.cargo-checksum.json b/vendor/gix-ignore/.cargo-checksum.json
new file mode 100644
index 000000000..fc97aab93
--- /dev/null
+++ b/vendor/gix-ignore/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"CHANGELOG.md":"fcca667578342ae251addb97576a7a9cc15d90c3122a500f43d673c82ab3505d","Cargo.toml":"4e9c07e22c228fbb03f22fa59482d85dc8054fd47e31a28f582331143e04ff24","src/lib.rs":"455b36514f19f0f8a2bad71c3b14cf1e09ff0387006a6d53216a4032b7478fc9","src/parse.rs":"1ff89eb91bf98473494b459eb334ed8c4665e352247ccd02708568ff0a85172b","src/search.rs":"d9f8082db10e7d0580872f0fdb41ac112c1eed304456ec352262fba87c5ed207"},"package":"ba205b6df563e2906768bb22834c82eb46c5fdfcd86ba2c347270bc8309a05b2"} \ No newline at end of file
diff --git a/vendor/gix-ignore/CHANGELOG.md b/vendor/gix-ignore/CHANGELOG.md
new file mode 100644
index 000000000..ebd383310
--- /dev/null
+++ b/vendor/gix-ignore/CHANGELOG.md
@@ -0,0 +1,71 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
+and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+
+## 0.2.0 (2023-04-27)
+
+A maintenance release without user-facing changes.
+
+### Commit Statistics
+
+<csr-read-only-do-not-edit/>
+
+ - 2 commits contributed to the release.
+ - 0 commits were understood as [conventional](https://www.conventionalcommits.org).
+ - 0 issues like '(#ID)' were seen in commit messages
+
+### Commit Details
+
+<csr-read-only-do-not-edit/>
+
+<details><summary>view details</summary>
+
+ * **Uncategorized**
+ - Prepare changelogs prior to release ([`0135158`](https://github.com/Byron/gitoxide/commit/013515897215400539bfd53c25548bd054186ba6))
+ - Bump gix-path v0.8.0, safety bump 20 crates (gix set to 0.44.1 manually) ([`43ebaf2`](https://github.com/Byron/gitoxide/commit/43ebaf267557218865862538ffc7bdf00558492f))
+</details>
+
+## 0.1.0 (2023-04-26)
+
+### New Features (BREAKING)
+
+ - <csr-id-b83ee366a3c65c717beb587ad809268f1c54b8ad/> Rename `serde1` cargo feature to `serde` and use the weak-deps cargo capability.
+ With it it's possible to not automatically declare all optional dependencies externally visible
+ features, and thus re-use feature names that oterwise are also a crate name.
+
+ Previously I thought that `serde1` is for future-proofing and supporting multiple serde versions
+ at the same time. However, it's most definitely a burden I wouldn't want anyway, so using
+ `serde` seems to be the way to go into the future.
+
+### Commit Statistics
+
+<csr-read-only-do-not-edit/>
+
+ - 11 commits contributed to the release over the course of 12 calendar days.
+ - 1 commit was understood as [conventional](https://www.conventionalcommits.org).
+ - 1 unique issue was worked on: [#814](https://github.com/Byron/gitoxide/issues/814)
+
+### Commit Details
+
+<csr-read-only-do-not-edit/>
+
+<details><summary>view details</summary>
+
+ * **[#814](https://github.com/Byron/gitoxide/issues/814)**
+ - Rename `serde1` cargo feature to `serde` and use the weak-deps cargo capability. ([`b83ee36`](https://github.com/Byron/gitoxide/commit/b83ee366a3c65c717beb587ad809268f1c54b8ad))
+ * **Uncategorized**
+ - Release gix-hash v0.11.1, gix-path v0.7.4, gix-glob v0.6.0, gix-attributes v0.11.0, gix-config-value v0.11.0, gix-fs v0.1.1, gix-tempfile v5.0.3, gix-utils v0.1.1, gix-lock v5.0.1, gix-object v0.29.1, gix-ref v0.28.0, gix-sec v0.7.0, gix-config v0.21.0, gix-prompt v0.4.0, gix-url v0.17.0, gix-credentials v0.13.0, gix-diff v0.29.0, gix-discover v0.17.0, gix-hashtable v0.2.0, gix-ignore v0.1.0, gix-bitmap v0.2.3, gix-traverse v0.25.0, gix-index v0.16.0, gix-mailmap v0.12.0, gix-pack v0.34.0, gix-odb v0.44.0, gix-packetline v0.16.0, gix-transport v0.30.0, gix-protocol v0.31.0, gix-revision v0.13.0, gix-refspec v0.10.0, gix-worktree v0.16.0, gix v0.44.0, safety bump 7 crates ([`91134a1`](https://github.com/Byron/gitoxide/commit/91134a11c8ba0e942f692488ec9bce9fa1086324))
+ - Prepare changelogs prior to release ([`30a1a71`](https://github.com/Byron/gitoxide/commit/30a1a71f36f24faac0e0b362ffdfedea7f9cdbf1))
+ - Release gix-utils v0.1.0, gix-hash v0.11.0, gix-date v0.5.0, gix-features v0.29.0, gix-actor v0.20.0, gix-object v0.29.0, gix-archive v0.1.0, gix-fs v0.1.0, safety bump 25 crates ([`8dbd0a6`](https://github.com/Byron/gitoxide/commit/8dbd0a60557a85acfa231800a058cbac0271a8cf))
+ - Make fmt ([`5d2b5d0`](https://github.com/Byron/gitoxide/commit/5d2b5d02c3869e07dc2507a8f2519ee1df633df7))
+ - Merge branch 'main' into dev ([`cdef398`](https://github.com/Byron/gitoxide/commit/cdef398c4a3bd01baf0be2c27a3f77a400172b0d))
+ - Rename the serde1 feature to serde ([`19338d9`](https://github.com/Byron/gitoxide/commit/19338d934b6712b7d6bd3fa3b2e4189bf7e6c8a1))
+ - Create new `gix-fs` crate to consolidate all filesystem utilities ([`f8cc33c`](https://github.com/Byron/gitoxide/commit/f8cc33cb372dd2b4bbe4a09cf4f64916681ab1dd))
+ - Merge branch 'main' into dev ([`23ee47f`](https://github.com/Byron/gitoxide/commit/23ee47fb24c197f8437bd426544b2aa74e005bdc))
+ - Merge branch 'worktree-stack' ([`3d47919`](https://github.com/Byron/gitoxide/commit/3d47919c1a2f83fc7c1fd7ae590d098057a22626))
+ - Add new `gix-ignore` crate with the contents moved and adapted from `gix-attributes`. ([`fc28701`](https://github.com/Byron/gitoxide/commit/fc28701b52139d9422dd73687d776cf95de98b35))
+</details>
+
diff --git a/vendor/gix-ignore/Cargo.toml b/vendor/gix-ignore/Cargo.toml
new file mode 100644
index 000000000..c5ad46608
--- /dev/null
+++ b/vendor/gix-ignore/Cargo.toml
@@ -0,0 +1,71 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+edition = "2021"
+rust-version = "1.64"
+name = "gix-ignore"
+version = "0.2.0"
+authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
+include = [
+ "src/**/*",
+ "CHANGELOG.md",
+]
+description = "A WIP crate of the gitoxide project dealing .gitignore files"
+license = "MIT/Apache-2.0"
+repository = "https://github.com/Byron/gitoxide"
+
+[package.metadata.docs.rs]
+all-features = true
+features = ["document-features"]
+rustdoc-args = [
+ "--cfg",
+ "docsrs",
+]
+
+[lib]
+doctest = false
+
+[dependencies.bstr]
+version = "1.3.0"
+features = [
+ "std",
+ "unicode",
+]
+default-features = false
+
+[dependencies.document-features]
+version = "0.2.1"
+optional = true
+
+[dependencies.gix-glob]
+version = "^0.7.0"
+
+[dependencies.gix-path]
+version = "^0.8.0"
+
+[dependencies.serde]
+version = "1.0.114"
+features = ["derive"]
+optional = true
+default-features = false
+
+[dependencies.unicode-bom]
+version = "2.0.2"
+
+[dev-dependencies]
+
+[features]
+serde = [
+ "dep:serde",
+ "bstr/serde",
+ "gix-glob/serde",
+]
diff --git a/vendor/gix-ignore/src/lib.rs b/vendor/gix-ignore/src/lib.rs
new file mode 100644
index 000000000..20ca1cc8c
--- /dev/null
+++ b/vendor/gix-ignore/src/lib.rs
@@ -0,0 +1,34 @@
+//! Parse `.gitignore` files and provide utilities to match against them.
+//!
+//! ## Feature Flags
+#![cfg_attr(
+ feature = "document-features",
+ cfg_attr(doc, doc = ::document_features::document_features!())
+)]
+#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
+#![deny(missing_docs, rust_2018_idioms)]
+#![forbid(unsafe_code)]
+
+pub use gix_glob as glob;
+
+///
+pub mod search;
+/// A grouping of lists of patterns while possibly keeping associated to their base path in order to find matches.
+///
+/// Pattern lists with base path are queryable relative to that base, otherwise they are relative to the repository root.
+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Default)]
+pub struct Search {
+ /// A list of pattern lists, each representing a patterns from a file or specified by hand, in the order they were
+ /// specified in.
+ ///
+ /// When matching, this order is reversed.
+ pub patterns: Vec<gix_glob::search::pattern::List<search::Ignore>>,
+}
+
+///
+pub mod parse;
+
+/// Parse git ignore patterns, line by line, from `bytes`.
+pub fn parse(bytes: &[u8]) -> parse::Lines<'_> {
+ parse::Lines::new(bytes)
+}
diff --git a/vendor/gix-ignore/src/parse.rs b/vendor/gix-ignore/src/parse.rs
new file mode 100644
index 000000000..11ceaabaf
--- /dev/null
+++ b/vendor/gix-ignore/src/parse.rs
@@ -0,0 +1,63 @@
+use bstr::ByteSlice;
+
+/// An iterator over line-wise ignore patterns parsed from a buffer.
+pub struct Lines<'a> {
+ lines: bstr::Lines<'a>,
+ line_no: usize,
+}
+
+impl<'a> Lines<'a> {
+ /// Create a new instance from `buf` to parse ignore patterns from.
+ pub fn new(buf: &'a [u8]) -> Self {
+ let bom = unicode_bom::Bom::from(buf);
+ Lines {
+ lines: buf[bom.len()..].lines(),
+ line_no: 0,
+ }
+ }
+}
+
+impl<'a> Iterator for Lines<'a> {
+ type Item = (gix_glob::Pattern, usize);
+
+ fn next(&mut self) -> Option<Self::Item> {
+ for line in self.lines.by_ref() {
+ self.line_no += 1;
+ if line.first() == Some(&b'#') {
+ continue;
+ }
+ match gix_glob::Pattern::from_bytes(truncate_non_escaped_trailing_spaces(line)) {
+ None => continue,
+ Some(pattern) => return Some((pattern, self.line_no)),
+ }
+ }
+ None
+ }
+}
+
+/// We always copy just because that's ultimately needed anyway, not because we always have to.
+fn truncate_non_escaped_trailing_spaces(buf: &[u8]) -> &[u8] {
+ let mut last_space_pos = None;
+ let mut bytes = buf.iter().enumerate();
+ while let Some((pos, b)) = bytes.next() {
+ match *b {
+ b' ' => {
+ last_space_pos.get_or_insert(pos);
+ continue;
+ }
+ b'\\' => {
+ if bytes.next().is_none() {
+ return buf;
+ }
+ }
+ _ => {}
+ }
+ last_space_pos = None;
+ }
+
+ if let Some(pos) = last_space_pos {
+ &buf[..pos]
+ } else {
+ buf
+ }
+}
diff --git a/vendor/gix-ignore/src/search.rs b/vendor/gix-ignore/src/search.rs
new file mode 100644
index 000000000..5c957f136
--- /dev/null
+++ b/vendor/gix-ignore/src/search.rs
@@ -0,0 +1,183 @@
+use std::{
+ ffi::OsString,
+ path::{Path, PathBuf},
+};
+
+use bstr::{BStr, ByteSlice};
+use gix_glob::search::{pattern, Pattern};
+
+use crate::Search;
+
+/// Describes a matching pattern within a search for ignored paths.
+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
+pub struct Match<'a, T> {
+ /// The glob pattern itself, like `/target/*`.
+ pub pattern: &'a gix_glob::Pattern,
+ /// The value associated with the pattern.
+ pub value: &'a T,
+ /// The path to the source from which the pattern was loaded, or `None` if it was specified by other means.
+ pub source: Option<&'a Path>,
+ /// The line at which the pattern was found in its `source` file, or the occurrence in which it was provided.
+ pub sequence_number: usize,
+}
+
+/// An implementation of the [`Pattern`] trait for ignore patterns.
+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Default)]
+pub struct Ignore;
+
+impl Pattern for Ignore {
+ type Value = ();
+
+ fn bytes_to_patterns(bytes: &[u8], _source: &std::path::Path) -> Vec<pattern::Mapping<Self::Value>> {
+ crate::parse(bytes)
+ .map(|(pattern, line_number)| pattern::Mapping {
+ pattern,
+ value: (),
+ sequence_number: line_number,
+ })
+ .collect()
+ }
+
+ fn may_use_glob_pattern(_pattern: &gix_glob::Pattern) -> bool {
+ true
+ }
+}
+
+/// Instantiation of a search for ignore patterns.
+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> {
+ let mut group = Self::default();
+
+ let follow_symlinks = true;
+ // order matters! More important ones first.
+ group.patterns.extend(
+ excludes_file
+ .and_then(|file| pattern::List::<Ignore>::from_file(file, None, follow_symlinks, buf).transpose())
+ .transpose()?,
+ );
+ group.patterns.extend(pattern::List::<Ignore>::from_file(
+ git_dir.as_ref().join("info").join("exclude"),
+ None,
+ follow_symlinks,
+ buf,
+ )?);
+ Ok(group)
+ }
+
+ /// Parse a list of patterns, using slashes as path separators
+ pub fn from_overrides(patterns: impl IntoIterator<Item = impl Into<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()?;
+ gix_glob::parse(pattern.as_ref()).map(|p| pattern::Mapping {
+ pattern: p,
+ value: (),
+ sequence_number: seq_id,
+ })
+ })
+ .collect(),
+ source: None,
+ base: None,
+ }],
+ }
+ }
+}
+
+/// Mutation
+impl Search {
+ /// 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.
+ pub fn add_patterns_buffer(&mut self, bytes: &[u8], source: impl Into<PathBuf>, root: Option<&Path>) {
+ self.patterns
+ .push(pattern::List::from_bytes(bytes, source.into(), root));
+ }
+}
+
+/// Return a match if a pattern matches `relative_path`, providing a pre-computed `basename_pos` which is the
+/// starting position of the basename of `relative_path`. `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>(
+ list: &'a gix_glob::search::pattern::List<Ignore>,
+ relative_path: &BStr,
+ basename_pos: Option<usize>,
+ is_dir: Option<bool>,
+ case: gix_glob::pattern::Case,
+) -> 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,
+ value,
+ source: list.source.as_deref(),
+ sequence_number: *sequence_number,
+ })
+ },
+ )
+}
+
+/// Like [`pattern_matching_relative_path()`], but returns an index to the pattern
+/// that matched `relative_path`, instead of the match itself.
+pub fn pattern_idx_matching_relative_path(
+ list: &gix_glob::search::pattern::List<Ignore>,
+ relative_path: &BStr,
+ basename_pos: Option<usize>,
+ is_dir: Option<bool>,
+ case: gix_glob::pattern::Case,
+) -> 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)
+ })
+}
+
+/// Matching of ignore patterns.
+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>(
+ &self,
+ relative_path: impl Into<&'a 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()
+ .rev()
+ .find_map(|pl| pattern_matching_relative_path(pl, relative_path, basename_pos, is_dir, case))
+ }
+}