From dc0db358abe19481e475e10c32149b53370f1a1c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:31 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix/src/config/cache/access.rs | 3 +- vendor/gix/src/config/cache/init.rs | 18 +++--- vendor/gix/src/config/cache/util.rs | 12 ++-- vendor/gix/src/config/mod.rs | 4 +- vendor/gix/src/config/overrides.rs | 2 +- .../gix/src/config/snapshot/credential_helpers.rs | 2 +- vendor/gix/src/config/tree/keys.rs | 7 ++- vendor/gix/src/config/tree/mod.rs | 13 +++-- vendor/gix/src/config/tree/sections/core.rs | 6 +- vendor/gix/src/config/tree/sections/fetch.rs | 68 ++++++++++++++++++++++ vendor/gix/src/config/tree/sections/gitoxide.rs | 17 ++++-- vendor/gix/src/config/tree/sections/index.rs | 10 ++-- vendor/gix/src/config/tree/sections/mod.rs | 5 ++ vendor/gix/src/config/tree/sections/protocol.rs | 54 ++++++++++++++++- 14 files changed, 186 insertions(+), 35 deletions(-) create mode 100644 vendor/gix/src/config/tree/sections/fetch.rs (limited to 'vendor/gix/src/config') diff --git a/vendor/gix/src/config/cache/access.rs b/vendor/gix/src/config/cache/access.rs index 77324efe3..cea56f973 100644 --- a/vendor/gix/src/config/cache/access.rs +++ b/vendor/gix/src/config/cache/access.rs @@ -47,8 +47,7 @@ impl Cache { .get_or_init(|| { self.resolved .string_by_key(Gitoxide::USER_AGENT.logical_name().as_str()) - .map(|s| s.to_string()) - .unwrap_or_else(|| crate::env::agent().into()) + .map_or_else(|| crate::env::agent().into(), |s| s.to_string()) }) .to_owned(); ("agent", Some(gix_protocol::agent(agent).into())) diff --git a/vendor/gix/src/config/cache/init.rs b/vendor/gix/src/config/cache/init.rs index ee20e0354..6fcbcc4ec 100644 --- a/vendor/gix/src/config/cache/init.rs +++ b/vendor/gix/src/config/cache/init.rs @@ -151,7 +151,7 @@ impl Cache { lenient_config, )?; let object_kind_hint = util::disambiguate_hint(&config, lenient_config)?; - let (pack_cache_bytes, object_cache_bytes) = + let (static_pack_cache_limit_bytes, pack_cache_bytes, object_cache_bytes) = util::parse_object_caches(&config, lenient_config, filter_config_section)?; // NOTE: When adding a new initial cache, consider adjusting `reread_values_and_clear_caches()` as well. Ok(Cache { @@ -159,6 +159,7 @@ impl Cache { use_multi_pack_index, object_hash, object_kind_hint, + static_pack_cache_limit_bytes, pack_cache_bytes, object_cache_bytes, reflog, @@ -222,8 +223,11 @@ impl Cache { self.url_rewrite = Default::default(); self.diff_renames = Default::default(); self.diff_algorithm = Default::default(); - (self.pack_cache_bytes, self.object_cache_bytes) = - util::parse_object_caches(config, self.lenient_config, self.filter_config_section)?; + ( + self.static_pack_cache_limit_bytes, + self.pack_cache_bytes, + self.object_cache_bytes, + ) = util::parse_object_caches(config, self.lenient_config, self.filter_config_section)?; #[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))] { self.url_scheme = Default::default(); @@ -422,10 +426,6 @@ fn apply_environment_overrides( Some(Cow::Borrowed("objects".into())), objects, &[ - { - let key = &gitoxide::Objects::NO_REPLACE; - (env(key), key.name) - }, { let key = &gitoxide::Objects::REPLACE_REF_BASE; (env(key), key.name) @@ -487,6 +487,10 @@ fn apply_environment_overrides( let key = &Core::SSH_COMMAND; (env(key), key.name, git_prefix) }, + { + let key = &Core::USE_REPLACE_REFS; + (env(key), key.name, objects) + }, ] { if let Some(value) = var_as_bstring(var, permission) { section.push_with_comment( diff --git a/vendor/gix/src/config/cache/util.rs b/vendor/gix/src/config/cache/util.rs index d5a0a4acb..7c478fcf9 100644 --- a/vendor/gix/src/config/cache/util.rs +++ b/vendor/gix/src/config/cache/util.rs @@ -40,8 +40,7 @@ pub(crate) fn config_bool( ); config .boolean_by_key(key_str) - .map(|res| key.enrich_error(res)) - .unwrap_or(Ok(default)) + .map_or(Ok(default), |res| key.enrich_error(res)) .map_err(Error::from) .with_lenient_default(lenient) } @@ -73,7 +72,12 @@ pub(crate) fn parse_object_caches( config: &gix_config::File<'static>, lenient: bool, mut filter_config_section: fn(&gix_config::file::Metadata) -> bool, -) -> Result<(Option, usize), Error> { +) -> Result<(Option, Option, usize), Error> { + let static_pack_cache_limit = config + .integer_filter_by_key("core.deltaBaseCacheLimit", &mut filter_config_section) + .map(|res| gitoxide::Core::DEFAULT_PACK_CACHE_MEMORY_LIMIT.try_into_usize(res)) + .transpose() + .with_leniency(lenient)?; let pack_cache_bytes = config .integer_filter_by_key("core.deltaBaseCacheLimit", &mut filter_config_section) .map(|res| Core::DELTA_BASE_CACHE_LIMIT.try_into_usize(res)) @@ -85,7 +89,7 @@ pub(crate) fn parse_object_caches( .transpose() .with_leniency(lenient)? .unwrap_or_default(); - Ok((pack_cache_bytes, object_cache_bytes)) + Ok((static_pack_cache_limit, pack_cache_bytes, object_cache_bytes)) } pub(crate) fn parse_core_abbrev( diff --git a/vendor/gix/src/config/mod.rs b/vendor/gix/src/config/mod.rs index 5da569605..3353806f8 100644 --- a/vendor/gix/src/config/mod.rs +++ b/vendor/gix/src/config/mod.rs @@ -438,7 +438,7 @@ pub mod transport { /// Utility type to keep pre-obtained configuration values, only for those required during initial setup /// and other basic operations that are common enough to warrant a permanent cache. /// -/// All other values are obtained lazily using OnceCell. +/// All other values are obtained lazily using `OnceCell`. #[derive(Clone)] pub(crate) struct Cache { pub resolved: crate::Config, @@ -470,6 +470,8 @@ pub(crate) struct Cache { pub(crate) pack_cache_bytes: Option, /// The amount of bytes to use for caching whole objects, or 0 to turn it off entirely. pub(crate) object_cache_bytes: usize, + /// The amount of bytes we can hold in our static LRU cache. Otherwise, go with the defaults. + pub(crate) static_pack_cache_limit_bytes: Option, /// The config section filter from the options used to initialize this instance. Keep these in sync! filter_config_section: fn(&gix_config::file::Metadata) -> bool, /// The object kind to pick if a prefix is ambiguous. diff --git a/vendor/gix/src/config/overrides.rs b/vendor/gix/src/config/overrides.rs index f43e8471b..4bdf4a13f 100644 --- a/vendor/gix/src/config/overrides.rs +++ b/vendor/gix/src/config/overrides.rs @@ -2,7 +2,7 @@ use std::convert::TryFrom; use crate::bstr::{BStr, BString, ByteSlice}; -/// The error returned by [SnapshotMut::apply_cli_overrides()][crate::config::SnapshotMut::append_config()]. +/// The error returned by [`SnapshotMut::apply_cli_overrides()`][crate::config::SnapshotMut::append_config()]. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] pub enum Error { diff --git a/vendor/gix/src/config/snapshot/credential_helpers.rs b/vendor/gix/src/config/snapshot/credential_helpers.rs index 5a07e9fe2..c4eef35d6 100644 --- a/vendor/gix/src/config/snapshot/credential_helpers.rs +++ b/vendor/gix/src/config/snapshot/credential_helpers.rs @@ -13,7 +13,7 @@ use crate::{ mod error { use crate::bstr::BString; - /// The error returned by [Snapshot::credential_helpers()][super::Snapshot::credential_helpers()]. + /// The error returned by [`Snapshot::credential_helpers()`][super::Snapshot::credential_helpers()]. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] pub enum Error { diff --git a/vendor/gix/src/config/tree/keys.rs b/vendor/gix/src/config/tree/keys.rs index 1cdd187d0..b03fa49c6 100644 --- a/vendor/gix/src/config/tree/keys.rs +++ b/vendor/gix/src/config/tree/keys.rs @@ -179,10 +179,10 @@ pub type Url = Any; /// A key that represents a UTF-8 string. pub type String = Any; -/// A key that represents a RefSpec for pushing. +/// A key that represents a `RefSpec` for pushing. pub type PushRefSpec = Any; -/// A key that represents a RefSpec for fetching. +/// A key that represents a `RefSpec` for fetching. pub type FetchRefSpec = Any; mod duration { @@ -511,7 +511,8 @@ pub mod validate { gix_config::Integer::try_from(value)? .to_decimal() .ok_or_else(|| format!("integer {value} cannot be represented as `usize`"))?, - )?; + ) + .map_err(|_| "cannot use sign for unsigned integer")?; Ok(()) } } diff --git a/vendor/gix/src/config/tree/mod.rs b/vendor/gix/src/config/tree/mod.rs index b378b8c49..3f69ccb97 100644 --- a/vendor/gix/src/config/tree/mod.rs +++ b/vendor/gix/src/config/tree/mod.rs @@ -34,6 +34,8 @@ pub(crate) mod root { pub const DIFF: sections::Diff = sections::Diff; /// The `extensions` section. pub const EXTENSIONS: sections::Extensions = sections::Extensions; + /// The `fetch` section. + pub const FETCH: sections::Fetch = sections::Fetch; /// The `gitoxide` section. pub const GITOXIDE: sections::Gitoxide = sections::Gitoxide; /// The `http` section. @@ -69,6 +71,7 @@ pub(crate) mod root { &Self::CREDENTIAL, &Self::DIFF, &Self::EXTENSIONS, + &Self::FETCH, &Self::GITOXIDE, &Self::HTTP, &Self::INDEX, @@ -87,9 +90,9 @@ pub(crate) mod root { mod sections; pub use sections::{ - branch, checkout, core, credential, diff, extensions, gitoxide, http, index, protocol, remote, ssh, Author, Branch, - Checkout, Clone, Committer, Core, Credential, Diff, Extensions, Gitoxide, Http, Index, Init, Pack, Protocol, - Remote, Safe, Ssh, Url, User, + branch, checkout, core, credential, diff, extensions, fetch, gitoxide, http, index, protocol, remote, ssh, Author, + Branch, Checkout, Clone, Committer, Core, Credential, Diff, Extensions, Fetch, Gitoxide, Http, Index, Init, Pack, + Protocol, Remote, Safe, Ssh, Url, User, }; /// Generic value implementations for static instantiation. @@ -99,7 +102,7 @@ pub mod keys; pub mod key { /// pub mod validate { - /// The error returned by [Key::validate()][crate::config::tree::Key::validate()]. + /// The error returned by [`Key::validate()`][crate::config::tree::Key::validate()]. #[derive(Debug, thiserror::Error)] #[error(transparent)] #[allow(missing_docs)] @@ -110,7 +113,7 @@ pub mod key { } /// pub mod validate_assignment { - /// The error returned by [Key::validated_assignment*()][crate::config::tree::Key::validated_assignment_fmt()]. + /// The error returned by [`Key::validated_assignment`*()][crate::config::tree::Key::validated_assignment_fmt()]. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] pub enum Error { diff --git a/vendor/gix/src/config/tree/sections/core.rs b/vendor/gix/src/config/tree/sections/core.rs index 6ea0580e1..93d2fcd01 100644 --- a/vendor/gix/src/config/tree/sections/core.rs +++ b/vendor/gix/src/config/tree/sections/core.rs @@ -36,7 +36,7 @@ impl Core { LogAllRefUpdates::new_with_validate("logAllRefUpdates", &config::Tree::CORE, validate::LogAllRefUpdates); /// The `core.precomposeUnicode` key. /// - /// Needs application to use [env::args_os][crate::env::args_os()] to conform all input paths before they are used. + /// Needs application to use [`env::args_os`][crate::env::args_os()] to conform all input paths before they are used. pub const PRECOMPOSE_UNICODE: keys::Boolean = keys::Boolean::new_boolean("precomposeUnicode", &config::Tree::CORE) .with_note("application needs to conform all program input by using gix::env::args_os()"); /// The `core.repositoryFormatVersion` key. @@ -63,6 +63,9 @@ impl Core { /// The `core.sshCommand` key. pub const SSH_COMMAND: keys::Executable = keys::Executable::new_executable("sshCommand", &config::Tree::CORE) .with_environment_override("GIT_SSH_COMMAND"); + /// The `core.useReplaceRefs` key. + pub const USE_REPLACE_REFS: keys::Boolean = keys::Boolean::new_boolean("useReplaceRefs", &config::Tree::CORE) + .with_environment_override("GIT_NO_REPLACE_OBJECTS"); } impl Section for Core { @@ -92,6 +95,7 @@ impl Section for Core { &Self::EXCLUDES_FILE, &Self::ATTRIBUTES_FILE, &Self::SSH_COMMAND, + &Self::USE_REPLACE_REFS, ] } } diff --git a/vendor/gix/src/config/tree/sections/fetch.rs b/vendor/gix/src/config/tree/sections/fetch.rs new file mode 100644 index 000000000..117cabfd2 --- /dev/null +++ b/vendor/gix/src/config/tree/sections/fetch.rs @@ -0,0 +1,68 @@ +use crate::{ + config, + config::tree::{keys, Fetch, Key, Section}, +}; + +impl Fetch { + /// The `fetch.negotiationAlgorithm` key. + pub const NEGOTIATION_ALGORITHM: NegotiationAlgorithm = NegotiationAlgorithm::new_with_validate( + "negotiationAlgorithm", + &config::Tree::FETCH, + validate::NegotiationAlgorithm, + ); +} + +impl Section for Fetch { + fn name(&self) -> &str { + "fetch" + } + + fn keys(&self) -> &[&dyn Key] { + &[&Self::NEGOTIATION_ALGORITHM] + } +} + +/// The `fetch.negotiationAlgorithm` key. +pub type NegotiationAlgorithm = keys::Any; + +mod algorithm { + use std::borrow::Cow; + + use gix_object::bstr::ByteSlice; + + use crate::{ + bstr::BStr, + config::{key::GenericErrorWithValue, tree::sections::fetch::NegotiationAlgorithm}, + remote::fetch::negotiate, + }; + + impl NegotiationAlgorithm { + /// Derive the negotiation algorithm identified by `name`, case-sensitively. + pub fn try_into_negotiation_algorithm( + &'static self, + name: Cow<'_, BStr>, + ) -> Result { + Ok(match name.as_ref().as_bytes() { + b"noop" => negotiate::Algorithm::Noop, + b"consecutive" | b"default" => negotiate::Algorithm::Consecutive, + b"skipping" => negotiate::Algorithm::Skipping, + _ => return Err(GenericErrorWithValue::from_value(self, name.into_owned())), + }) + } + } +} + +mod validate { + use crate::{ + bstr::BStr, + config::tree::{keys, Fetch}, + }; + + pub struct NegotiationAlgorithm; + impl keys::Validate for NegotiationAlgorithm { + fn validate(&self, value: &BStr) -> Result<(), Box> { + Fetch::NEGOTIATION_ALGORITHM.try_into_negotiation_algorithm(value.into())?; + Ok(()) + } + } +} diff --git a/vendor/gix/src/config/tree/sections/gitoxide.rs b/vendor/gix/src/config/tree/sections/gitoxide.rs index 7d60f1287..f07d494fb 100644 --- a/vendor/gix/src/config/tree/sections/gitoxide.rs +++ b/vendor/gix/src/config/tree/sections/gitoxide.rs @@ -67,6 +67,11 @@ mod subsections { pub struct Core; impl Core { + /// The `gitoxide.core.defaultPackCacheMemoryLimit` key. + pub const DEFAULT_PACK_CACHE_MEMORY_LIMIT: keys::UnsignedInteger = + keys::UnsignedInteger::new_unsigned_integer("defaultPackCacheMemoryLimit", &Gitoxide::CORE).with_note( + "If unset, we default to 96MB memory cap for the default 64 slot LRU cache for object deltas.", + ); /// The `gitoxide.core.useNsec` key. pub const USE_NSEC: keys::Boolean = keys::Boolean::new_boolean("useNsec", &Gitoxide::CORE) .with_note("A runtime version of the USE_NSEC build flag."); @@ -89,7 +94,12 @@ mod subsections { } fn keys(&self) -> &[&dyn Key] { - &[&Self::USE_NSEC, &Self::USE_STDEV, &Self::SHALLOW_FILE] + &[ + &Self::DEFAULT_PACK_CACHE_MEMORY_LIMIT, + &Self::USE_NSEC, + &Self::USE_STDEV, + &Self::SHALLOW_FILE, + ] } fn parent(&self) -> Option<&dyn Section> { @@ -307,8 +317,7 @@ mod subsections { .with_note("If unset or 0, there is no object cache") .with_environment_override("GITOXIDE_OBJECT_CACHE_MEMORY"); /// The `gitoxide.objects.noReplace` key. - pub const NO_REPLACE: keys::Boolean = keys::Boolean::new_boolean("noReplace", &Gitoxide::OBJECTS) - .with_environment_override("GIT_NO_REPLACE_OBJECTS"); + pub const NO_REPLACE: keys::Boolean = keys::Boolean::new_boolean("noReplace", &Gitoxide::OBJECTS); /// The `gitoxide.objects.replaceRefBase` key. pub const REPLACE_REF_BASE: keys::Any = keys::Any::new("replaceRefBase", &Gitoxide::OBJECTS).with_environment_override("GIT_REPLACE_REF_BASE"); @@ -320,7 +329,7 @@ mod subsections { } fn keys(&self) -> &[&dyn Key] { - &[&Self::CACHE_LIMIT, &Self::NO_REPLACE, &Self::REPLACE_REF_BASE] + &[&Self::CACHE_LIMIT, &Self::REPLACE_REF_BASE] } fn parent(&self) -> Option<&dyn Section> { diff --git a/vendor/gix/src/config/tree/sections/index.rs b/vendor/gix/src/config/tree/sections/index.rs index d03322247..08f7ec1bd 100644 --- a/vendor/gix/src/config/tree/sections/index.rs +++ b/vendor/gix/src/config/tree/sections/index.rs @@ -13,12 +13,14 @@ impl Index { pub type IndexThreads = keys::Any; mod index_threads { - use crate::bstr::BStr; - use crate::config; - use crate::config::key::GenericErrorWithValue; - use crate::config::tree::index::IndexThreads; use std::borrow::Cow; + use crate::{ + bstr::BStr, + config, + config::{key::GenericErrorWithValue, tree::index::IndexThreads}, + }; + impl IndexThreads { /// Parse `value` into the amount of threads to use, with `1` being single-threaded, or `0` indicating /// to select the amount of threads, with any other number being the specific amount of threads to use. diff --git a/vendor/gix/src/config/tree/sections/mod.rs b/vendor/gix/src/config/tree/sections/mod.rs index 9f0a50c93..ebf24a8b7 100644 --- a/vendor/gix/src/config/tree/sections/mod.rs +++ b/vendor/gix/src/config/tree/sections/mod.rs @@ -45,6 +45,11 @@ pub mod diff; pub struct Extensions; pub mod extensions; +/// The `fetch` top-level section. +#[derive(Copy, Clone, Default)] +pub struct Fetch; +pub mod fetch; + /// The `gitoxide` top-level section. #[derive(Copy, Clone, Default)] pub struct Gitoxide; diff --git a/vendor/gix/src/config/tree/sections/protocol.rs b/vendor/gix/src/config/tree/sections/protocol.rs index 58e907b0f..a0510f2b8 100644 --- a/vendor/gix/src/config/tree/sections/protocol.rs +++ b/vendor/gix/src/config/tree/sections/protocol.rs @@ -6,6 +6,8 @@ use crate::{ impl Protocol { /// The `protocol.allow` key. pub const ALLOW: Allow = Allow::new_with_validate("allow", &config::Tree::PROTOCOL, validate::Allow); + /// The `protocol.version` key. + pub const VERSION: Version = Version::new_with_validate("version", &config::Tree::PROTOCOL, validate::Version); /// The `protocol.` subsection pub const NAME_PARAMETER: NameParameter = NameParameter; @@ -14,6 +16,9 @@ impl Protocol { /// The `protocol.allow` key type. pub type Allow = keys::Any; +/// The `protocol.version` key. +pub type Version = keys::Any; + #[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))] mod allow { use std::borrow::Cow; @@ -39,7 +44,7 @@ mod allow { pub struct NameParameter; impl NameParameter { - /// The `credential..helper` key. + /// The `protocol..allow` key. pub const ALLOW: Allow = Allow::new_with_validate("allow", &Protocol::NAME_PARAMETER, validate::Allow); } @@ -63,7 +68,7 @@ impl Section for Protocol { } fn keys(&self) -> &[&dyn Key] { - &[&Self::ALLOW] + &[&Self::ALLOW, &Self::VERSION] } fn sub_sections(&self) -> &[&dyn Section] { @@ -71,6 +76,38 @@ impl Section for Protocol { } } +mod key_impls { + impl super::Version { + /// Convert `value` into the corresponding protocol version, possibly applying the correct default. + #[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))] + pub fn try_into_protocol_version( + &'static self, + value: Option>, + ) -> Result { + let value = match value { + None => return Ok(gix_protocol::transport::Protocol::V2), + Some(v) => v, + }; + Ok(match value { + Ok(0) => gix_protocol::transport::Protocol::V0, + Ok(1) => gix_protocol::transport::Protocol::V1, + Ok(2) => gix_protocol::transport::Protocol::V2, + Ok(other) => { + return Err(crate::config::key::GenericErrorWithValue::from_value( + self, + other.to_string().into(), + )) + } + Err(err) => { + return Err( + crate::config::key::GenericErrorWithValue::from_value(self, "unknown".into()).with_source(err), + ) + } + }) + } + } +} + mod validate { use crate::{bstr::BStr, config::tree::keys}; @@ -82,4 +119,17 @@ mod validate { Ok(()) } } + + pub struct Version; + impl keys::Validate for Version { + fn validate(&self, value: &BStr) -> Result<(), Box> { + let value = gix_config::Integer::try_from(value)? + .to_decimal() + .ok_or_else(|| format!("integer {value} cannot be represented as integer"))?; + match value { + 0 | 1 | 2 => Ok(()), + _ => Err(format!("protocol version {value} is unknown").into()), + } + } + } } -- cgit v1.2.3