History

refactor

- use improved API in git-config - expose `plumbing` directly via AsDeref.

Sebastian Thiel committed 3 years ago

Commit 603f3411 parent f1a4c8b3 files · +11 −16Browse files

Unified · Split

3 files
  1. git-repository/src/config/snapshot/_impls.rs +8 −0
  2. git-repository/src/config/snapshot/access.rs +3 −15
  3. gitoxide-core/src/repository/config.rs +0 −1
git-repository/src/config/snapshot/_impls.rs+8−0
@@ -47,6 +47,14 @@ impl Deref for SnapshotMut<'_> { · 46 unmodified lines
47 }47 }
48}48}
49 49
50impl Deref for Snapshot<'_> {
51 type Target = git_config::File<'static>;
52
53 fn deref(&self) -> &Self::Target {
54 &self.plumbing()
55 }
56}
57
50impl Deref for CommitAutoRollback<'_> {58impl Deref for CommitAutoRollback<'_> {
51 type Target = crate::Repository;59 type Target = crate::Repository;
52 60
git-repository/src/config/snapshot/access.rs+3−15
@@ -25,11 +25,7 @@ impl<'repo> Snapshot<'repo> { · 24 unmodified lines
25 25
26 /// Like [`boolean()`][Self::boolean()], but it will report an error if the value couldn't be interpreted as boolean.26 /// Like [`boolean()`][Self::boolean()], but it will report an error if the value couldn't be interpreted as boolean.
27 pub fn try_boolean<'a>(&self, key: impl Into<&'a BStr>) -> Option<Result<bool, git_config::value::Error>> {27 pub fn try_boolean<'a>(&self, key: impl Into<&'a BStr>) -> Option<Result<bool, git_config::value::Error>> {
28 let key = git_config::parse::key(key)?;28 self.repo.config.resolved.boolean_by_key(key)
29 self.repo
30 .config
31 .resolved
32 .boolean(key.section_name, key.subsection_name, key.value_name)
33 }29 }
34 30
35 /// Return the resolved integer at `key`, or `None` if there is no such value or if the value can't be interpreted as31 /// Return the resolved integer at `key`, or `None` if there is no such value or if the value can't be interpreted as
@@ -44,22 +40,14 @@ impl<'repo> Snapshot<'repo> { · 8 unmodified lines
44 40
45 /// Like [`integer()`][Self::integer()], but it will report an error if the value couldn't be interpreted as boolean.41 /// Like [`integer()`][Self::integer()], but it will report an error if the value couldn't be interpreted as boolean.
46 pub fn try_integer<'a>(&self, key: impl Into<&'a BStr>) -> Option<Result<i64, git_config::value::Error>> {42 pub fn try_integer<'a>(&self, key: impl Into<&'a BStr>) -> Option<Result<i64, git_config::value::Error>> {
47 let key = git_config::parse::key(key)?;43 self.repo.config.resolved.integer_by_key(key)
48 self.repo
49 .config
50 .resolved
51 .integer(key.section_name, key.subsection_name, key.value_name)
52 }44 }
53 45
54 /// Return the string at `key`, or `None` if there is no such value.46 /// Return the string at `key`, or `None` if there is no such value.
55 ///47 ///
56 /// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust.48 /// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust.
57 pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'_, BStr>> {49 pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'_, BStr>> {
58 let key = git_config::parse::key(key)?;50 self.repo.config.resolved.string_by_key(key)
59 self.repo
60 .config
61 .resolved
62 .string(key.section_name, key.subsection_name, key.value_name)
63 }51 }
64 52
65 /// Return the trusted and fully interpolated path at `key`, or `None` if there is no such value53 /// Return the trusted and fully interpolated path at `key`, or `None` if there is no such value
gitoxide-core/src/repository/config.rs+0−1
@@ -19,7 +19,6 @@ pub fn list( · 18 unmodified lines
19 repo.open_options().clone().lossy_config(false).cli_overrides(overrides),19 repo.open_options().clone().lossy_config(false).cli_overrides(overrides),
20 )?;20 )?;
21 let config = repo.config_snapshot();21 let config = repo.config_snapshot();
22 let config = config.plumbing();
23 if let Some(frontmatter) = config.frontmatter() {22 if let Some(frontmatter) = config.frontmatter() {
24 for event in frontmatter {23 for event in frontmatter {
25 event.write_to(&mut out)?;24 event.write_to(&mut out)?;