summaryrefslogtreecommitdiffstats
path: root/vendor/gix/src/config/snapshot
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix/src/config/snapshot
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-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/config/snapshot')
-rw-r--r--vendor/gix/src/config/snapshot/access.rs54
-rw-r--r--vendor/gix/src/config/snapshot/credential_helpers.rs4
-rw-r--r--vendor/gix/src/config/snapshot/mod.rs1
3 files changed, 56 insertions, 3 deletions
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<Result<bool, gix_config::value::Error>> {
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<Result<i64, gix_config::value::Error>> {
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<Cow<'_, BStr>> {
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<Result<Cow<'_, std::path::Path>, 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<Option<BString>, 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<Option<BString>, 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;