diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix/src/repository/pathspec.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-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/src/repository/pathspec.rs')
-rw-r--r-- | vendor/gix/src/repository/pathspec.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/gix/src/repository/pathspec.rs b/vendor/gix/src/repository/pathspec.rs new file mode 100644 index 000000000..8e7e9bbe9 --- /dev/null +++ b/vendor/gix/src/repository/pathspec.rs @@ -0,0 +1,55 @@ +use gix_pathspec::MagicSignature; + +use crate::{bstr::BStr, config::cache::util::ApplyLeniencyDefault, AttributeStack, Pathspec, Repository}; + +impl Repository { + /// Create a new pathspec abstraction that allows to conduct searches using `patterns`. + /// `inherit_ignore_case` should be `true` if `patterns` will match against files on disk, or `false` otherwise, for more natural matching + /// (but also note that `git` does not do that). + /// `index` may be needed to load attributes which is required only if `patterns` refer to attributes via `:(attr:…)` syntax. + /// In the same vein, `attributes_source` affects where `.gitattributes` files are read from if pathspecs need to match against attributes. + /// + /// It will be initialized exactly how it would, and attribute matching will be conducted by reading the worktree first if available. + /// If that is not desirable, consider calling [`Pathspec::new()`] directly. + #[doc(alias = "Pathspec", alias = "git2")] + pub fn pathspec( + &self, + patterns: impl IntoIterator<Item = impl AsRef<BStr>>, + inherit_ignore_case: bool, + index: &gix_index::State, + attributes_source: gix_worktree::stack::state::attributes::Source, + ) -> Result<Pathspec<'_>, crate::pathspec::init::Error> { + Pathspec::new(self, patterns, inherit_ignore_case, || { + self.attributes_only(index, attributes_source) + .map(AttributeStack::detach) + .map_err(Into::into) + }) + } + + /// Return default settings that are required when [parsing pathspecs](gix_pathspec::parse()) by hand. + /// + /// These are stemming from environment variables which have been converted to [config settings](crate::config::tree::gitoxide::Pathspec), + /// which now serve as authority for configuration. + pub fn pathspec_defaults(&self) -> Result<gix_pathspec::Defaults, gix_pathspec::defaults::from_environment::Error> { + self.config.pathspec_defaults() + } + + /// Similar to [Self::pathspec_defaults()], but will automatically configure the returned defaults to match case-insensitively if the underlying + /// filesystem is also configured to be case-insensitive according to `core.ignoreCase`, and `inherit_ignore_case` is `true`. + pub fn pathspec_defaults_inherit_ignore_case( + &self, + inherit_ignore_case: bool, + ) -> Result<gix_pathspec::Defaults, crate::repository::pathspec_defaults_ignore_case::Error> { + let mut defaults = self.config.pathspec_defaults()?; + if inherit_ignore_case + && self + .config + .fs_capabilities() + .with_lenient_default(self.config.lenient_config)? + .ignore_case + { + defaults.signature |= MagicSignature::ICASE; + } + Ok(defaults) + } +} |