Skip to content

Commit bf04644

Browse files
committed
change!: remove Option<impl Progress> in favor of impl Progress (#279)
1 parent 21013a1 commit bf04644

File tree

11 files changed

+45
-50
lines changed

11 files changed

+45
-50
lines changed

git-pack/src/bundle/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub mod verify {
2020
/// The packs traversal outcome
2121
pub pack_traverse_outcome: crate::index::traverse::Outcome,
2222
/// The provided progress instance.
23-
pub progress: Option<P>,
23+
pub progress: P,
2424
}
2525
}
2626

@@ -35,7 +35,7 @@ pub mod verify {
3535
traversal: crate::index::traverse::Algorithm,
3636
make_pack_lookup_cache: impl Fn() -> C + Send + Clone,
3737
thread_limit: Option<usize>,
38-
progress: Option<P>,
38+
progress: P,
3939
should_interrupt: &AtomicBool,
4040
) -> Result<integrity::Outcome<P>, crate::index::traverse::Error<crate::index::verify::integrity::Error>>
4141
where

git-pack/src/index/traverse/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use std::sync::atomic::AtomicBool;
22

3-
use git_features::{
4-
parallel,
5-
progress::{self, Progress},
6-
};
3+
use git_features::{parallel, progress::Progress};
74

85
use crate::index;
96

