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
234 pub mod open {234 pub mod open {
235 pub type Error = git_config::parser::ParserOrIoError<'static>;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///
git-repository/src/repository/config.rs+7−4
@@ -1,9 +1,12 @@
1use crate::config;
2
3/// Provide simplified access to git configuration values1/// Provide simplified access to git configuration values
4impl crate::Repository {2impl crate::Repository {
5 /// Return the integer value at `key` (like `core.abbrev`) or use the given `default` value if it isn't present.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> {4 // TODO: figure out how to identify sub-sections, or how to design such an API. This is really just a first test.
7 todo!()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}

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