Skip to content

Commit af1ad55

Browse files
authored
Merge pull request #2493 from GitoxideLabs/improvements
improvements
2 parents ec66ceb + 7bda16a commit af1ad55

25 files changed

Lines changed: 74 additions & 42 deletions

File tree

gitoxide-core/src/repository/blame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn blame_file(
1111
) -> anyhow::Result<()> {
1212
{
1313
let mut config = repo.config_snapshot_mut();
14-
if config.string(&tree::Core::DELTA_BASE_CACHE_LIMIT).is_none() {
14+
if config.string(tree::Core::DELTA_BASE_CACHE_LIMIT).is_none() {
1515
config.set_value(&tree::Core::DELTA_BASE_CACHE_LIMIT, "100m")?;
1616
}
1717
}

gitoxide-core/src/repository/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct Filter {
5555

5656
impl Filter {
5757
fn new(input: BString) -> Self {
58-
match input.try_as_key() {
58+
match (&input).try_as_key() {
5959
Some(key) => Filter {
6060
name: key.section_name.into(),
6161
subsection: key.subsection_name.map(ToOwned::to_owned),

gix-config/src/key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bstr::{BStr, ByteSlice};
22

33
/// Parse parts of a Git configuration key, like `remote.origin.url` or `core.bare`.
4-
pub trait AsKey {
4+
pub trait AsKey: Copy {
55
/// Return a parsed key reference, containing all relevant parts of a key.
66
/// For instance, `remote.origin.url` such key would yield access to `("remote", Some("origin"), "url")`
77
/// while `user.name` would yield `("user", None, "name")`.
@@ -22,7 +22,7 @@ mod impls {
2222

2323
use crate::key::{AsKey, KeyRef};
2424

25-
impl AsKey for String {
25+
impl AsKey for &String {
2626
fn as_key(&self) -> KeyRef<'_> {
2727
self.try_as_key()
2828
.unwrap_or_else(|| panic!("'{self}' is not a valid configuration key"))
@@ -44,7 +44,7 @@ mod impls {
4444
}
4545
}
4646

47-
impl AsKey for BString {
47+
impl AsKey for &BString {
4848
fn as_key(&self) -> KeyRef<'_> {
4949
self.try_as_key()
5050
.unwrap_or_else(|| panic!("'{self}' is not a valid configuration key"))

gix-submodule/src/access.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl File {
119119
pub fn path(&self, name: &BStr) -> Result<Cow<'_, BStr>, config::path::Error> {
120120
let path_bstr =
121121
self.config
122-
.string(format!("submodule.{name}.path"))
122+
.string(&format!("submodule.{name}.path"))
123123
.ok_or_else(|| config::path::Error::Missing {
124124
submodule: name.to_owned(),
125125
})?;
@@ -148,7 +148,7 @@ impl File {
148148
pub fn url(&self, name: &BStr) -> Result<gix_url::Url, config::url::Error> {
149149
let url = self
150150
.config
151-
.string(format!("submodule.{name}.url"))
151+
.string(&format!("submodule.{name}.url"))
152152
.ok_or_else(|| config::url::Error::Missing {
153153
submodule: name.to_owned(),
154154
})?;
@@ -166,7 +166,7 @@ impl File {
166166

167167
/// Retrieve the `update` field of the submodule named `name`, if present.
168168
pub fn update(&self, name: &BStr) -> Result<Option<Update>, config::update::Error> {
169-
let value: Update = match self.config.string(format!("submodule.{name}.update")) {
169+
let value: Update = match self.config.string(&format!("submodule.{name}.update")) {
170170
Some(v) => v.as_ref().try_into().map_err(|()| config::update::Error::Invalid {
171171
submodule: name.to_owned(),
172172
actual: v.into_owned(),
@@ -196,7 +196,7 @@ impl File {
196196
///
197197
/// Note that `Default` is implemented for [`Branch`].
198198
pub fn branch(&self, name: &BStr) -> Result<Option<Branch>, config::branch::Error> {
199-
let branch = match self.config.string(format!("submodule.{name}.branch")) {
199+
let branch = match self.config.string(&format!("submodule.{name}.branch")) {
200200
Some(v) => v,
201201
None => return Ok(None),
202202
};
@@ -215,7 +215,7 @@ impl File {
215215
/// Note that if it's unset, it should be retrieved from `fetch.recurseSubmodules` in the configuration.
216216
pub fn fetch_recurse(&self, name: &BStr) -> Result<Option<FetchRecurse>, config::Error> {
217217
self.config
218-
.boolean(format!("submodule.{name}.fetchRecurseSubmodules"))
218+
.boolean(&format!("submodule.{name}.fetchRecurseSubmodules"))
219219
.map(FetchRecurse::new)
220220
.transpose()
221221
.map_err(|value| config::Error {
@@ -228,7 +228,7 @@ impl File {
228228
/// Retrieve the `ignore` field of the submodule named `name`, or `None` if unset.
229229
pub fn ignore(&self, name: &BStr) -> Result<Option<Ignore>, config::Error> {
230230
self.config
231-
.string(format!("submodule.{name}.ignore"))
231+
.string(&format!("submodule.{name}.ignore"))
232232
.map(|value| {
233233
Ignore::try_from(value.as_ref()).map_err(|()| config::Error {
234234
field: "ignore",
@@ -243,6 +243,6 @@ impl File {
243243
///
244244
/// If `true`, the submodule will be checked out with `depth = 1`. If unset, `false` is assumed.
245245
pub fn shallow(&self, name: &BStr) -> Result<Option<bool>, gix_config::value::Error> {
246-
self.config.boolean(format!("submodule.{name}.shallow")).transpose()
246+
self.config.boolean(&format!("submodule.{name}.shallow")).transpose()
247247
}
248248
}

gix-submodule/src/is_active_platform.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl IsActivePlatform {
3434
&mut gix_pathspec::attributes::search::Outcome,
3535
) -> bool,
3636
) -> Result<bool, gix_config::value::Error> {
37-
if let Some(val) = config.boolean(format!("submodule.{name}.active")).transpose()? {
37+
if let Some(val) = config.boolean(&format!("submodule.{name}.active")).transpose()? {
3838
return Ok(val);
3939
}
4040
if let Some(val) = self.search.as_mut().map(|search| {
@@ -44,6 +44,6 @@ impl IsActivePlatform {
4444
}) {
4545
return Ok(val);
4646
}
47-
Ok(config.string(format!("submodule.{name}.url")).is_some())
47+
Ok(config.string(&format!("submodule.{name}.url")).is_some())
4848
}
4949
}

gix/src/config/cache/access.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl Cache {
186186
.user_agent
187187
.get_or_init(|| {
188188
self.resolved
189-
.string(&Gitoxide::USER_AGENT)
189+
.string(Gitoxide::USER_AGENT)
190190
.map_or_else(|| crate::env::agent().into(), |s| s.to_string())
191191
})
192192
.to_owned();
@@ -533,7 +533,7 @@ pub(crate) fn trusted_file_path<'config>(
533533
lenient_config: bool,
534534
environment: crate::open::permissions::Environment,
535535
) -> Option<Result<Cow<'config, std::path::Path>, gix_config::path::interpolate::Error>> {
536-
let path = config.path_filter(&key, filter)?;
536+
let path = config.path_filter(key, filter)?;
537537

538538
if lenient_config && path.is_empty() {
539539
let _key = key.as_key();

gix/src/config/cache/incubate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl StageOne {
7474
config.append(worktree_config);
7575
}
7676
let precompose_unicode = config
77-
.boolean(&Core::PRECOMPOSE_UNICODE)
77+
.boolean(Core::PRECOMPOSE_UNICODE)
7878
.map(|v| Core::PRECOMPOSE_UNICODE.enrich_error(v))
7979
.transpose()
8080
.with_leniency(lenient)

gix/src/config/snapshot/credential_helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub(super) mod function {
186186
let prompt_options = gix_prompt::Options {
187187
askpass: crate::config::cache::access::trusted_file_path(
188188
config,
189-
&Core::ASKPASS,
189+
Core::ASKPASS,
190190
&mut filter,
191191
is_lenient_config,
192192
environment,
@@ -195,7 +195,7 @@ pub(super) mod function {
195195
.ignore_empty()?
196196
.map(|c| Cow::Owned(c.into_owned())),
197197
mode: config
198-
.boolean(&Credentials::TERMINAL_PROMPT)
198+
.boolean(Credentials::TERMINAL_PROMPT)
199199
.map(|val| Credentials::TERMINAL_PROMPT.enrich_error(val))
200200
.transpose()
201201
.with_leniency(is_lenient_config)?
@@ -210,7 +210,7 @@ pub(super) mod function {
210210
// The default ssh implementation uses binaries that do their own auth, so our passwords aren't used.
211211
query_user_only: url.scheme == gix_url::Scheme::Ssh,
212212
stderr: config
213-
.boolean(&Credentials::HELPER_STDERR)
213+
.boolean(Credentials::HELPER_STDERR)
214214
.map(|val| Credentials::HELPER_STDERR.enrich_error(val))
215215
.transpose()
216216
.with_leniency(is_lenient_config)?

gix/src/config/tree/keys.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
};
1515

1616
/// Implements a value without any constraints, i.e. a any value.
17+
#[derive(Copy, Clone)]
1718
pub struct Any<T: Validate = validate::All> {
1819
/// The key of the value in the git configuration.
1920
pub name: &'static str,
@@ -148,7 +149,7 @@ impl<T: Validate> Key for Any<T> {
148149
}
149150
}
150151

151-
impl<T: Validate> gix_config::AsKey for Any<T> {
152+
impl<T: Validate + Copy + Clone> gix_config::AsKey for Any<T> {
152153
fn as_key(&self) -> gix_config::KeyRef<'_> {
153154
self.try_as_key().expect("infallible")
154155
}
@@ -512,7 +513,7 @@ pub mod validate {
512513
};
513514

514515
/// Everything is valid.
515-
#[derive(Default)]
516+
#[derive(Default, Copy, Clone)]
516517
pub struct All;
517518

518519
impl Validate for All {
@@ -522,7 +523,7 @@ pub mod validate {
522523
}
523524

524525
/// Assure that values that parse as git dates are valid.
525-
#[derive(Default)]
526+
#[derive(Default, Clone, Copy)]
526527
pub struct Time;
527528

528529
impl Validate for Time {
@@ -534,7 +535,7 @@ pub mod validate {
534535
}
535536

536537
/// Assure that values that parse as unsigned integers are valid.
537-
#[derive(Default)]
538+
#[derive(Default, Clone, Copy)]
538539
pub struct UnsignedInteger;
539540

540541
impl Validate for UnsignedInteger {
@@ -550,7 +551,7 @@ pub mod validate {
550551
}
551552

552553
/// Assure that values that parse as git booleans are valid.
553-
#[derive(Default)]
554+
#[derive(Default, Clone, Copy)]
554555
pub struct Boolean;
555556

556557
impl Validate for Boolean {
@@ -561,7 +562,7 @@ pub mod validate {
561562
}
562563

563564
/// Values that are git remotes, symbolic or urls
564-
#[derive(Default)]
565+
#[derive(Default, Clone, Copy)]
565566
pub struct RemoteName;
566567
impl Validate for RemoteName {
567568
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -572,7 +573,7 @@ pub mod validate {
572573
}
573574

574575
/// Values that are programs - everything is allowed.
575-
#[derive(Default)]
576+
#[derive(Default, Clone, Copy)]
576577
pub struct Program;
577578
impl Validate for Program {
578579
fn validate(&self, _value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -581,7 +582,7 @@ pub mod validate {
581582
}
582583

583584
/// Values that are programs executables, everything is allowed.
584-
#[derive(Default)]
585+
#[derive(Default, Clone, Copy)]
585586
pub struct Executable;
586587
impl Validate for Executable {
587588
fn validate(&self, _value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -590,7 +591,7 @@ pub mod validate {
590591
}
591592

592593
/// Values that parse as URLs.
593-
#[derive(Default)]
594+
#[derive(Default, Clone, Copy)]
594595
pub struct Url;
595596
impl Validate for Url {
596597
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -600,7 +601,7 @@ pub mod validate {
600601
}
601602

602603
/// Values that parse as ref-specs for pushing.
603-
#[derive(Default)]
604+
#[derive(Default, Clone, Copy)]
604605
pub struct PushRefSpec;
605606
impl Validate for PushRefSpec {
606607
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -610,7 +611,7 @@ pub mod validate {
610611
}
611612

612613
/// Values that parse as ref-specs for pushing.
613-
#[derive(Default)]
614+
#[derive(Default, Clone, Copy)]
614615
pub struct FetchRefSpec;
615616
impl Validate for FetchRefSpec {
616617
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -620,6 +621,7 @@ pub mod validate {
620621
}
621622

622623
/// Timeouts used for file locks.
624+
#[derive(Clone, Copy)]
623625
pub struct LockTimeout;
624626
impl Validate for LockTimeout {
625627
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -632,6 +634,7 @@ pub mod validate {
632634
}
633635

634636
/// Durations in milliseconds.
637+
#[derive(Clone, Copy)]
635638
pub struct DurationInMilliseconds;
636639
impl Validate for DurationInMilliseconds {
637640
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -644,6 +647,7 @@ pub mod validate {
644647
}
645648

646649
/// A UTF-8 string.
650+
#[derive(Clone, Copy)]
647651
pub struct String;
648652
impl Validate for String {
649653
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -653,6 +657,7 @@ pub mod validate {
653657
}
654658

655659
/// Any path - everything is allowed.
660+
#[derive(Clone, Copy)]
656661
pub struct Path;
657662
impl Validate for Path {
658663
fn validate(&self, _value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {

gix/src/config/tree/sections/core.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ mod abbrev {
442442
mod validate {
443443
use crate::{bstr::BStr, config::tree::keys};
444444

445+
#[derive(Clone, Copy)]
445446
pub struct Disambiguate;
446447
impl keys::Validate for Disambiguate {
447448
#[cfg_attr(not(feature = "revision"), allow(unused_variables))]
@@ -452,6 +453,7 @@ mod validate {
452453
}
453454
}
454455

456+
#[derive(Clone, Copy)]
455457
pub struct LogAllRefUpdates;
456458
impl keys::Validate for LogAllRefUpdates {
457459
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -461,6 +463,7 @@ mod validate {
461463
}
462464
}
463465

466+
#[derive(Clone, Copy)]
464467
pub struct CheckStat;
465468
impl keys::Validate for CheckStat {
466469
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -469,6 +472,7 @@ mod validate {
469472
}
470473
}
471474

475+
#[derive(Clone, Copy)]
472476
pub struct Abbrev;
473477
impl keys::Validate for Abbrev {
474478
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
@@ -479,6 +483,7 @@ mod validate {
479483
}
480484

481485
#[cfg(feature = "attributes")]
486+
#[derive(Clone, Copy)]
482487
pub struct SafeCrlf;
483488
#[cfg(feature = "attributes")]
484489
impl keys::Validate for SafeCrlf {
@@ -489,6 +494,7 @@ mod validate {
489494
}
490495

491496
#[cfg(feature = "attributes")]
497+
#[derive(Clone, Copy)]
492498
pub struct AutoCrlf;
493499
#[cfg(feature = "attributes")]
494500
impl keys::Validate for AutoCrlf {
@@ -499,6 +505,7 @@ mod validate {
499505
}
500506

501507
#[cfg(feature = "attributes")]
508+
#[derive(Clone, Copy)]
502509
pub struct Eol;
503510
#[cfg(feature = "attributes")]
504511
impl keys::Validate for Eol {
@@ -509,6 +516,7 @@ mod validate {
509516
}
510517

511518
#[cfg(feature = "attributes")]
519+
#[derive(Clone, Copy)]
512520
pub struct CheckRoundTripEncoding;
513521
#[cfg(feature = "attributes")]
514522
impl keys::Validate for CheckRoundTripEncoding {

0 commit comments

Comments
 (0)