From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix/src/config/snapshot/access.rs | 54 +++++++++++++++++++++- .../gix/src/config/snapshot/credential_helpers.rs | 4 +- vendor/gix/src/config/snapshot/mod.rs | 1 + 3 files changed, 56 insertions(+), 3 deletions(-) (limited to 'vendor/gix/src/config/snapshot') diff --git a/vendor/gix/src/config/snapshot/access.rs b/vendor/gix/src/config/snapshot/access.rs index 1710348a9..7dc593880 100644 --- a/vendor/gix/src/config/snapshot/access.rs +++ b/vendor/gix/src/config/snapshot/access.rs @@ -2,9 +2,11 @@ use std::borrow::Cow; use gix_features::threading::OwnShared; +use gix_macros::momo; +use crate::bstr::ByteSlice; use crate::{ - bstr::BStr, + bstr::{BStr, BString}, config::{CommitAutoRollback, Snapshot, SnapshotMut}, }; @@ -25,6 +27,7 @@ impl<'repo> Snapshot<'repo> { } /// Like [`boolean()`][Self::boolean()], but it will report an error if the value couldn't be interpreted as boolean. + #[momo] pub fn try_boolean<'a>(&self, key: impl Into<&'a BStr>) -> Option> { self.repo.config.resolved.boolean_by_key(key) } @@ -40,6 +43,7 @@ impl<'repo> Snapshot<'repo> { } /// Like [`integer()`][Self::integer()], but it will report an error if the value couldn't be interpreted as boolean. + #[momo] pub fn try_integer<'a>(&self, key: impl Into<&'a BStr>) -> Option> { self.repo.config.resolved.integer_by_key(key) } @@ -47,6 +51,7 @@ impl<'repo> Snapshot<'repo> { /// Return the string at `key`, or `None` if there is no such value. /// /// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust. + #[momo] pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option> { self.repo.config.resolved.string_by_key(key) } @@ -54,11 +59,12 @@ impl<'repo> Snapshot<'repo> { /// Return the trusted and fully interpolated path at `key`, or `None` if there is no such value /// or if no value was found in a trusted file. /// An error occurs if the path could not be interpolated to its final value. + #[momo] pub fn trusted_path<'a>( &self, key: impl Into<&'a BStr>, ) -> Option, gix_config::path::interpolate::Error>> { - let key = gix_config::parse::key(key)?; + let key = gix_config::parse::key(key.into())?; self.repo .config .trusted_file_path(key.section_name, key.subsection_name, key.value_name) @@ -99,6 +105,50 @@ impl<'repo> SnapshotMut<'repo> { self.commit_inner(repo) } + /// Set the value at `key` to `new_value`, possibly creating the section if it doesn't exist yet, or overriding the most recent existing + /// value, which will be returned. + #[momo] + pub fn set_value<'b>( + &mut self, + key: &'static dyn crate::config::tree::Key, + new_value: impl Into<&'b BStr>, + ) -> Result, crate::config::set_value::Error> { + if let Some(crate::config::tree::SubSectionRequirement::Parameter(_)) = key.subsection_requirement() { + return Err(crate::config::set_value::Error::SubSectionRequired); + } + let value = new_value.into(); + key.validate(value)?; + let current = self + .config + .set_raw_value(key.section().name(), None, key.name(), value)?; + Ok(current.map(std::borrow::Cow::into_owned)) + } + + /// Set the value at `key` to `new_value` in the given `subsection`, possibly creating the section and sub-section if it doesn't exist yet, + /// or overriding the most recent existing value, which will be returned. + #[momo] + pub fn set_subsection_value<'a, 'b>( + &mut self, + key: &'static dyn crate::config::tree::Key, + subsection: impl Into<&'a BStr>, + new_value: impl Into<&'b BStr>, + ) -> Result, crate::config::set_value::Error> { + if let Some(crate::config::tree::SubSectionRequirement::Never) = key.subsection_requirement() { + return Err(crate::config::set_value::Error::SubSectionForbidden); + } + let value = new_value.into(); + key.validate(value)?; + + let name = key + .full_name(Some(subsection.into())) + .expect("we know it needs a subsection"); + let key = gix_config::parse::key((**name).as_bstr()).expect("statically known keys can always be parsed"); + let current = + self.config + .set_raw_value(key.section_name, key.subsection_name, key.value_name.to_owned(), value)?; + Ok(current.map(std::borrow::Cow::into_owned)) + } + pub(crate) fn commit_inner( &mut self, repo: &'repo mut crate::Repository, diff --git a/vendor/gix/src/config/snapshot/credential_helpers.rs b/vendor/gix/src/config/snapshot/credential_helpers.rs index c4eef35d6..189e74471 100644 --- a/vendor/gix/src/config/snapshot/credential_helpers.rs +++ b/vendor/gix/src/config/snapshot/credential_helpers.rs @@ -2,6 +2,7 @@ use std::{borrow::Cow, convert::TryFrom}; pub use error::Error; +use crate::config::cache::util::IgnoreEmptyPath; use crate::{ bstr::{ByteSlice, ByteVec}, config::{ @@ -140,7 +141,8 @@ impl Snapshot<'_> { let prompt_options = gix_prompt::Options { askpass: self .trusted_path(Core::ASKPASS.logical_name().as_str()) - .transpose()? + .transpose() + .ignore_empty()? .map(|c| Cow::Owned(c.into_owned())), ..Default::default() } diff --git a/vendor/gix/src/config/snapshot/mod.rs b/vendor/gix/src/config/snapshot/mod.rs index 80ec6f948..de143ea1f 100644 --- a/vendor/gix/src/config/snapshot/mod.rs +++ b/vendor/gix/src/config/snapshot/mod.rs @@ -2,4 +2,5 @@ mod _impls; mod access; /// +#[cfg(feature = "credentials")] pub mod credential_helpers; -- cgit v1.2.3