Skip to content

Commit 072ee32

Browse files
committed
fix!: use dyn trait where possible.
This reduces compile time due to avoiding duplication.
1 parent 24dd870 commit 072ee32

File tree

289 files changed

+1694
-1641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

289 files changed

+1694
-1641
lines changed

Diff for: Cargo.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: gitoxide-core/src/commitgraph/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(crate) mod function {
3939
W1: io::Write,
4040
W2: io::Write,
4141
{
42-
let g = Graph::at(path).with_context(|| "Could not open commit graph")?;
42+
let g = Graph::at(path.as_ref()).with_context(|| "Could not open commit graph")?;
4343

4444
#[allow(clippy::unnecessary_wraps, unknown_lints)]
4545
fn noop_processor(_commit: &gix::commitgraph::file::Commit<'_>) -> std::result::Result<(), std::fmt::Error> {

Diff for: gitoxide-core/src/corpus/run.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use gix::progress::DynNestedProgress;
12
use std::{path::Path, sync::atomic::AtomicBool};
23

34
use crate::{
@@ -141,7 +142,7 @@ impl Execute for VerifyOdb {
141142
crate::repository::verify::integrity(
142143
repo,
143144
std::io::sink(),
144-
progress,
145+
progress.add_child("integrity".into()),
145146
should_interrupt,
146147
crate::repository::verify::Context {
147148
output_statistics: None,

Diff for: gitoxide-core/src/index/checkout.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ pub fn checkout_exclusive(
104104
}
105105
}
106106
},
107-
&mut files,
108-
&mut bytes,
107+
&files,
108+
&bytes,
109109
should_interrupt,
110110
opts,
111111
),
@@ -116,8 +116,8 @@ pub fn checkout_exclusive(
116116
buf.clear();
117117
Ok(gix::objs::BlobRef { data: buf })
118118
},
119-
&mut files,
120-
&mut bytes,
119+
&files,
120+
&bytes,
121121
should_interrupt,
122122
opts,
123123
),

Diff for: gitoxide-core/src/organize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ pub fn find_git_repository_workdirs(
9292
fn find_origin_remote(repo: &Path) -> anyhow::Result<Option<gix_url::Url>> {
9393
let non_bare = repo.join(".git").join("config");
9494
let local = gix::config::Source::Local;
95-
let config = gix::config::File::from_path_no_includes(non_bare.as_path(), local)
96-
.or_else(|_| gix::config::File::from_path_no_includes(repo.join("config").as_path(), local))?;
95+
let config = gix::config::File::from_path_no_includes(non_bare.as_path().into(), local)
96+
.or_else(|_| gix::config::File::from_path_no_includes(repo.join("config"), local))?;
9797
Ok(config
9898
.string_by_key("remote.origin.url")
9999
.map(|url| gix_url::Url::from_bytes(url.as_ref()))

Diff for: gitoxide-core/src/pack/create.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,13 @@ where
112112
P: NestedProgress,
113113
P::SubProgress: 'static,
114114
{
115+
type ObjectIdIter = dyn Iterator<Item = Result<ObjectId, Box<dyn std::error::Error + Send + Sync>>> + Send;
116+
115117
let repo = gix::discover(repository_path)?.into_sync();
116118
progress.init(Some(2), progress::steps());
117119
let tips = tips.into_iter();
118120
let make_cancellation_err = || anyhow!("Cancelled by user");
119-
let (mut handle, input): (
120-
_,
121-
Box<dyn Iterator<Item = Result<ObjectId, input_iteration::Error>> + Send>,
122-
) = match input {
121+
let (mut handle, mut input): (_, Box<ObjectIdIter>) = match input {
123122
None => {
124123
let mut progress = progress.add_child("traversing");
125124
progress.init(None, progress::count("commits"));
@@ -141,7 +140,7 @@ where
141140
let handle = handle.clone();
142141
move |oid, buf| handle.find_commit_iter(oid, buf).map(|t| t.0)
143142
})
144-
.map(|res| res.map_err(Into::into).map(|c| c.id))
143+
.map(|res| res.map_err(|err| Box::new(err) as Box<_>).map(|c| c.id))
145144
.inspect(move |_| progress.inc()),
146145
);
147146
(handle, iter)
@@ -157,7 +156,7 @@ where
157156
.lines()
158157
.map(|hex_id| {
159158
hex_id
160-
.map_err(Into::into)
159+
.map_err(|err| Box::new(err) as Box<_>)
161160
.and_then(|hex_id| ObjectId::from_hex(hex_id.as_bytes()).map_err(Into::into))
162161
})
163162
.inspect(move |_| progress.inc()),
@@ -207,7 +206,7 @@ where
207206
pack::data::output::count::objects(
208207
handle.clone(),
209208
input,
210-
progress,
209+
&progress,
211210
&interrupt::IS_INTERRUPTED,
212211
pack::data::output::count::objects::Options {
213212
thread_limit,
@@ -217,9 +216,9 @@ where
217216
)?
218217
} else {
219218
pack::data::output::count::objects_unthreaded(
220-
handle.clone(),
221-
input,
222-
progress,
219+
&handle,
220+
&mut input,
221+
&progress,
223222
&interrupt::IS_INTERRUPTED,
224223
input_object_expansion,
225224
)?
@@ -236,7 +235,7 @@ where
236235
InOrderIter::from(pack::data::output::entry::iter_from_counts(
237236
counts,
238237
handle,
239-
progress,
238+
Box::new(progress),
240239
pack::data::output::entry::iter_from_counts::Options {
241240
thread_limit,
242241
mode: pack::data::output::entry::iter_from_counts::Mode::PackCopyAndBaseObjects,

Diff for: gitoxide-core/src/pack/explode.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,22 @@ enum OutputWriter {
9797
}
9898

9999
impl gix::odb::Write for OutputWriter {
100-
type Error = Error;
101-
102-
fn write_buf(&self, kind: object::Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
100+
fn write_buf(&self, kind: object::Kind, from: &[u8]) -> Result<ObjectId, gix::odb::write::Error> {
103101
match self {
104-
OutputWriter::Loose(db) => db.write_buf(kind, from).map_err(Into::into),
105-
OutputWriter::Sink(db) => db.write_buf(kind, from).map_err(Into::into),
102+
OutputWriter::Loose(db) => db.write_buf(kind, from),
103+
OutputWriter::Sink(db) => db.write_buf(kind, from),
106104
}
107105
}
108106

109-
fn write_stream(&self, kind: object::Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
107+
fn write_stream(
108+
&self,
109+
kind: object::Kind,
110+
size: u64,
111+
from: &mut dyn Read,
112+
) -> Result<ObjectId, gix::odb::write::Error> {
110113
match self {
111-
OutputWriter::Loose(db) => db.write_stream(kind, size, from).map_err(Into::into),
112-
OutputWriter::Sink(db) => db.write_stream(kind, size, from).map_err(Into::into),
114+
OutputWriter::Loose(db) => db.write_stream(kind, size, from),
115+
OutputWriter::Sink(db) => db.write_stream(kind, size, from),
113116
}
114117
}
115118
}
@@ -137,7 +140,7 @@ pub fn pack_or_pack_index(
137140
pack_path: impl AsRef<Path>,
138141
object_path: Option<impl AsRef<Path>>,
139142
check: SafetyCheck,
140-
progress: impl NestedProgress,
143+
mut progress: impl NestedProgress + 'static,
141144
Context {
142145
thread_limit,
143146
delete_pack,
@@ -178,11 +181,11 @@ pub fn pack_or_pack_index(
178181
|_| pack::index::traverse::Algorithm::Lookup,
179182
);
180183

181-
let pack::index::traverse::Outcome { progress, .. } = bundle
184+
let pack::index::traverse::Outcome { .. } = bundle
182185
.index
183186
.traverse(
184187
&bundle.pack,
185-
progress,
188+
&mut progress,
186189
&should_interrupt,
187190
{
188191
let object_path = object_path.map(|p| p.as_ref().to_owned());
@@ -193,7 +196,7 @@ pub fn pack_or_pack_index(
193196
let mut read_buf = Vec::new();
194197
move |object_kind, buf, index_entry, progress| {
195198
let written_id = out.write_buf(object_kind, buf).map_err(|err| Error::Write {
196-
source: Box::new(err) as Box<dyn std::error::Error + Send + Sync>,
199+
source: err,
197200
kind: object_kind,
198201
id: index_entry.oid,
199202
})?;
@@ -213,13 +216,13 @@ pub fn pack_or_pack_index(
213216
}
214217
if let Some(verifier) = loose_odb.as_ref() {
215218
let obj = verifier
216-
.try_find(written_id, &mut read_buf)
219+
.try_find(&written_id, &mut read_buf)
217220
.map_err(|err| Error::WrittenFileCorrupt {
218221
source: err,
219222
id: written_id,
220223
})?
221224
.ok_or(Error::WrittenFileMissing { id: written_id })?;
222-
obj.verify_checksum(written_id)?;
225+
obj.verify_checksum(&written_id)?;
223226
}
224227
Ok(())
225228
}

Diff for: gitoxide-core/src/pack/index.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,12 @@ pub enum PathOrRead {
7070
Read(Box<dyn std::io::Read + Send + 'static>),
7171
}
7272

73-
pub fn from_pack<P>(
73+
pub fn from_pack(
7474
pack: PathOrRead,
7575
directory: Option<PathBuf>,
76-
progress: P,
76+
mut progress: impl NestedProgress + 'static,
7777
ctx: Context<'static, impl io::Write>,
78-
) -> anyhow::Result<()>
79-
where
80-
P: NestedProgress,
81-
P::SubProgress: 'static,
82-
{
78+
) -> anyhow::Result<()> {
8379
use anyhow::Context;
8480
let options = pack::bundle::write::Options {
8581
thread_limit: ctx.thread_limit,
@@ -94,10 +90,10 @@ where
9490
let pack_len = pack.metadata()?.len();
9591
let pack_file = fs::File::open(pack)?;
9692
pack::Bundle::write_to_directory_eagerly(
97-
pack_file,
93+
Box::new(pack_file),
9894
Some(pack_len),
9995
directory,
100-
progress,
96+
&mut progress,
10197
ctx.should_interrupt,
10298
None,
10399
options,
@@ -107,7 +103,7 @@ where
107103
input,
108104
None,
109105
directory,
110-
progress,
106+
&mut progress,
111107
ctx.should_interrupt,
112108
None,
113109
options,

Diff for: gitoxide-core/src/pack/multi_index.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=3;
99

1010
pub fn verify(
1111
multi_index_path: PathBuf,
12-
progress: impl NestedProgress,
12+
mut progress: impl NestedProgress + 'static,
1313
should_interrupt: &AtomicBool,
1414
) -> anyhow::Result<()> {
15-
gix::odb::pack::multi_index::File::at(multi_index_path)?.verify_integrity_fast(progress, should_interrupt)?;
15+
gix::odb::pack::multi_index::File::at(multi_index_path)?.verify_integrity_fast(&mut progress, should_interrupt)?;
1616
Ok(())
1717
}
1818

1919
pub fn create(
2020
index_paths: Vec<PathBuf>,
2121
output_path: PathBuf,
22-
progress: impl NestedProgress,
22+
mut progress: impl NestedProgress + 'static,
2323
should_interrupt: &AtomicBool,
2424
object_hash: gix::hash::Kind,
2525
) -> anyhow::Result<()> {
@@ -31,7 +31,7 @@ pub fn create(
3131
gix::odb::pack::multi_index::File::write_from_index_paths(
3232
index_paths,
3333
&mut out,
34-
progress,
34+
&mut progress,
3535
should_interrupt,
3636
gix::odb::pack::multi_index::write::Options { object_hash },
3737
)?;

Diff for: gitoxide-core/src/pack/receive.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ mod blocking_io {
130130
fn receive_pack(
131131
&mut self,
132132
input: impl BufRead,
133-
progress: impl NestedProgress,
133+
progress: impl NestedProgress + 'static,
134134
refs: &[Ref],
135135
_previous_response: &Response,
136136
) -> io::Result<()> {
@@ -156,7 +156,7 @@ mod blocking_io {
156156
) -> anyhow::Result<()>
157157
where
158158
W: std::io::Write,
159-
P: NestedProgress,
159+
P: NestedProgress + 'static,
160160
P::SubProgress: 'static,
161161
{
162162
let transport = net::connect(
@@ -212,7 +212,7 @@ mod async_io {
212212
async fn receive_pack(
213213
&mut self,
214214
input: impl AsyncBufRead + Unpin + 'async_trait,
215-
progress: impl gix::NestedProgress,
215+
progress: impl gix::NestedProgress + 'static,
216216
refs: &[Ref],
217217
_previous_response: &Response,
218218
) -> io::Result<()> {
@@ -367,8 +367,8 @@ fn receive_pack_blocking<W: io::Write>(
367367
mut directory: Option<PathBuf>,
368368
mut refs_directory: Option<PathBuf>,
369369
ctx: &mut Context<W>,
370-
input: impl io::BufRead,
371-
progress: impl NestedProgress,
370+
mut input: impl io::BufRead,
371+
mut progress: impl NestedProgress + 'static,
372372
refs: &[Ref],
373373
) -> io::Result<()> {
374374
let options = pack::bundle::write::Options {
@@ -377,9 +377,15 @@ fn receive_pack_blocking<W: io::Write>(
377377
iteration_mode: pack::data::input::Mode::Verify,
378378
object_hash: ctx.object_hash,
379379
};
380-
let outcome =
381-
pack::Bundle::write_to_directory(input, directory.take(), progress, &ctx.should_interrupt, None, options)
382-
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
380+
let outcome = pack::Bundle::write_to_directory(
381+
&mut input,
382+
directory.take().as_deref(),
383+
&mut progress,
384+
&ctx.should_interrupt,
385+
None,
386+
options,
387+
)
388+
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
383389

384390
if let Some(directory) = refs_directory.take() {
385391
write_raw_refs(refs, directory)?;

0 commit comments

Comments
 (0)