diff options
Diffstat (limited to 'vendor/gix/src/config/cache')
-rw-r--r-- | vendor/gix/src/config/cache/access.rs | 134 | ||||
-rw-r--r-- | vendor/gix/src/config/cache/incubate.rs | 34 | ||||
-rw-r--r-- | vendor/gix/src/config/cache/init.rs | 71 | ||||
-rw-r--r-- | vendor/gix/src/config/cache/util.rs | 3 |
4 files changed, 174 insertions, 68 deletions
diff --git a/vendor/gix/src/config/cache/access.rs b/vendor/gix/src/config/cache/access.rs index 8244eaf27..77324efe3 100644 --- a/vendor/gix/src/config/cache/access.rs +++ b/vendor/gix/src/config/cache/access.rs @@ -1,6 +1,7 @@ #![allow(clippy::result_large_err)] use std::{borrow::Cow, path::PathBuf, time::Duration}; +use gix_attributes::Source; use gix_lock::acquire::Fail; use crate::{ @@ -9,7 +10,7 @@ use crate::{ config::{ cache::util::{ApplyLeniency, ApplyLeniencyDefault}, checkout_options, - tree::{Checkout, Core, Key}, + tree::{gitoxide, Checkout, Core, Key}, Cache, }, remote, @@ -137,7 +138,7 @@ impl Cache { pub(crate) fn checkout_options( &self, git_dir: &std::path::Path, - ) -> Result<gix_worktree::index::checkout::Options, checkout_options::Error> { + ) -> Result<gix_worktree::checkout::Options, checkout_options::Error> { fn boolean( me: &Cache, full_key: &str, @@ -154,63 +155,118 @@ impl Cache { .unwrap_or(default)) } - fn assemble_attribute_globals( - me: &Cache, - _git_dir: &std::path::Path, - ) -> Result<gix_attributes::MatchGroup, checkout_options::Error> { - let _attributes_file = match me - .trusted_file_path("core", None, Core::ATTRIBUTES_FILE.name) - .transpose()? - { - Some(attributes) => Some(attributes.into_owned()), - None => me.xdg_config_path("attributes").ok().flatten(), - }; - // TODO: implement gix_attributes::MatchGroup::<gix_attributes::Attributes>::from_git_dir(), similar to what's done for `Ignore`. - Ok(Default::default()) - } - let thread_limit = self.apply_leniency( self.resolved .integer_filter_by_key("checkout.workers", &mut self.filter_config_section.clone()) .map(|value| Checkout::WORKERS.try_from_workers(value)), )?; - Ok(gix_worktree::index::checkout::Options { - fs: gix_worktree::fs::Capabilities { - precompose_unicode: boolean(self, "core.precomposeUnicode", &Core::PRECOMPOSE_UNICODE, false)?, - ignore_case: boolean(self, "core.ignoreCase", &Core::IGNORE_CASE, false)?, - executable_bit: boolean(self, "core.fileMode", &Core::FILE_MODE, true)?, - symlink: boolean(self, "core.symlinks", &Core::SYMLINKS, true)?, - }, + let capabilities = gix_fs::Capabilities { + precompose_unicode: boolean(self, "core.precomposeUnicode", &Core::PRECOMPOSE_UNICODE, false)?, + ignore_case: boolean(self, "core.ignoreCase", &Core::IGNORE_CASE, false)?, + executable_bit: boolean(self, "core.fileMode", &Core::FILE_MODE, true)?, + symlink: boolean(self, "core.symlinks", &Core::SYMLINKS, true)?, + }; + Ok(gix_worktree::checkout::Options { + attributes: self + .assemble_attribute_globals( + git_dir, + gix_worktree::cache::state::attributes::Source::IdMappingThenWorktree, + self.attributes, + )? + .0, + fs: capabilities, thread_limit, destination_is_initially_empty: false, overwrite_existing: false, keep_going: false, - trust_ctime: boolean(self, "core.trustCTime", &Core::TRUST_C_TIME, true)?, - check_stat: self - .apply_leniency( - self.resolved - .string("core", None, "checkStat") - .map(|v| Core::CHECK_STAT.try_into_checkstat(v)), - )? - .unwrap_or(true), - attribute_globals: assemble_attribute_globals(self, git_dir)?, + stat_options: gix_index::entry::stat::Options { + trust_ctime: boolean(self, "core.trustCTime", &Core::TRUST_C_TIME, true)?, + use_nsec: boolean(self, "gitoxide.core.useNsec", &gitoxide::Core::USE_NSEC, false)?, + use_stdev: boolean(self, "gitoxide.core.useStdev", &gitoxide::Core::USE_STDEV, false)?, + check_stat: self + .apply_leniency( + self.resolved + .string("core", None, "checkStat") + .map(|v| Core::CHECK_STAT.try_into_checkstat(v)), + )? + .unwrap_or(true), + }, }) } + + pub(crate) fn assemble_exclude_globals( + &self, + git_dir: &std::path::Path, + overrides: Option<gix_ignore::Search>, + source: gix_worktree::cache::state::ignore::Source, + buf: &mut Vec<u8>, + ) -> Result<gix_worktree::cache::state::Ignore, config::exclude_stack::Error> { + let excludes_file = match self.excludes_file().transpose()? { + Some(user_path) => Some(user_path), + None => self.xdg_config_path("ignore")?, + }; + Ok(gix_worktree::cache::state::Ignore::new( + overrides.unwrap_or_default(), + gix_ignore::Search::from_git_dir(git_dir, excludes_file, buf)?, + None, + source, + )) + } + // TODO: at least one test, maybe related to core.attributesFile configuration. + pub(crate) fn assemble_attribute_globals( + &self, + git_dir: &std::path::Path, + source: gix_worktree::cache::state::attributes::Source, + attributes: crate::open::permissions::Attributes, + ) -> Result<(gix_worktree::cache::state::Attributes, Vec<u8>), config::attribute_stack::Error> { + let configured_or_user_attributes = match self + .trusted_file_path("core", None, Core::ATTRIBUTES_FILE.name) + .transpose()? + { + Some(attributes) => Some(attributes), + None => { + if attributes.git { + self.xdg_config_path("attributes").ok().flatten().map(Cow::Owned) + } else { + None + } + } + }; + let attribute_files = [gix_attributes::Source::GitInstallation, gix_attributes::Source::System] + .into_iter() + .filter(|source| match source { + Source::GitInstallation => attributes.git_binary, + Source::System => attributes.system, + Source::Git | Source::Local => unreachable!("we don't offer turning this off right now"), + }) + .filter_map(|source| source.storage_location(&mut Self::make_source_env(self.environment))) + .chain(configured_or_user_attributes); + let info_attributes_path = git_dir.join("info").join("attributes"); + let mut buf = Vec::new(); + let mut collection = gix_attributes::search::MetadataCollection::default(); + let res = gix_worktree::cache::state::Attributes::new( + gix_attributes::Search::new_globals(attribute_files, &mut buf, &mut collection)?, + Some(info_attributes_path), + source, + collection, + ); + Ok((res, buf)) + } + pub(crate) fn xdg_config_path( &self, resource_file_name: &str, ) -> Result<Option<PathBuf>, gix_sec::permission::Error<PathBuf>> { std::env::var_os("XDG_CONFIG_HOME") - .map(|path| (PathBuf::from(path), &self.xdg_config_home_env)) + .map(|path| (PathBuf::from(path), &self.environment.xdg_config_home)) .or_else(|| { - std::env::var_os("HOME").map(|path| { + gix_path::env::home_dir().map(|mut p| { ( { - let mut p = PathBuf::from(path); p.push(".config"); p }, - &self.home_env, + &self.environment.home, ) }) }) @@ -226,8 +282,6 @@ impl Cache { /// We never fail for here even if the permission is set to deny as we `gix-config` will fail later /// if it actually wants to use the home directory - we don't want to fail prematurely. pub(crate) fn home_dir(&self) -> Option<PathBuf> { - std::env::var_os("HOME") - .map(PathBuf::from) - .and_then(|path| self.home_env.check_opt(path)) + gix_path::env::home_dir().and_then(|path| self.environment.home.check_opt(path)) } } diff --git a/vendor/gix/src/config/cache/incubate.rs b/vendor/gix/src/config/cache/incubate.rs index 047f2132b..44c537b50 100644 --- a/vendor/gix/src/config/cache/incubate.rs +++ b/vendor/gix/src/config/cache/incubate.rs @@ -30,6 +30,7 @@ impl StageOne { gix_config::Source::Local, git_dir_trust, lossy, + lenient, )?; // Note that we assume the repo is bare by default unless we are told otherwise. This is relevant if @@ -64,6 +65,7 @@ impl StageOne { gix_config::Source::Worktree, git_dir_trust, lossy, + lenient, )?; config.append(worktree_config); }; @@ -86,24 +88,48 @@ fn load_config( source: gix_config::Source, git_dir_trust: gix_sec::Trust, lossy: Option<bool>, + lenient: bool, ) -> Result<gix_config::File<'static>, Error> { - buf.clear(); let metadata = gix_config::file::Metadata::from(source) .at(&config_path) .with(git_dir_trust); let mut file = match std::fs::File::open(&config_path) { Ok(f) => f, Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(gix_config::File::new(metadata)), - Err(err) => return Err(err.into()), + Err(err) => { + let err = Error::Io { + source: err, + path: config_path, + }; + if lenient { + log::warn!("ignoring: {err:#?}"); + return Ok(gix_config::File::new(metadata)); + } else { + return Err(err); + } + } + }; + + buf.clear(); + if let Err(err) = std::io::copy(&mut file, buf) { + let err = Error::Io { + source: err, + path: config_path, + }; + if lenient { + log::warn!("ignoring: {err:#?}"); + buf.clear(); + } else { + return Err(err); + } }; - std::io::copy(&mut file, buf)?; let config = gix_config::File::from_bytes_owned( buf, metadata, gix_config::file::init::Options { includes: gix_config::file::includes::Options::no_follow(), - ..util::base_options(lossy) + ..util::base_options(lossy, lenient) }, )?; diff --git a/vendor/gix/src/config/cache/init.rs b/vendor/gix/src/config/cache/init.rs index dc76f78bb..ee20e0354 100644 --- a/vendor/gix/src/config/cache/init.rs +++ b/vendor/gix/src/config/cache/init.rs @@ -1,5 +1,5 @@ #![allow(clippy::result_large_err)] -use std::borrow::Cow; +use std::{borrow::Cow, ffi::OsString}; use gix_sec::Permission; @@ -12,7 +12,7 @@ use crate::{ tree::{gitoxide, Core, Http}, Cache, }, - repository, + open, }; /// Initialization @@ -32,23 +32,24 @@ impl Cache { filter_config_section: fn(&gix_config::file::Metadata) -> bool, git_install_dir: Option<&std::path::Path>, home: Option<&std::path::Path>, - repository::permissions::Environment { + environment @ open::permissions::Environment { git_prefix, - home: home_env, - xdg_config_home: xdg_config_home_env, ssh_prefix: _, + xdg_config_home: _, + home: _, http_transport, identity, objects, - }: repository::permissions::Environment, - repository::permissions::Config { + }: open::permissions::Environment, + attributes: open::permissions::Attributes, + open::permissions::Config { git_binary: use_installation, system: use_system, git: use_git, user: use_user, env: use_env, includes: use_includes, - }: repository::permissions::Config, + }: open::permissions::Config, lenient_config: bool, api_config_overrides: &[BString], cli_config_overrides: &[BString], @@ -65,12 +66,10 @@ impl Cache { } else { gix_config::file::includes::Options::no_follow() }, - ..util::base_options(lossy) + ..util::base_options(lossy, lenient_config) }; let config = { - let home_env = &home_env; - let xdg_config_home_env = &xdg_config_home_env; let git_prefix = &git_prefix; let metas = [ gix_config::source::Kind::GitInstallation, @@ -88,15 +87,7 @@ impl Cache { _ => {} } source - .storage_location(&mut |name| { - match name { - git_ if git_.starts_with("GIT_") => Some(git_prefix), - "XDG_CONFIG_HOME" => Some(xdg_config_home_env), - "HOME" => Some(home_env), - _ => None, - } - .and_then(|perm| perm.check_opt(name).and_then(std::env::var_os)) - }) + .storage_location(&mut Self::make_source_env(environment)) .map(|p| (source, p.into_owned())) }) .map(|(source, path)| gix_config::file::Metadata { @@ -118,7 +109,7 @@ impl Cache { ) .map_err(|err| match err { gix_config::file::init::from_paths::Error::Init(err) => Error::from(err), - gix_config::file::init::from_paths::Error::Io(err) => err.into(), + gix_config::file::init::from_paths::Error::Io { source, path } => Error::Io { source, path }, })? .unwrap_or_default(); @@ -175,9 +166,9 @@ impl Cache { ignore_case, hex_len, filter_config_section, - xdg_config_home_env, - home_env, + environment, lenient_config, + attributes, user_agent: Default::default(), personas: Default::default(), url_rewrite: Default::default(), @@ -240,6 +231,31 @@ impl Cache { Ok(()) } + + pub(crate) fn make_source_env( + crate::open::permissions::Environment { + xdg_config_home, + git_prefix, + home, + .. + }: open::permissions::Environment, + ) -> impl FnMut(&str) -> Option<OsString> { + move |name| { + match name { + git_ if git_.starts_with("GIT_") => Some(git_prefix), + "XDG_CONFIG_HOME" => Some(xdg_config_home), + "HOME" => { + return if home.is_allowed() { + gix_path::env::home_dir().map(Into::into) + } else { + None + } + } + _ => None, + } + .and_then(|perm| perm.check_opt(name).and_then(gix_path::env::var)) + } + } } impl crate::Repository { @@ -349,6 +365,15 @@ fn apply_environment_overrides( ), ( "gitoxide", + Some(Cow::Borrowed("core".into())), + git_prefix, + &[{ + let key = &gitoxide::Core::SHALLOW_FILE; + (env(key), key.name) + }], + ), + ( + "gitoxide", Some(Cow::Borrowed("author".into())), identity, &[ diff --git a/vendor/gix/src/config/cache/util.rs b/vendor/gix/src/config/cache/util.rs index c12f850e6..d5a0a4acb 100644 --- a/vendor/gix/src/config/cache/util.rs +++ b/vendor/gix/src/config/cache/util.rs @@ -17,9 +17,10 @@ pub(crate) fn interpolate_context<'a>( } } -pub(crate) fn base_options(lossy: Option<bool>) -> gix_config::file::init::Options<'static> { +pub(crate) fn base_options(lossy: Option<bool>, lenient: bool) -> gix_config::file::init::Options<'static> { gix_config::file::init::Options { lossy: lossy.unwrap_or(!cfg!(debug_assertions)), + ignore_io_errors: lenient, ..Default::default() } } |