However, I think this should really be part of `config` itself, while the `Repository` provides some utilities at best to deal with mutability maybe.
Unified · Split
| @@ -234,10 +234,6 @@ mod config { · 233 unmodified lines | ||
| 234 | 234 | pub mod open { |
| 235 | 235 | pub type Error = git_config::parser::ParserOrIoError<'static>; |
| 236 | 236 | } |
| 237 | − /// | |
| 238 | − pub mod query { | |
| 239 | − pub type Error = git_config::file::GitConfigError<'static>; | |
| 240 | − } | |
| 241 | 237 | } |
| 242 | 238 | |
| 243 | 239 | /// |
| @@ -1,9 +1,12 @@ | ||
| 1 | −use crate::config; | |
| 2 | − | |
| 3 | 1 | /// Provide simplified access to git configuration values |
| 4 | 2 | impl crate::Repository { |
| 5 | 3 | /// 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) | |
| 8 | 11 | } |
| 9 | 12 | } |