1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::{
config,
config::tree::{keys, Extensions, Key, Section},
};
impl Extensions {
pub const WORKTREE_CONFIG: keys::Boolean = keys::Boolean::new_boolean("worktreeConfig", &config::Tree::EXTENSIONS);
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",
);
}
pub type ObjectFormat = keys::Any<validate::ObjectFormat>;
mod object_format {
use std::borrow::Cow;
use crate::{bstr::BStr, config, config::tree::sections::extensions::ObjectFormat};
impl ObjectFormat {
pub fn try_into_object_format(
&'static self,
value: Cow<'_, BStr>,
) -> Result<git_hash::Kind, config::key::GenericErrorWithValue> {
if value.as_ref().eq_ignore_ascii_case(b"sha1") {
Ok(git_hash::Kind::Sha1)
} else {
Err(config::key::GenericErrorWithValue::from_value(self, value.into_owned()))
}
}
}
}
impl Section for Extensions {
fn name(&self) -> &str {
"extensions"
}
fn keys(&self) -> &[&dyn Key] {
&[&Self::OBJECT_FORMAT, &Self::WORKTREE_CONFIG]
}
}
mod validate {
use crate::{bstr::BStr, config::tree::keys};
pub struct ObjectFormat;
impl keys::Validate for ObjectFormat {
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
super::Extensions::OBJECT_FORMAT.try_into_object_format(value.into())?;
Ok(())
}
}
}