History

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.

Sebastian Thiel committed 4 years ago

Commit af6326f1 parent eba2b9a2 files · +7 −8Browse files

Unified · Split

2 files
  1. git-repository/src/lib.rs +0 −4
  2. git-repository/src/repository/config.rs +7 −4
git-repository/src/lib.rs+0−4
@@ -234,10 +234,6 @@ mod config { · 233 unmodified lines
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 ///
git-repository/src/repository/config.rs+7−4
@@ -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 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t