gix 0.88.0

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

impl Extensions {
    /// The `extensions.worktreeConfig` key.
    pub const WORKTREE_CONFIG: keys::Boolean = keys::Boolean::new_boolean("worktreeConfig", &config::Tree::EXTENSIONS);
    /// The `extensions.objectFormat` key.
    pub const OBJECT_FORMAT: ObjectFormat =
        ObjectFormat::new_with_validate("objectFormat", &config::Tree::EXTENSIONS, validate::ObjectFormat).with_note(
            "Support for SHA256 is prepared but not fully implemented yet. For now we abort when encountered",
        );
}

/// The `core.checkStat` key.
pub type ObjectFormat = keys::Any<validate::ObjectFormat>;

mod object_format {
    use crate::{Error, Result, bstr::ByteSlice, config, config::tree::sections::extensions::ObjectFormat};

    impl ObjectFormat {
        pub fn try_into_object_format(&'static self, value: impl gix_utils::AsBStr) -> Result<gix_hash::Kind> {
            let value = value.as_bstr();
            #[cfg(feature = "sha1")]
            if value.as_bstr().eq_ignore_ascii_case(b"sha1") {
                return Ok(gix_hash::Kind::Sha1);
            }

            #[cfg(feature = "sha256")]
            if value.as_bstr().eq_ignore_ascii_case(b"sha256") {
                return Ok(gix_hash::Kind::Sha256);
            }

            Err(Error::from_error(config::key::error_with_value(
                self,
                "Invalid configuration value",
                value,
            )))
        }
    }
}

impl Section for Extensions {
    fn name(&self) -> &str {
        "extensions"
    }

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

mod validate {
    use crate::{ExnResult, bstr::BStr, config::tree::keys};
    use gix_error::ResultExt;

    #[derive(Clone, Copy)]
    pub struct ObjectFormat;

    impl keys::Validate for ObjectFormat {
        fn validate(&self, value: &BStr) -> ExnResult {
            super::Extensions::OBJECT_FORMAT
                .try_into_object_format(value)
                .or_erased()?;
            Ok(())
        }
    }
}