Skip to content

Commit 38e3c50

Browse files
committed
fix!: all config::Snapshot access now uses the new Key trait.
That way one can officially use "section.name" strings or `&Section::NAME`.
1 parent 30d69d3 commit 38e3c50

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

gix/src/config/snapshot/access.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ impl<'repo> Snapshot<'repo> {
2222
/// For a non-degenerating version, use [`try_boolean(…)`][Self::try_boolean()].
2323
///
2424
/// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust.
25-
pub fn boolean<'a>(&self, key: impl Into<&'a BStr>) -> Option<bool> {
25+
pub fn boolean(&self, key: impl gix_config::AsKey) -> Option<bool> {
2626
self.try_boolean(key).and_then(Result::ok)
2727
}
2828

2929
/// Like [`boolean()`][Self::boolean()], but it will report an error if the value couldn't be interpreted as boolean.
30-
pub fn try_boolean<'a>(&self, key: impl Into<&'a BStr>) -> Option<Result<bool, gix_config::value::Error>> {
31-
self.repo.config.resolved.boolean(key.into())
30+
pub fn try_boolean(&self, key: impl gix_config::AsKey) -> Option<Result<bool, gix_config::value::Error>> {
31+
self.repo.config.resolved.boolean(key)
3232
}
3333

3434
/// Return the resolved integer at `key`, or `None` if there is no such value or if the value can't be interpreted as
@@ -37,40 +37,40 @@ impl<'repo> Snapshot<'repo> {
3737
/// For a non-degenerating version, use [`try_integer(…)`][Self::try_integer()].
3838
///
3939
/// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust.
40-
pub fn integer<'a>(&self, key: impl Into<&'a BStr>) -> Option<i64> {
40+
pub fn integer(&self, key: impl gix_config::AsKey) -> Option<i64> {
4141
self.try_integer(key).and_then(Result::ok)
4242
}
4343

4444
/// Like [`integer()`][Self::integer()], but it will report an error if the value couldn't be interpreted as boolean.
45-
pub fn try_integer<'a>(&self, key: impl Into<&'a BStr>) -> Option<Result<i64, gix_config::value::Error>> {
46-
self.repo.config.resolved.integer(key.into())
45+
pub fn try_integer(&self, key: impl gix_config::AsKey) -> Option<Result<i64, gix_config::value::Error>> {
46+
self.repo.config.resolved.integer(key)
4747
}
4848

4949
/// Return the string at `key`, or `None` if there is no such value.
5050
///
5151
/// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust.
52-
pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'repo, BStr>> {
53-
self.repo.config.resolved.string(key.into())
52+
pub fn string(&self, key: impl gix_config::AsKey) -> Option<Cow<'repo, BStr>> {
53+
self.repo.config.resolved.string(key)
5454
}
5555

5656
/// Return the trusted and fully interpolated path at `key`, or `None` if there is no such value
5757
/// or if no value was found in a trusted file.
5858
/// An error occurs if the path could not be interpolated to its final value.
59-
pub fn trusted_path<'a>(
59+
pub fn trusted_path(
6060
&self,
61-
key: impl Into<&'a BStr>,
61+
key: impl gix_config::AsKey,
6262
) -> Option<Result<Cow<'repo, std::path::Path>, gix_config::path::interpolate::Error>> {
63-
self.repo.config.trusted_file_path(key.into())
63+
self.repo.config.trusted_file_path(key)
6464
}
6565

