Skip to content

Commit f290030

Browse files
committed
quick sketch of how the retrieval of ints from config could look like (#298)
However, I think this should really be part of `config` itself, while the `Repository` provides some utilities at best to deal with mutability maybe.
1 parent 056b09b commit f290030

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

git-repository/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,6 @@ mod config {
234234
pub mod open {
235235
pub type Error = git_config::parser::ParserOrIoError<'static>;
236236
}
237-
///
238-
pub mod query {
239-
pub type Error = git_config::file::GitConfigError<'static>;
240-
}
241237
}
242238

243239
///
+7-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use crate::config;
2-
31
/// Provide simplified access to git configuration values
42
impl crate::Repository {
53
/// Return the integer value at `key` (like `core.abbrev`) or use the given `default` value if it isn't present.
6-
pub fn config_int(_key: &str, _default: i64) -> Result<i64, config::query::Error> {
7-
todo!()
4+
// TODO: figure out how to identify sub-sections, or how to design such an API. This is really just a first test.
5+
// TODO: tests
6+
pub fn config_int(&self, key: &str, default: i64) -> i64 {
7+
let (section, key) = key.split_once('.').expect("valid section.key format");
8+
self.config
9+
.value::<git_config::values::Integer>(section, None, key)
10+
.map_or(default, |v| v.value)
811
}
912
}

0 commit comments

Comments
 (0)