diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/gix/src/config/tree/sections/protocol.rs | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix/src/config/tree/sections/protocol.rs')
-rw-r--r-- | vendor/gix/src/config/tree/sections/protocol.rs | 54 |
1 files changed, 52 insertions, 2 deletions
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.<name>` subsection pub const NAME_PARAMETER: NameParameter = NameParameter; @@ -14,6 +16,9 @@ impl Protocol { /// The `protocol.allow` key type. pub type Allow = keys::Any<validate::Allow>; +/// The `protocol.version` key. +pub type Version = keys::Any<validate::Version>; + #[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.<url>.helper` key. + /// The `protocol.<name>.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<i64, gix_config::value::Error>>, + ) -> Result<gix_protocol::transport::Protocol, crate::config::key::GenericErrorWithValue> { + 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<dyn std::error::Error + Send + Sync + 'static>> { + 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()), + } + } + } } |