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-
"noEmailAvailable@example.com",
103+
gitoxide::Committer::EMAIL_FALLBACK
104+
.name
105+
.try_into()
106+
.expect("compile time"),
107+
"noEmailAvailable@example.com".into(),
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
}

gix/src/object/tree/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'repo> Tree<'repo> {
7171
}));
7272
} else {
7373
let next_id = entry.oid.to_owned();
74-
let obj = self.repo.objects.find(next_id, buf)?;
74+
let obj = self.repo.objects.find(&next_id, buf)?;
7575
if !obj.kind.is_tree() {
7676
return Ok(None);
7777
}
@@ -113,7 +113,7 @@ impl<'repo> Tree<'repo> {
113113
}));
114114
} else {
115115
let next_id = entry.oid.to_owned();
116-
let obj = self.repo.objects.find(next_id, &mut self.data)?;
116+
let obj = self.repo.objects.find(&next_id, &mut self.data)?;
117117
self.id = next_id;
118118
if !obj.kind.is_tree() {
119119
return Ok(None);

gix/src/open/repository.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl ThreadSafeRepository {
176176
// This would be something read in later as have to first check for extensions. Also this means
177177
// that each worktree, even if accessible through this instance, has to come in its own Repository instance
178178
// as it may have its own configuration. That's fine actually.
179-
let common_dir = gix_discover::path::from_plain_file(git_dir.join("commondir"))
179+
let common_dir = gix_discover::path::from_plain_file(git_dir.join("commondir").as_ref())
180180
.transpose()?
181181
.map(|cd| git_dir.join(cd));
182182
let common_dir_ref = common_dir.as_deref().unwrap_or(&git_dir);
@@ -192,8 +192,10 @@ impl ThreadSafeRepository {
192192
let reflog = repo_config.reflog.unwrap_or(gix_ref::store::WriteReflog::Disable);
193193
let object_hash = repo_config.object_hash;
194194
match &common_dir {
195-
Some(common_dir) => crate::RefStore::for_linked_worktree(&git_dir, common_dir, reflog, object_hash),
196-
None => crate::RefStore::at(&git_dir, reflog, object_hash),
195+
Some(common_dir) => {
196+
crate::RefStore::for_linked_worktree(git_dir.to_owned(), common_dir.into(), reflog, object_hash)
197+
}
198+
None => crate::RefStore::at(git_dir.to_owned(), reflog, object_hash),
197199
}
198200
};
199201
let head = refs.find("HEAD").ok();
@@ -236,7 +238,7 @@ impl ThreadSafeRepository {
236238
.interpolate(interpolate_context(git_install_dir.as_deref(), home.as_deref()))
237239
.map_err(config::Error::PathInterpolation)?;
238240
worktree_dir = {
239-
gix_path::normalize(git_dir.join(wt_path), current_dir)
241+
gix_path::normalize(git_dir.join(wt_path).into(), current_dir)
240242
.and_then(|wt| wt.as_ref().is_dir().then(|| wt.into_owned()))
241243
}
242244
}
@@ -276,7 +278,7 @@ impl ThreadSafeRepository {
276278
Ok(ThreadSafeRepository {
277279
objects: OwnShared::new(gix_odb::Store::at_opts(
278280
common_dir_ref.join("objects"),
279-
replacements,
281+
&mut replacements.into_iter(),
280282
gix_odb::store::init::Options {
281283
slots: object_store_slots,
282284
object_hash: config.object_hash,

gix/src/reference/iter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,31 @@ impl<'r> Platform<'r> {
4343
// TODO: Create a custom `Path` type that enforces the requirements of git naturally, this type is surprising possibly on windows
4444
// and when not using a trailing '/' to signal directories.
4545
pub fn prefixed(&self, prefix: impl AsRef<Path>) -> Result<Iter<'_>, init::Error> {
46-
Ok(Iter::new(self.repo, self.platform.prefixed(prefix)?))
46+
Ok(Iter::new(self.repo, self.platform.prefixed(prefix.as_ref())?))
4747
}
4848

4949
// TODO: tests
5050
/// Return an iterator over all references that are tags.
5151
///
5252
/// They are all prefixed with `refs/tags`.
5353
pub fn tags(&self) -> Result<Iter<'_>, init::Error> {
54-
Ok(Iter::new(self.repo, self.platform.prefixed("refs/tags/")?))
54+
Ok(Iter::new(self.repo, self.platform.prefixed("refs/tags/".as_ref())?))
5555
}
5656

5757
// TODO: tests
5858
/// Return an iterator over all local branches.
5959
///
6060
/// They are all prefixed with `refs/heads`.
6161
pub fn local_branches(&self) -> Result<Iter<'_>, init::Error> {
62-
Ok(Iter::new(self.repo, self.platform.prefixed("refs/heads/")?))
62+
Ok(Iter::new(self.repo, self.platform.prefixed("refs/heads/".as_ref())?))
6363
}
6464

6565
// TODO: tests
6666
/// Return an iterator over all remote branches.
6767
///
6868
/// They are all prefixed with `refs/remotes`.
6969
pub fn remote_branches(&self) -> Result<Iter<'_>, init::Error> {
70-
Ok(Iter::new(self.repo, self.platform.prefixed("refs/remotes/")?))
70+
Ok(Iter::new(self.repo, self.platform.prefixed("refs/remotes/".as_ref())?))
7171
}
7272
}
7373

@@ -95,10 +95,10 @@ impl<'r> Iterator for Iter<'r> {
9595
.and_then(|mut r| {
9696
if self.peel {
9797
let handle = &self.repo;
98-
r.peel_to_id_in_place(&handle.refs, |oid, buf| {
98+
r.peel_to_id_in_place(&handle.refs, &mut |oid, buf| {
9999
handle
100100
.objects
101-
.try_find(oid, buf)
101+
.try_find(oid.as_ref(), buf)
102102
.map(|po| po.map(|(o, _l)| (o.kind, o.data)))
103103
})
104104
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)

gix/src/reference/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ impl<'repo> Reference<'repo> {
7070
/// This is useful to learn where this reference is ultimately pointing to.
7171
pub fn peel_to_id_in_place(&mut self) -> Result<Id<'repo>, peel::Error> {
7272
let repo = &self.repo;
73-
let oid = self.inner.peel_to_id_in_place(&repo.refs, |oid, buf| {
73+
let oid = self.inner.peel_to_id_in_place(&repo.refs, &mut |oid, buf| {
7474
repo.objects
75-
.try_find(oid, buf)
75+
.try_find(&oid, buf)
7676
.map(|po| po.map(|(o, _l)| (o.kind, o.data)))
7777
})?;
7878
Ok(Id::from_id(oid, repo))

gix/src/repository/object.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl crate::Repository {
3232
});
3333
}
3434
let mut buf = self.free_buf();
35-
let kind = self.objects.find(id, &mut buf)?.kind;
35+
let kind = self.objects.find(&id, &mut buf)?.kind;
3636
Ok(Object::from_data(id, kind, buf, self))
3737
}
3838

@@ -65,7 +65,7 @@ impl crate::Repository {
6565
size: 0,
6666
}));
6767
}
68-
self.objects.try_header(id)
68+
self.objects.try_header(&id)
6969
}
7070

7171
/// Try to find the object with `id` or return `None` if it wasn't found.
@@ -81,7 +81,7 @@ impl crate::Repository {
8181
}
8282

8383
let mut buf = self.free_buf();
84-
match self.objects.try_find(id, &mut buf)? {
84+
match self.objects.try_find(&id, &mut buf)? {
8585
Some(obj) => {
8686
let kind = obj.kind;
8787
Ok(Some(Object::from_data(id, kind, buf, self)))
@@ -111,7 +111,7 @@ impl crate::Repository {
111111
object.write_to(buf.deref_mut())?;
112112

113113
let oid = gix_object::compute_hash(self.object_hash(), object.kind(), &buf);
114-
if self.objects.contains(oid) {
114+
if self.objects.contains(&oid) {
115115
return Ok(oid.attach(self));
116116
}
117117

@@ -128,7 +128,7 @@ impl crate::Repository {
128128
pub fn write_blob(&self, bytes: impl AsRef<[u8]>) -> Result<Id<'_>, object::write::Error> {
129129
let bytes = bytes.as_ref();
130130
let oid = gix_object::compute_hash(self.object_hash(), gix_object::Kind::Blob, bytes);
131-
if self.objects.contains(oid) {
131+
if self.objects.contains(&oid) {
132132
return Ok(oid.attach(self));
133133
}
134134
self.objects
@@ -149,7 +149,7 @@ impl crate::Repository {
149149
let mut buf = self.shared_empty_buf();
150150
std::io::copy(&mut bytes, buf.deref_mut())?;
151151
let oid = gix_object::compute_hash(self.object_hash(), gix_object::Kind::Blob, &buf);
152-
if self.objects.contains(oid) {
152+
if self.objects.contains(&oid) {
153153
return Ok(oid.attach(self));
154154
}
155155

0 commit comments

Comments
 (0)