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 crate::{Error, Result, bstr::ByteSlice, 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::try_from(value.as_bstr())
.ok()
.and_then(|i| i.to_decimal().and_then(|i| i.try_into().ok()))
.or_else(|| {
gix_config::Boolean::try_from(value.as_bstr())
.ok()
.map(|b| if b.0 { 0 } else { 1 })
})
.ok_or_else(|| {
Error::from_error(config::key::error_with_value(
self,
"Invalid configuration value",
value,
))
})
}
}
}
impl Section for Index {
fn name(&self) -> &str {
"index"
}
fn keys(&self) -> &[&dyn Key] {
&[&Self::THREADS, &Self::SKIP_HASH]
}
}
mod validate {
use crate::{ExnResult, bstr::BStr, config::tree::keys};
use gix_error::ResultExt;
#[derive(Clone, Copy)]
pub struct IndexThreads;
impl keys::Validate for IndexThreads {
fn validate(&self, value: &BStr) -> ExnResult {
super::Index::THREADS.try_into_index_threads(value).or_erased()?;
Ok(())
}
}
}