use crate::{
config,
config::tree::{Index, Key, Section, keys},
};
impl Index {
pub const THREADS: IndexThreads =
IndexThreads::new_with_validate("threads", &config::Tree::INDEX, validate::IndexThreads);
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");
}
pub type IndexThreads = keys::Any<validate::IndexThreads>;
mod index_threads {
use gix_error::ResultExt;
use crate::{Result, config, config::tree::index::IndexThreads};
impl IndexThreads {
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(())
}
}
}