@@ -67,7 +64,7 @@ impl index::File {
6764
pub fn traverse<P, C, Processor, E>(
6865
&self,
6966
pack: &crate::data::File,
70-
progress: Option<P>,
67+
progress: P,
7168
new_processor: impl Fn() -> Processor + Send + Clone,
7269
new_cache: impl Fn() -> C + Send + Clone,
7370
Options {
@@ -76,7 +73,7 @@ impl index::File {
7673
check,
7774
should_interrupt,
7875
}: Options<'_>,
79-
) -> Result<(git_hash::ObjectId, Outcome, Option<P>), Error<E>>
76+
) -> Result<(git_hash::ObjectId, Outcome, P), Error<E>>
8077
where
8178
P: Progress,
8279
C: crate::cache::DecodeEntry,
@@ -85,10 +82,9 @@ impl index::File {
8582
git_object::Kind,
8683
&[u8],
8784
&index::Entry,
88-
&mut progress::DoOrDiscard<<<P as Progress>::SubProgress as Progress>::SubProgress>,
85+
&mut <<P as Progress>::SubProgress as Progress>::SubProgress,
8986
) -> Result<(), E>,
9087
{
91-
let progress = progress::DoOrDiscard::from(progress);
9288
match algorithm {
9389
Algorithm::Lookup => self.traverse_with_lookup(
9490
new_processor,
@@ -105,7 +101,6 @@ impl index::File {
105101
self.traverse_with_index(check, thread_limit, new_processor, progress, pack, should_interrupt)
106102
}
107103
}
108-
.map(|(a, b, p)| (a, b, p.into_inner()))
109104
}
110105

111106
fn possibly_verify<E>(

git-pack/src/index/verify.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::atomic::AtomicBool;
22

3-
use git_features::progress::{self, Progress};
3+
use git_features::progress::Progress;
44
use git_object::{bstr::ByteSlice, WriteTo};
55

66
use crate::index;
@@ -35,7 +35,7 @@ pub mod integrity {
3535
/// The packs traversal outcome, if one was provided
3636
pub pack_traverse_outcome: Option<crate::index::traverse::Outcome>,
3737
/// The provided progress instance.
38-
pub progress: Option<P>,
38+
pub progress: P,
3939
}
4040
}
4141

@@ -129,15 +129,14 @@ impl index::File {
129129
&self,
130130
pack: Option<PackContext<'_, C, F>>,
131131
thread_limit: Option<usize>,
132-
progress: Option<P>,
132+
mut progress: P,
133133
should_interrupt: &AtomicBool,
134134
) -> Result<integrity::Outcome<P>, index::traverse::Error<crate::index::verify::integrity::Error>>
135135
where
136136
P: Progress,
137137
C: crate::cache::DecodeEntry,
138138
F: Fn() -> C + Send + Clone,
139139
{
140-
let mut root = progress::DoOrDiscard::from(progress);
141140
match pack {
142141
Some(PackContext {
143142
data: pack,
@@ -147,7 +146,7 @@ impl index::File {
147146
}) => self
148147
.traverse(
149148
pack,
150-
root.into_inner(),
149+
progress,
151150
|| {
152151
let mut encode_buf = Vec::with_capacity(2048);
153152
move |kind, data, index_entry, progress| {
@@ -162,18 +161,18 @@ impl index::File {
162161
should_interrupt,
163162
},
164163
)
165-
.map(|(id, outcome, root)| integrity::Outcome {
164+
.map(|(id, outcome, progress)| integrity::Outcome {
166165
actual_index_checksum: id,
167166
pack_traverse_outcome: Some(outcome),
168-
progress: root,
167+
progress,
169168
}),
170169
None => self
171-
.verify_checksum(root.add_child("Sha1 of index"), should_interrupt)
170+
.verify_checksum(progress.add_child("Sha1 of index"), should_interrupt)
172171
.map_err(Into::into)
173172
.map(|id| integrity::Outcome {
174173
actual_index_checksum: id,
175174
pack_traverse_outcome: None,
176-
progress: root.into_inner(),
175+
progress,
177176
}),
178177
}
179178
}

git-pack/src/multi_index/verify.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub mod integrity {
2323
/// The for each entry in [`index_names()`][super::File::index_names()] provide the corresponding pack traversal outcome.
2424
pub pack_traverse_outcomes: Vec<crate::index::traverse::Outcome>,
2525
/// The provided progress instance.
26-
pub progress: Option<P>,
26+
pub progress: P,
2727
}
2828
}
2929

@@ -61,7 +61,7 @@ impl File {
6161
traversal: crate::index::traverse::Algorithm,
6262
make_pack_lookup_cache: impl Fn() -> C + Send + Clone,
6363
thread_limit: Option<usize>,
64-
mut progress: Option<P>,
64+
mut progress: P,
6565
should_interrupt: &AtomicBool,
6666
) -> Result<integrity::Outcome<P>, crate::index::traverse::Error<integrity::Error>>
6767
where
@@ -70,24 +70,21 @@ impl File {
7070
{
7171
let parent = self.path.parent().expect("must be in a directory");
7272

73-
let mut progress = git_features::progress::DoOrDiscard::from(progress);
7473
let actual_index_checksum = self
7574
.verify_checksum(
7675
progress.add_child(format!("checksum of '{}'", self.path.display())),
7776
should_interrupt,
7877
)
7978
.map_err(integrity::Error::from)
8079
.map_err(crate::index::traverse::Error::Processor)?;
81-
let mut progress = progress.into_inner();
8280

8381
let mut pack_traverse_outcomes = Vec::new();
8482
for index_file_name in &self.index_names {
8583
let bundle = crate::Bundle::at(parent.join(index_file_name), self.object_hash)
8684
.map_err(integrity::Error::from)
8785
.map_err(crate::index::traverse::Error::Processor)?;
88-
if let Some(progress) = progress.as_mut() {
89-
progress.set_name(index_file_name.display().to_string());
90-
}
86+
87+
progress.set_name(index_file_name.display().to_string());
9188
let crate::bundle::verify::integrity::Outcome {
9289
actual_index_checksum: _,
9390
pack_traverse_outcome,

git-pack/tests/pack/data/output/count_and_entries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ fn write_and_verify(
392392
pack::index::traverse::Algorithm::Lookup,
393393
|| pack::cache::Never,
394394
None,
395-
progress::Discard.into(),
395+
progress::Discard,
396396
&should_interrupt,
397397
)?;
398398

git-pack/tests/pack/index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ mod file {
308308
make_cache_fn: || cache::Never
309309
}),
310310
None,
311-
progress::Discard.into(),
311+
progress::Discard,
312312
&AtomicBool::new(false)
313313
)
314314
.map(|o| (o.actual_index_checksum, o.pack_traverse_outcome))?,
@@ -408,7 +408,7 @@ mod file {
408408
idx.verify_integrity(
409409
None::<git_pack::index::verify::PackContext<'_, _, fn() -> cache::Never>>,
410410
None,
411-
progress::Discard.into(),
411+
progress::Discard,
412412
&AtomicBool::new(false)
413413
)
414414
.map(|o| (o.actual_index_checksum, o.pack_traverse_outcome))?,

git-pack/tests/pack/multi_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ mod verify {
7676
git_pack::index::traverse::Algorithm::DeltaTreeLookup,
7777
|| git_pack::cache::Never,
7878
None,
79-
Some(progress::Discard),
79+
progress::Discard,
8080
&AtomicBool::new(false),
8181
)
8282
.unwrap();

gitoxide-core/src/pack/explode.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use git_repository::{
1111
hash::ObjectId,
1212
objs, odb,
1313
odb::{loose, pack, Write},
14-
progress, Progress,
14+
Progress,
1515
};
1616
use quick_error::quick_error;
1717

@@ -151,7 +151,7 @@ pub fn pack_or_pack_index(
151151
pack_path: impl AsRef<Path>,
152152
object_path: Option<impl AsRef<Path>>,
153153
check: SafetyCheck,
154-
progress: Option<impl Progress>,
154+
progress: impl Progress,
155155
Context {
156156
thread_limit,
157157
delete_pack,
@@ -191,7 +191,7 @@ pub fn pack_or_pack_index(
191191
pack::index::traverse::Algorithm::DeltaTreeLookup
192192
}
193193
});
194-
let mut progress = bundle
194+
let (_, _, mut progress) = bundle
195195
.index
196196
.traverse(
197197
&bundle.pack,
@@ -239,7 +239,6 @@ pub fn pack_or_pack_index(
239239
should_interrupt: &should_interrupt,
240240
},
241241
)
242-
.map(|(_, _, c)| progress::DoOrDiscard::from(c))
243242
.with_context(|| "Failed to explode the entire pack - some loose objects may have been created nonetheless")?;
244243

245244
let (index_path, data_path) = (bundle.index.path().to_owned(), bundle.pack.path().to_owned());

gitoxide-core/src/pack/verify.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use git_repository::{
88
hash::ObjectId,
99
odb,
1010
odb::{pack, pack::index},
11-
progress, Progress,
11+
Progress,
1212
};
1313
pub use index::verify::Mode;
1414

@@ -103,7 +103,7 @@ impl<const SIZE: usize> pack::cache::DecodeEntry for EitherCache<SIZE> {
103103

104104
pub fn pack_or_pack_index<W1, W2>(
105105
path: impl AsRef<Path>,
106-
progress: Option<impl Progress>,
106+
mut progress: impl Progress,
107107
Context {
108108
mut out,
109109
mut err,
@@ -129,11 +129,8 @@ where
129129
let res = match ext {
130130
"pack" => {
131131
let pack = odb::pack::data::File::at(path, object_hash).with_context(|| "Could not open pack file")?;
132-
pack.verify_checksum(
133-
progress::DoOrDiscard::from(progress).add_child("Sha1 of pack"),
134-
should_interrupt,
135-
)
136-
.map(|id| (id, None))?
132+
pack.verify_checksum(progress.add_child("Sha1 of pack"), should_interrupt)
133+
.map(|id| (id, None))?
137134
}
138135
"idx" => {
139136
let idx =

src/plumbing/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ pub fn main() -> Result<()> {
114114
core::pack::create::ObjectExpansion::None
115115
}),
116116
};
117-
let progress = git_features::progress::DoOrDiscard::from(progress);
118117
core::pack::create(repository, tips, input, output_directory, progress, context)
119118
},
120119
)
@@ -233,7 +232,7 @@ pub fn main() -> Result<()> {
233232
core::pack::index::from_pack(
234233
input,
235234
directory,
236-
git_features::progress::DoOrDiscard::from(progress),
235+
progress,
237236
core::pack::index::Context {
238237
thread_limit,
239238
iteration_mode,

src/shared.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub mod pretty {
4949
use std::io::{stderr, stdout};
5050

5151
use anyhow::Result;
52+
use git_repository::progress;
5253

5354
use crate::shared::ProgressRange;
5455

@@ -59,26 +60,34 @@ pub mod pretty {
5960
#[cfg_attr(not(feature = "prodash-render-tui"), allow(unused_variables))] progress_keep_open: bool,
6061
#[cfg_attr(not(feature = "prodash-render-line"), allow(unused_variables))] range: impl Into<Option<ProgressRange>>,
6162
#[cfg(not(any(feature = "prodash-render-line", feature = "prodash-render-tui")))] run: impl FnOnce(
62-
Option<prodash::progress::Log>,
63+
progress::DoOrDiscard<prodash::progress::Log>,
6364
&mut dyn std::io::Write,
6465
&mut dyn std::io::Write,
6566
)
6667
-> Result<T>,
67-
#[cfg(any(feature = "prodash-render-line", feature = "prodash-render-tui"))] run: impl FnOnce(Option<prodash::tree::Item>, &mut dyn std::io::Write, &mut dyn std::io::Write) -> Result<T>
68+
#[cfg(any(feature = "prodash-render-line", feature = "prodash-render-tui"))] run: impl FnOnce(
69+
progress::DoOrDiscard<prodash::tree::Item>,
70+
&mut dyn std::io::Write,
71+
&mut dyn std::io::Write,
72+
) -> Result<T>
6873
+ Send
6974
+ std::panic::UnwindSafe
7075
+ 'static,
7176
) -> Result<T> {
7277
crate::shared::init_env_logger(false);
7378

7479
match (verbose, progress) {
75-
(false, false) => run(None, &mut stdout(), &mut stderr()),
80+
(false, false) => run(progress::DoOrDiscard::from(None), &mut stdout(), &mut stderr()),
7681
(true, false) => {
7782
let progress = crate::shared::progress_tree();
7883
let sub_progress = progress.add_child(name);
7984
#[cfg(not(feature = "prodash-render-line"))]
8085
{
81-
run(Some(sub_progress), &mut stdout(), &mut stderr())
86+
run(
87+
progress::DoOrDiscard::from(Some(sub_progress)),
88+
&mut stdout(),
89+
&mut stderr(),
90+
)
8291
}
8392
#[cfg(feature = "prodash-render-line")]
8493
{
@@ -105,7 +114,7 @@ pub mod pretty {
105114
let join_handle = std::thread::spawn(move || {
106115
let mut out = Vec::<u8>::new();
107116
let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
108-
run(Some(sub_progress), &mut out, &mut stderr())
117+
run(progress::DoOrDiscard::from(Some(sub_progress)), &mut out, &mut stderr())
109118
}));
110119
match res {
111120
Ok(res) => tx.send(Event::ComputationDone(res, out)).ok(),
@@ -174,7 +183,7 @@ pub mod pretty {
174183
// We might have something interesting to show, which would be hidden by the alternate screen if there is a progress TUI
175184
// We know that the printing happens at the end, so this is fine.
176185
let mut out = Vec::new();
177-
let res = run(Some(sub_progress), &mut out, &mut stderr());
186+
let res = run(progress::DoOrDiscard::from(Some(sub_progress)), &mut out, &mut stderr());
178187
tx.send(Event::ComputationDone(res, out)).ok();
179188
});
180189
loop {

0 commit comments

Comments
 (0)