Skip to content

Commit 2c5d28b

Browse files
committed
fix!: use dyn trait where possible.
This reduces compile time due to avoiding duplication.
1 parent c5fee82 commit 2c5d28b

File tree

19 files changed

+86
-66
lines changed

19 files changed

+86
-66
lines changed

gix/src/clone/checkout.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ pub mod main_worktree {
2626
#[error(transparent)]
2727
CheckoutOptions(#[from] crate::config::checkout_options::Error),
2828
#[error(transparent)]
29-
IndexCheckout(
30-
#[from]
31-
gix_worktree_state::checkout::Error<gix_odb::find::existing_object::Error<gix_odb::store::find::Error>>,
32-
),
29+
IndexCheckout(#[from] gix_worktree_state::checkout::Error<gix_odb::find::existing_object::Error>),
3330
#[error("Failed to reopen object database as Arc (only if thread-safety wasn't compiled in)")]
3431
OpenArcOdb(#[from] std::io::Error),
3532
#[error("The HEAD reference could not be located")]

gix/src/clone/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,22 @@ impl PrepareFetch {
8989
.set_raw_value(
9090
"gitoxide",
9191
Some("committer".into()),
92-
gitoxide::Committer::NAME_FALLBACK.name,
93-
"no name configured during clone",
92+
gitoxide::Committer::NAME_FALLBACK
93+
.name
94+
.try_into()
95+
.expect("compile time"),
96+
"no name configured during clone".into(),
9497
)
9598
.expect("works - statically known");
9699
config
97100
.set_raw_value(
98101
"gitoxide",
99102
Some("committer".into()),
100-
gitoxide::Committer::EMAIL_FALLBACK.name,
101-
103+
gitoxide::Committer::EMAIL_FALLBACK
104+
.name
105+
.try_into()
106+
.expect("compile time"),
107+
102108
)
103109
.expect("works - statically known");
104110
let mut repo_config = repo.config_snapshot_mut();

gix/src/commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub mod describe {
204204
.try_find(id, buf)
205205
.map(|r| r.and_then(gix_object::Data::try_into_commit_iter))
206206
},
207-
gix_commitgraph::Graph::from_info_dir(self.repo.objects.store_ref().path().join("info")).ok(),
207+
gix_commitgraph::Graph::from_info_dir(self.repo.objects.store_ref().path().join("info").as_ref()).ok(),
208208
);
209209
let outcome = gix_revision::describe(
210210
&self.id,

gix/src/config/cache/init.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Cache {
7272

7373
let config = {
7474
let git_prefix = &git_prefix;
75-
let metas = [
75+
let mut metas = [
7676
gix_config::source::Kind::GitInstallation,
7777
gix_config::source::Kind::System,
7878
gix_config::source::Kind::Global,
@@ -100,7 +100,7 @@ impl Cache {
100100

101101
let err_on_nonexisting_paths = false;
102102
let mut globals = gix_config::File::from_paths_metadata_buf(
103-
metas,
103+
&mut metas,
104104
&mut buf,
105105
err_on_nonexisting_paths,
106106
gix_config::file::init::Options {
@@ -491,7 +491,7 @@ fn apply_environment_overrides(
491491
),
492492
] {
493493
let mut section = env_override
494-
.new_section(section_name, subsection_name)
494+
.new_section(section_name.into(), subsection_name)
495495
.expect("statically known valid section name");
496496
for (var, key) in data {
497497
if let Some(value) = var_as_bstring(var, permission) {
@@ -510,7 +510,7 @@ fn apply_environment_overrides(
510510

511511
{
512512
let mut section = env_override
513-
.new_section("core", None)
513+
.new_section("core".into(), None)
514514
.expect("statically known valid section name");
515515

516516
for (var, key, permission) in [

gix/src/config/overrides.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ pub(crate) fn append(
2929
let mut tokens = key_value.splitn(2, |b| *b == b'=').map(ByteSlice::trim);
3030
let key = tokens.next().expect("always one value").as_bstr();
3131
let value = tokens.next();
32-
let key = gix_config::parse::key(key.to_str().map_err(|_| Error::InvalidKey { input: key.into() })?)
33-
.ok_or_else(|| Error::InvalidKey { input: key.into() })?;
32+
let key = gix_config::parse::key(
33+
key.to_str()
34+
.map_err(|_| Error::InvalidKey { input: key.into() })?
35+
.into(),
36+
)
37+
.ok_or_else(|| Error::InvalidKey { input: key.into() })?;
3438
let mut section = file.section_mut_or_create_new(key.section_name, key.subsection_name)?;
3539
let key =
3640
gix_config::parse::section::Key::try_from(key.value_name.to_owned()).map_err(|err| Error::SectionKey {

gix/src/config/snapshot/access.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::borrow::Cow;
33

44
use gix_features::threading::OwnShared;
55

6+
use crate::bstr::ByteSlice;
67
use crate::{
78
bstr::{BStr, BString},
89
config::{CommitAutoRollback, Snapshot, SnapshotMut},
@@ -58,7 +59,7 @@ impl<'repo> Snapshot<'repo> {
5859
&self,
5960
key: impl Into<&'a BStr>,
6061
) -> Option<Result<Cow<'_, std::path::Path>, gix_config::path::interpolate::Error>> {
61-
let key = gix_config::parse::key(key)?;
62+
let key = gix_config::parse::key(key.into())?;
6263
self.repo
6364
.config
6465
.trusted_file_path(key.section_name, key.subsection_name, key.value_name)
@@ -111,9 +112,12 @@ impl<'repo> SnapshotMut<'repo> {
111112
}
112113
let value = new_value.into();
113114
key.validate(value)?;
114-
let current = self
115-
.config
116-
.set_raw_value(key.section().name(), None, key.name(), value)?;
115+
let current = self.config.set_raw_value(
116+
key.section().name(),
117+
None,
118+
key.name().try_into().expect("compile time"),
119+
value,
120+
)?;
117121
Ok(current.map(std::borrow::Cow::into_owned))
118122
}
119123

@@ -134,10 +138,13 @@ impl<'repo> SnapshotMut<'repo> {
134138
let name = key
135139
.full_name(Some(subsection.into()))
136140
.expect("we know it needs a subsection");
137-
let key = gix_config::parse::key(&**name).expect("statically known keys can always be parsed");
138-
let current =
139-
self.config
140-
.set_raw_value(key.section_name, key.subsection_name, key.value_name.to_owned(), value)?;
141+
let key = gix_config::parse::key((&**name).as_bstr()).expect("statically known keys can always be parsed");
142+
let current = self.config.set_raw_value(
143+
key.section_name,
144+
key.subsection_name,
145+
key.value_name.to_owned().try_into().expect("compile time"),
146+
value,
147+
)?;
141148
Ok(current.map(std::borrow::Cow::into_owned))
142149
}
143150

gix/src/create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub fn into(
207207
let mut config = gix_config::File::default();
208208
{
209209
let caps = fs_capabilities.unwrap_or_else(|| gix_fs::Capabilities::probe(&dot_git));
210-
let mut core = config.new_section("core", None).expect("valid section name");
210+
let mut core = config.new_section("core".into(), None).expect("valid section name");
211211

212212
core.push(key("repositoryformatversion"), Some("0".into()));
213213
core.push(key("filemode"), Some(bool(caps.executable_bit).into()));
@@ -232,7 +232,7 @@ pub fn into(
232232
} else {
233233
gix_discover::repository::Kind::WorkTree { linked_git_dir: None }
234234
},
235-
std::env::current_dir()?,
235+
&std::env::current_dir()?,
236236
)
237237
.expect("by now the `dot_git` dir is valid as we have accessed it"))
238238
}

gix/src/discover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl ThreadSafeRepository {
3737
trust_map: gix_sec::trust::Mapping<crate::open::Options>,
3838
) -> Result<Self, Error> {
3939
let _span = gix_trace::coarse!("ThreadSafeRepository::discover()");
40-
let (path, trust) = upwards_opts(directory, options)?;
40+
let (path, trust) = upwards_opts(directory.as_ref(), options)?;
4141
let (git_dir, worktree_dir) = path.into_repository_and_work_tree_directories();
4242
let mut options = trust_map.into_value_by_level(trust);
4343
options.git_dir_trust = trust.into();

gix/src/filter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ impl<'repo> Pipeline<'repo> {
147147
Ok(self.inner.convert_to_git(
148148
src,
149149
rela_path,
150-
|_, attrs| {
150+
&mut |_, attrs| {
151151
entry.matching_attributes(attrs);
152152
},
153-
|rela_path, buf| -> Result<_, crate::object::find::Error> {
153+
&mut |rela_path, buf| -> Result<_, crate::object::find::Error> {
154154
let entry = match index.entry_by_path(rela_path) {
155155
None => return Ok(None),
156156
Some(entry) => entry,
157157
};
158-
let obj = self.repo.objects.try_find(entry.id, buf)?;
158+
let obj = self.repo.objects.try_find(&entry.id, buf)?;
159159
Ok(obj.filter(|obj| obj.kind == gix_object::Kind::Blob).map(|_| ()))
160160
},
161161
)?)
@@ -181,7 +181,7 @@ impl<'repo> Pipeline<'repo> {
181181
Ok(self.inner.convert_to_worktree(
182182
src,
183183
rela_path,
184-
|_, attrs| {
184+
&mut |_, attrs| {
185185
entry.matching_attributes(attrs);
186186
},
187187
can_delay,

gix/src/object/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ pub mod conversion {
1818
///
1919
pub mod find {
2020
/// Indicate that an error occurred when trying to find an object.
21-
pub type Error = gix_odb::store::find::Error;
21+
pub type Error = gix_odb::find::Error;
2222

2323
///
2424
pub mod existing {
2525
/// An object could not be found in the database, or an error occurred when trying to obtain it.
26-
pub type Error = gix_odb::find::existing::Error<gix_odb::store::find::Error>;
26+
pub type Error = gix_odb::find::existing::Error;
2727
}
2828
}
2929

3030
///
3131
pub mod write {
3232
/// An error to indicate writing to the loose object store failed.
33-
pub type Error = gix_odb::store::write::Error;
33+
pub type Error = gix_odb::write::Error;
3434
}

0 commit comments

Comments
 (0)