gix 0.88.0

Interact with git repositories just like git would
Documentation
use crate::{
    config,
    config::tree::{Key, Section, Ssh, keys},
};

impl Ssh {
    /// The `ssh.variant` key
    pub const VARIANT: Variant = Variant::new_with_validate("variant", &config::Tree::SSH, validate::Variant)
        .with_environment_override("GIT_SSH_VARIANT")
        .with_deviation("We error if a variant is chosen that we don't know, as opposed to defaulting to 'ssh'");
}

/// The `ssh.variant` key.
pub type Variant = keys::Any<validate::Variant>;

#[cfg(feature = "blocking-network-client")]
mod variant {
    use crate::{Error, Result, bstr::ByteSlice, config, config::tree::ssh::Variant};

    impl Variant {
        pub fn try_into_variant(
            &'static self,
            value: impl gix_utils::AsBStr,
        ) -> Result<Option<gix_protocol::transport::client::blocking_io::ssh::ProgramKind>> {
            use gix_protocol::transport::client::blocking_io::ssh::ProgramKind;

            let value = value.as_bstr();
            Ok(Some(match value.as_bstr().as_bytes() {
                b"auto" => return Ok(None),
                b"ssh" => ProgramKind::Ssh,
                b"plink" => ProgramKind::Plink,
                b"putty" => ProgramKind::Putty,
                b"tortoiseplink" => ProgramKind::TortoisePlink,
                b"simple" => ProgramKind::Simple,
                _ => {
                    return Err(Error::from_error(config::key::error_with_value(
                        self,
                        "Invalid configuration value",
                        value,
                    )));
                }
            }))
        }
    }
}

impl Section for Ssh {
    fn name(&self) -> &str {
        "ssh"
    }

    fn keys(&self) -> &[&dyn Key] {
        &[&Self::VARIANT]
    }
}

mod validate {
    use crate::{ExnResult, bstr::BStr, config::tree::keys};
    #[cfg(feature = "blocking-network-client")]
    use gix_error::ResultExt;

    pub struct Variant;
    impl keys::Validate for Variant {
        fn validate(&self, _value: &BStr) -> ExnResult {
            #[cfg(feature = "blocking-network-client")]
            super::Ssh::VARIANT.try_into_variant(_value).or_erased()?;
            Ok(())
        }
    }
}