6666
/// Return the trusted string at `key` for launching using [command::prepare()](gix_command::prepare()),
6767
/// or `None` if there is no such value or if no value was found in a trusted file.
68-
pub fn trusted_program<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'repo, OsStr>> {
68+
pub fn trusted_program(&self, key: impl gix_config::AsKey) -> Option<Cow<'repo, OsStr>> {
6969
let value = self
7070
.repo
7171
.config
7272
.resolved
73-
.string_filter(key.into(), &mut self.repo.config.filter_config_section.clone())?;
73+
.string_filter(key, &mut self.repo.config.filter_config_section.clone())?;
7474
Some(match gix_path::from_bstr(value) {
7575
Cow::Borrowed(v) => Cow::Borrowed(v.as_os_str()),
7676
Cow::Owned(v) => Cow::Owned(v.into_os_string()),

gix/src/remote/connection/fetch/receive_pack.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
config::{
33
cache::util::ApplyLeniency,
4-
tree::{Clone, Fetch, Key},
4+
tree::{Clone, Fetch},
55
},
66
remote,
77
remote::{
@@ -117,7 +117,7 @@ where
117117
let negotiator = repo
118118
.config
119119
.resolved
120-
.string(Fetch::NEGOTIATION_ALGORITHM.logical_name().as_str())
120+
.string(Fetch::NEGOTIATION_ALGORITHM)
121121
.map(|n| Fetch::NEGOTIATION_ALGORITHM.try_into_negotiation_algorithm(n))
122122
.transpose()
123123
.with_leniency(repo.config.lenient_config)?

gix/src/remote/url/scheme_permission.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{borrow::Cow, collections::BTreeMap};
33
use crate::{
44
bstr::{BStr, BString, ByteSlice},
55
config,
6-
config::tree::{gitoxide, Key, Protocol},
6+
config::tree::{gitoxide, Protocol},
77
};
88

99
/// All allowed values of the `protocol.allow` key.
@@ -91,7 +91,7 @@ impl SchemePermission {
9191

9292
let user_allowed = saw_user.then(|| {
9393
config
94-
.string_filter(gitoxide::Allow::PROTOCOL_FROM_USER.logical_name().as_str(), &mut filter)
94+
.string_filter(gitoxide::Allow::PROTOCOL_FROM_USER, &mut filter)
9595
.map_or(true, |val| val.as_ref() == "1")
9696
});
9797
Ok(SchemePermission {

gix/src/repository/identity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Personas {
149149

150150
user_email = user_email.or_else(|| {
151151
config
152-
.string(gitoxide::User::EMAIL_FALLBACK.logical_name().as_str())
152+
.string(gitoxide::User::EMAIL_FALLBACK)
153153
.map(std::borrow::Cow::into_owned)
154154
});
155155
Personas {

gix/src/repository/mailmap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::tree::{Key, Mailmap};
1+
use crate::config::tree::Mailmap;
22
use crate::Id;
33

44
impl crate::Repository {
@@ -68,7 +68,7 @@ impl crate::Repository {
6868

6969
let configured_path = self
7070
.config_snapshot()
71-
.trusted_path(Mailmap::FILE.logical_name().as_str())
71+
.trusted_path(&Mailmap::FILE)
7272
.and_then(|res| res.map_err(|e| err.get_or_insert(e.into())).ok());
7373

7474
if let Some(mut file) =

gix/src/repository/shallow.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use std::{borrow::Cow, path::PathBuf};
22

3-
use crate::{
4-
config::tree::{gitoxide, Key},
5-
Repository,
6-
};
3+
use crate::{config::tree::gitoxide, Repository};
74

85
impl Repository {
96
/// Return `true` if the repository is a shallow clone, i.e. contains history only up to a certain depth.
@@ -36,10 +33,7 @@ impl Repository {
3633
let shallow_name = self
3734
.config
3835
.resolved
39-
.string_filter(
40-
gitoxide::Core::SHALLOW_FILE.logical_name().as_str(),
41-
&mut self.filter_config_section(),
42-
)
36+
.string_filter(gitoxide::Core::SHALLOW_FILE, &mut self.filter_config_section())
4337
.unwrap_or_else(|| Cow::Borrowed("shallow".into()));
4438
self.common_dir().join(gix_path::from_bstr(shallow_name))
4539
}

0 commit comments

Comments
 (0)