Skip to content

Commit 24dd870

Browse files
committed
feat!: use prodash::Count to indicate that nothing more than counting is performed, in place of prodash::Progress
1 parent ed327f6 commit 24dd870

File tree

12 files changed

+63
-83
lines changed

12 files changed

+63
-83
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ gix = { version = "^0.53.0", path = "gix", default-features = false }
168168
time = "0.3.23"
169169

170170
clap = { version = "4.1.1", features = ["derive", "cargo"] }
171-
prodash = { version = "26.0.0", optional = true, default-features = false }
171+
prodash = { version = "26.2.0", optional = true, default-features = false }
172172
is-terminal = { version = "0.4.0", optional = true }
173173
env_logger = { version = "0.10.0", default-features = false }
174174
crosstermion = { version = "0.11.0", optional = true, default-features = false }

gix-features/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ crc32fast = { version = "1.2.1", optional = true }
129129
sha1 = { version = "0.10.0", optional = true }
130130

131131
# progress
132-
prodash = { version = "26.0.0", optional = true, default-features = false }
132+
prodash = { version = "26.2.0", optional = true, default-features = false }
133133
bytesize = { version = "1.0.1", optional = true }
134134

135135
# pipe

gix-features/src/progress.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ pub use bytesize;
66
pub use prodash::{
77
self,
88
messages::MessageLevel,
9-
progress::{Discard, DoOrDiscard, Either, Id, Step, StepShared, Task, ThroughputOnDrop, Value, UNKNOWN},
9+
progress::{
10+
AtomicStep, Discard, DoOrDiscard, Either, Id, Step, StepShared, Task, ThroughputOnDrop, Value, UNKNOWN,
11+
},
1012
unit, Count, NestedProgress, Progress, Unit,
1113
};
1214
/// A stub for the portions of the `bytesize` crate that we use internally in `gitoxide`.

gix-pack/src/data/file/verify.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::sync::atomic::AtomicBool;
2-
31
use gix_features::progress::Progress;
2+
use std::sync::atomic::AtomicBool;
43

54
use crate::data::File;
65

gix-pack/src/data/output/count/objects/mod.rs

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
use std::{
2-
cell::RefCell,
3-
sync::{atomic::AtomicBool, Arc},
4-
};
1+
use std::{cell::RefCell, sync::atomic::AtomicBool};
52

6-
use gix_features::progress::NestedProgress;
7-
use gix_features::{parallel, progress::Progress};
3+
use gix_features::parallel;
84
use gix_hash::ObjectId;
95

