summaryrefslogtreecommitdiffstats
path: root/vendor/gix/src/worktree/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix/src/worktree/mod.rs')
-rw-r--r--vendor/gix/src/worktree/mod.rs105
1 files changed, 52 insertions, 53 deletions
diff --git a/vendor/gix/src/worktree/mod.rs b/vendor/gix/src/worktree/mod.rs
index 19a44a900..8db123554 100644
--- a/vendor/gix/src/worktree/mod.rs
+++ b/vendor/gix/src/worktree/mod.rs
@@ -7,9 +7,9 @@ use crate::{
Repository,
};
-pub(crate) type IndexStorage = gix_features::threading::OwnShared<gix_features::fs::MutableSnapshot<gix_index::File>>;
+pub(crate) type IndexStorage = gix_features::threading::OwnShared<gix_fs::SharedFileSnapshotMut<gix_index::File>>;
/// A lazily loaded and auto-updated worktree index.
-pub type Index = gix_features::fs::SharedSnapshot<gix_index::File>;
+pub type Index = gix_fs::SharedFileSnapshot<gix_index::File>;
/// A stand-in to a worktree as result of a worktree iteration.
///
@@ -71,18 +71,12 @@ pub mod proxy;
///
pub mod open_index {
- use crate::bstr::BString;
-
/// The error returned by [`Worktree::open_index()`][crate::Worktree::open_index()].
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
- #[error("Could not interpret value '{}' as 'index.threads'", .value)]
- ConfigIndexThreads {
- value: BString,
- #[source]
- err: gix_config::value::Error,
- },
+ #[error(transparent)]
+ ConfigIndexThreads(#[from] crate::config::key::GenericErrorWithValue),
#[error(transparent)]
IndexFile(#[from] gix_index::file::init::Error),
}
@@ -102,59 +96,64 @@ pub mod open_index {
///
pub mod excludes {
- use std::path::PathBuf;
-
/// The error returned by [`Worktree::excludes()`][crate::Worktree::excludes()].
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
- #[error("Could not read repository exclude.")]
- Io(#[from] std::io::Error),
#[error(transparent)]
- EnvironmentPermission(#[from] gix_sec::permission::Error<PathBuf>),
- #[error("The value for `core.excludesFile` could not be read from configuration")]
- ExcludesFilePathInterpolation(#[from] gix_config::path::interpolate::Error),
+ OpenIndex(#[from] crate::worktree::open_index::Error),
+ #[error(transparent)]
+ CreateCache(#[from] crate::config::exclude_stack::Error),
}
impl<'repo> crate::Worktree<'repo> {
/// Configure a file-system cache checking if files below the repository are excluded.
///
- /// This takes into consideration all the usual repository configuration.
- // TODO: test, provide higher-level interface that is much easier to use and doesn't panic.
- pub fn excludes(
- &self,
- index: &gix_index::State,
- overrides: Option<gix_attributes::MatchGroup<gix_attributes::Ignore>>,
- ) -> Result<gix_worktree::fs::Cache, Error> {
- let repo = self.parent;
- let case = repo
- .config
- .ignore_case
- .then_some(gix_glob::pattern::Case::Fold)
- .unwrap_or_default();
- let mut buf = Vec::with_capacity(512);
- let excludes_file = match repo.config.excludes_file().transpose()? {
- Some(user_path) => Some(user_path),
- None => repo.config.xdg_config_path("ignore")?,
- };
- let state = gix_worktree::fs::cache::State::IgnoreStack(gix_worktree::fs::cache::state::Ignore::new(
- overrides.unwrap_or_default(),
- gix_attributes::MatchGroup::<gix_attributes::Ignore>::from_git_dir(
- repo.git_dir(),
- excludes_file,
- &mut buf,
- )?,
- None,
- case,
- ));
- let attribute_list = state.build_attribute_list(index, index.path_backing(), case);
- Ok(gix_worktree::fs::Cache::new(
- self.path,
- state,
- case,
- buf,
- attribute_list,
- ))
+ /// This takes into consideration all the usual repository configuration, namely:
+ ///
+ /// * `$XDG_CONFIG_HOME/…/ignore` if `core.excludesFile` is *not* set, otherwise use the configured file.
+ /// * `$GIT_DIR/info/exclude` if present.
+ ///
+ /// When only excludes are desired, this is the most efficient way to obtain them. Otherwise use
+ /// [`Worktree::attributes()`][crate::Worktree::attributes()] for accessing both attributes and excludes.
+ pub fn excludes(&self, overrides: Option<gix_ignore::Search>) -> Result<gix_worktree::Cache, Error> {
+ let index = self.index()?;
+ Ok(self.parent.excludes(
+ &index,
+ overrides,
+ gix_worktree::cache::state::ignore::Source::WorktreeThenIdMappingIfNotSkipped,
+ )?)
+ }
+ }
+}
+
+///
+pub mod attributes {
+ /// The error returned by [`Worktree::attributes()`][crate::Worktree::attributes()].
+ #[derive(Debug, thiserror::Error)]
+ #[allow(missing_docs)]
+ pub enum Error {
+ #[error(transparent)]
+ OpenIndex(#[from] crate::worktree::open_index::Error),
+ #[error(transparent)]
+ CreateCache(#[from] crate::attributes::Error),
+ }
+
+ impl<'repo> crate::Worktree<'repo> {
+ /// Configure a file-system cache checking if files below the repository are excluded or for querying their attributes.
+ ///
+ /// This takes into consideration all the usual repository configuration, namely:
+ ///
+ /// * `$XDG_CONFIG_HOME/…/ignore|attributes` if `core.excludesFile|attributesFile` is *not* set, otherwise use the configured file.
+ /// * `$GIT_DIR/info/exclude|attributes` if present.
+ pub fn attributes(&self, overrides: Option<gix_ignore::Search>) -> Result<gix_worktree::Cache, Error> {
+ let index = self.index()?;
+ Ok(self.parent.attributes(
+ &index,
+ gix_worktree::cache::state::attributes::Source::WorktreeThenIdMapping,
+ gix_worktree::cache::state::ignore::Source::WorktreeThenIdMappingIfNotSkipped,
+ overrides,
+ )?)
}
}
}