gix 0.90.0

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

impl Index {
    /// The `index.threads` key.
    pub const THREADS: IndexThreads =
        IndexThreads::new_with_validate("threads", &config::Tree::INDEX, validate::IndexThreads);
    /// The `index.skipHash` key.
    pub const SKIP_HASH: keys::Boolean = keys::Boolean::new_boolean("skipHash", &config::Tree::INDEX)
        .with_deviation("also used to skip the hash when reading, even if a hash exists in the index file");
}

/// The `index.threads` key.
pub type IndexThreads = keys::Any<validate::IndexThreads>;

mod index_threads {
    use gix_error::ResultExt;

    use crate::{Result, config, config::tree::index::IndexThreads};

    impl IndexThreads {
        /// Parse `value` into the amount of threads to use, with `1` being single-threaded, or `0` indicating
        /// to select the amount of threads, with any other number being the specific amount of threads to use.
        pub fn try_into_index_threads(&'static self, value: impl gix_utils::AsBStr) -> Result<usize> {
            let value = value.as_bstr();
            gix_config::Integer::from_bytes::<usize>(value)
                .or_else(|err| {
                    gix_config::Boolean::try_from(value)
                        .map(|b| if b.0 { 0 } else { 1 })
                        .map_err(|_| err)
                })
                .or_raise(|| config::key::error(self, "Invalid configuration value"))
        }
    }
}

impl Section for Index {
    fn name(&self) -> &str {
        "index"
    }

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

mod validate {
    use crate::{Result, bstr::BStr, config::tree::keys};

    #[derive(Clone, Copy)]
    pub struct IndexThreads;
    impl keys::Validate for IndexThreads {
        fn validate(&self, value: &BStr) -> Result {
            super::Index::THREADS.try_into_index_threads(value)?;
            Ok(())
        }
    }
}