106
use crate::{data::output, find};
@@ -30,16 +26,16 @@ pub type Result<E1, E2> = std::result::Result<(Vec<output::Count>, Outcome), Err
3026
/// * `objects_ids`
3127
/// * A list of objects ids to add to the pack. Duplication checks are performed so no object is ever added to a pack twice.
3228
/// * Objects may be expanded based on the provided [`options`][Options]
33-
/// * `progress`
34-
/// * a way to obtain progress information
29+
/// * `objects`
30+
/// * count the amount of objects we encounter
3531
/// * `should_interrupt`
3632
/// * A flag that is set to true if the operation should stop
3733
/// * `options`
3834
/// * more configuration
3935
pub fn objects<Find, Iter, IterErr, Oid>(
4036
db: Find,
4137
objects_ids: Iter,
42-
progress: impl NestedProgress,
38+
objects: &dyn gix_features::progress::Count,
4339
should_interrupt: &AtomicBool,
4440
Options {
4541
thread_limit,
@@ -66,52 +62,45 @@ where
6662
size: chunk_size,
6763
};
6864
let seen_objs = gix_hashtable::sync::ObjectIdMap::default();
69-
let progress = Arc::new(parking_lot::Mutex::new(progress));
65+
let objects = objects.counter();
7066

7167
parallel::in_parallel(
7268
chunks,
7369
thread_limit,
7470
{
75-
let progress = Arc::clone(&progress);
76-
move |n| {
71+
move |_| {
7772
(
7873
Vec::new(), // object data buffer
7974
Vec::new(), // object data buffer 2 to hold two objects at a time
80-
{
81-
let mut p = progress
82-
.lock()
83-
.add_child_with_id(format!("thread {n}"), gix_features::progress::UNKNOWN);
84-
p.init(None, gix_features::progress::count("objects"));
85-
p
86-
},
75+
objects.clone(),
8776
)
8877
}
8978
},
9079
{
9180
let seen_objs = &seen_objs;
92-
move |oids: Vec<std::result::Result<Oid, IterErr>>, (buf1, buf2, progress)| {
81+
move |oids: Vec<std::result::Result<Oid, IterErr>>, (buf1, buf2, objects)| {
9382
expand::this(
9483
&db,
9584
input_object_expansion,
9685
seen_objs,
9786
oids,
9887
buf1,
9988
buf2,
100-
progress,
89+
objects,
10190
should_interrupt,
10291
true, /*allow pack lookups*/
10392
)
10493
}
10594
},
106-
reduce::Statistics::new(progress),
95+
reduce::Statistics::new(),
10796
)
10897
}
10998

11099
/// Like [`objects()`] but using a single thread only to mostly save on the otherwise required overhead.
111100
pub fn objects_unthreaded<Find, IterErr, Oid>(
112101
db: Find,
113102
object_ids: impl Iterator<Item = std::result::Result<Oid, IterErr>>,
114-
mut progress: impl Progress,
103+
objects: impl gix_features::progress::Count,
115104
should_interrupt: &AtomicBool,
116105
input_object_expansion: ObjectExpansion,
117106
) -> Result<find::existing::Error<Find::Error>, IterErr>
@@ -130,7 +119,7 @@ where
130119
object_ids,
131120
&mut buf1,
132121
&mut buf2,
133-
&mut progress,
122+
&objects.counter(),
134123
should_interrupt,
135124
false, /*allow pack lookups*/
136125
)
@@ -139,7 +128,6 @@ where
139128
mod expand {
140129
use std::sync::atomic::{AtomicBool, Ordering};
141130

142-
use gix_features::progress::Progress;
143131
use gix_hash::{oid, ObjectId};
144132
use gix_object::{CommitRefIter, TagRefIter};
145133

@@ -161,7 +149,7 @@ mod expand {
161149
oids: impl IntoIterator<Item = std::result::Result<Oid, IterErr>>,
162150
buf1: &mut Vec<u8>,
163151
#[allow(clippy::ptr_arg)] buf2: &mut Vec<u8>,
164-
progress: &mut impl Progress,
152+
objects: &gix_features::progress::AtomicStep,
165153
should_interrupt: &AtomicBool,
166154
allow_pack_lookups: bool,
167155
) -> super::Result<find::existing::Error<Find::Error>, IterErr>
@@ -197,7 +185,7 @@ mod expand {
197185
let mut id = id.to_owned();
198186

199187
loop {
200-
push_obj_count_unique(&mut out, seen_objs, &id, location, progress, stats, false);
188+
push_obj_count_unique(&mut out, seen_objs, &id, location, objects, stats, false);
201189
match obj.kind {
202190
Tree | Blob => break,
203191
Tag => {
@@ -228,12 +216,12 @@ mod expand {
228216
}
229217
let (obj, location) = db.find(tree_id, buf1)?;
230218
push_obj_count_unique(
231-
&mut out, seen_objs, &tree_id, location, progress, stats, true,
219+
&mut out, seen_objs, &tree_id, location, objects, stats, true,
232220
);
233221
gix_object::TreeRefIter::from_bytes(obj.data)
234222
};
235223

236-
let objects = if parent_commit_ids.is_empty() {
224+
let objects_ref = if parent_commit_ids.is_empty() {
237225
traverse_delegate.clear();
238226
gix_traverse::tree::breadthfirst(
239227
current_tree_iter,
@@ -242,7 +230,7 @@ mod expand {
242230
stats.decoded_objects += 1;
243231
match db.find(oid, buf).ok() {
244232
Some((obj, location)) => {
245-
progress.inc();
233+
objects.fetch_add(1, Ordering::Relaxed);
246234
stats.expanded_objects += 1;
247235
out.push(output::Count::from_data(oid, location));
248236
obj.try_into_tree_iter()
@@ -260,7 +248,7 @@ mod expand {
260248
let (parent_commit_obj, location) = db.find(commit_id, buf2)?;
261249

262250
push_obj_count_unique(
263-
&mut out, seen_objs, commit_id, location, progress, stats, true,
251+
&mut out, seen_objs, commit_id, location, objects, stats, true,
264252
);
265253
CommitRefIter::from_bytes(parent_commit_obj.data)
266254
.tree_id()
@@ -273,7 +261,7 @@ mod expand {
273261
seen_objs,
274262
&parent_tree_id,
275263
location,
276-
progress,
264+
objects,
277265
stats,
278266
true,
279267
);
@@ -295,8 +283,8 @@ mod expand {
295283
}
296284
&changes_delegate.objects
297285
};
298-
for id in objects.iter() {
299-
out.push(id_to_count(db, buf2, id, progress, stats, allow_pack_lookups));
286+
for id in objects_ref.iter() {
287+
out.push(id_to_count(db, buf2, id, objects, stats, allow_pack_lookups));
300288
}
301289
break;
302290
}
@@ -308,7 +296,7 @@ mod expand {
308296
let mut id = id;
309297
let mut obj = (obj, location);
310298
loop {
311-
push_obj_count_unique(&mut out, seen_objs, &id, obj.1.clone(), progress, stats, false);
299+
push_obj_count_unique(&mut out, seen_objs, &id, obj.1.clone(), objects, stats, false);
312300
match obj.0.kind {
313301
Tree => {
314302
traverse_delegate.clear();
@@ -319,7 +307,7 @@ mod expand {
319307
stats.decoded_objects += 1;
320308
match db.find(oid, buf).ok() {
321309
Some((obj, location)) => {
322-
progress.inc();
310+
objects.fetch_add(1, Ordering::Relaxed);
323311
stats.expanded_objects += 1;
324312
out.push(output::Count::from_data(oid, location));
325313
obj.try_into_tree_iter()
@@ -331,7 +319,7 @@ mod expand {
331319
)
332320
.map_err(Error::TreeTraverse)?;
333321
for id in &traverse_delegate.non_trees {
334-
out.push(id_to_count(db, buf1, id, progress, stats, allow_pack_lookups));
322+
out.push(id_to_count(db, buf1, id, objects, stats, allow_pack_lookups));
335323
}
336324
break;
337325
}
@@ -355,7 +343,7 @@ mod expand {
355343
}
356344
}
357345
}
358-
AsIs => push_obj_count_unique(&mut out, seen_objs, &id, location, progress, stats, false),
346+
AsIs => push_obj_count_unique(&mut out, seen_objs, &id, location, objects, stats, false),
359347
}
360348
}
361349
outcome.total_objects = out.len();
@@ -368,13 +356,13 @@ mod expand {
368356
all_seen: &impl util::InsertImmutable,
369357
id: &oid,
370358
location: Option<crate::data::entry::Location>,
371-
progress: &mut impl Progress,
359+
objects: &gix_features::progress::AtomicStep,
372360
statistics: &mut Outcome,
373361
count_expanded: bool,
374362
) {
375363
let inserted = all_seen.insert(id.to_owned());
376364
if inserted {
377-
progress.inc();
365+
objects.fetch_add(1, Ordering::Relaxed);
378366
statistics.decoded_objects += 1;
379367
if count_expanded {
380368
statistics.expanded_objects += 1;
@@ -388,11 +376,11 @@ mod expand {
388376
db: &Find,
389377
buf: &mut Vec<u8>,
390378
id: &oid,
391-
progress: &mut impl Progress,
379+
objects: &gix_features::progress::AtomicStep,
392380
statistics: &mut Outcome,
393381
allow_pack_lookups: bool,
394382
) -> output::Count {
395-
progress.inc();
383+
objects.fetch_add(1, Ordering::Relaxed);
396384
statistics.expanded_objects += 1;
397385
output::Count {
398386
id: id.to_owned(),

gix-pack/src/data/output/count/objects/reduce.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
use std::{marker::PhantomData, sync::Arc};
1+
use std::marker::PhantomData;
22

3-
use gix_features::{parallel, progress::Progress};
3+
use gix_features::parallel;
44

55
use super::Outcome;
66
use crate::data::output;
77

8-
pub struct Statistics<E, P> {
8+
pub struct Statistics<E> {
99
total: Outcome,
1010
counts: Vec<output::Count>,
11-
progress: Arc<parking_lot::Mutex<P>>,
1211
_err: PhantomData<E>,
1312
}
1413

15-
impl<E, P> Statistics<E, P>
16-
where
17-
P: Progress,
18-
{
19-
pub fn new(progress: Arc<parking_lot::Mutex<P>>) -> Self {
14+
impl<E> Statistics<E> {
15+
pub fn new() -> Self {
2016
Statistics {
2117
total: Default::default(),
2218
counts: Default::default(),
23-
progress,
2419
_err: PhantomData,
2520
}
2621
}
2722
}
2823

29-
impl<E, P> parallel::Reduce for Statistics<E, P>
30-
where
31-
P: Progress,
32-
{
24+
impl<E> parallel::Reduce for Statistics<E> {
3325
type Input = Result<(Vec<output::Count>, Outcome), E>;
3426
type FeedProduce = ();
3527
type Output = (Vec<output::Count>, Outcome);
@@ -38,7 +30,6 @@ where
3830
fn feed(&mut self, item: Self::Input) -> Result<Self::FeedProduce, Self::Error> {
3931
let (counts, stats) = item?;
4032
self.total.aggregate(stats);
41-
self.progress.lock().inc_by(counts.len());
4233
self.counts.extend(counts);
4334
Ok(())
4435
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn traversals() -> crate::Result {
264264
})))
265265
.filter(|o| !o.is_null())
266266
.map(Ok::<_, Infallible>),
267-
progress::Discard,
267+
&progress::Discard,
268268
&AtomicBool::new(false),
269269
count::objects::Options {
270270
input_object_expansion: expansion_mode,

0 commit comments

Comments
 (0)