Skip to content

Commit 6901a09

Browse files
committed
First part of migration to prodash 8.0, but…
…supporting more features like throughput and custom formatting won't really be possible without duplicating/providing all trait implementations. Maybe prodash could in fact provide a version of itself without the tree, making it optional, to allow avoiding to continue duplicating efforts.
1 parent df4a186 commit 6901a09

File tree

15 files changed

+45
-44
lines changed

15 files changed

+45
-44
lines changed

Diff for: Cargo.lock

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

Diff for: Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ git-features = { version = "^0.2.0", path = "git-features" }
6363

6464
clap = { version = "3.0.0-beta.1", optional = true }
6565
argh = { version = "0.1.3", optional = true, default-features = false }
66-
prodash = { version = "7.0.2", optional = true, default-features = false }
66+
prodash = { version = "8.0.0", optional = true, default-features = false }
6767
atty = { version = "0.2.14", optional = true, default-features = false }
6868
env_logger = { version = "0.7.1", optional = true, default-features = false, features = ["humantime", "termcolor", "atty"] }
6969
crosstermion = { version = "0.3.0", optional = true, default-features = false }
@@ -89,3 +89,6 @@ members = [
8989
"git-tui",
9090
"demos"
9191
]
92+
93+
[patch.crates-io]
94+
prodash = { path = "../crates-io/prodash" }

Diff for: git-features/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fastsha1 = { package = "sha-1", version = "0.9.1", optional = true }
4646

4747
# progress
4848
log = { version = "0.4.8", optional = true }
49-
prodash = { version = "7.0.2", optional = true, default-features = false }
49+
prodash = { version = "8.0.0", optional = true, default-features = false }
5050

5151
# interruptible
5252
ctrlc = { version = "3.1.4", optional = true, default-features = false, features = ['termination'] }

Diff for: git-features/src/progress/log.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::time::Duration;
33

44
pub struct Log {
55
name: String,
6-
max: Option<u32>,
6+
max: Option<usize>,
77
unit: Option<&'static str>,
88
last_set: Option<std::time::SystemTime>,
9-
step: u32,
9+
step: usize,
1010
current_level: usize,
1111
max_level: usize,
1212
}
@@ -42,12 +42,12 @@ impl Progress for Log {
4242
}
4343
}
4444

45-
fn init(&mut self, max: Option<u32>, unit: Option<&'static str>) {
45+
fn init(&mut self, max: Option<usize>, unit: Option<&'static str>) {
4646
self.max = max;
4747
self.unit = unit;
4848
}
4949

50-
fn set(&mut self, step: u32) {
50+
fn set(&mut self, step: usize) {
5151
self.step = step;
5252
if self.current_level > self.max_level {
5353
return;
@@ -73,7 +73,7 @@ impl Progress for Log {
7373
}
7474
}
7575

76-
fn inc_by(&mut self, step: u32) {
76+
fn inc_by(&mut self, step: usize) {
7777
self.set(self.step + step)
7878
}
7979

Diff for: git-features/src/progress/mod.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ pub trait Progress {
3232
/// to the progress tree (e.g. a headline).
3333
///
3434
/// **Note** that this method can be called multiple times, changing the bounded-ness and unit at will.
35-
fn init(&mut self, max: Option<u32>, unit: Option<&'static str>);
35+
fn init(&mut self, max: Option<usize>, unit: Option<&'static str>);
3636

3737
/// Set the current progress to the given `step`. The cost of this call is negligible,
3838
/// making manual throttling *not* necessary.
3939
///
4040
/// **Note**: that this call has no effect unless `init(…)` was called before.
41-
fn set(&mut self, step: u32);
41+
fn set(&mut self, step: usize);
4242

4343
/// Increment the current progress to the given `step`. The cost of this call is negligible,
4444
/// making manual throttling *not* necessary.
4545
///
4646
/// **Note**: that this call has no effect unless `init(…)` was called before.
47-
fn inc_by(&mut self, step: u32);
47+
fn inc_by(&mut self, step: usize);
4848

4949
/// Increment the current progress to the given 1. The cost of this call is negligible,
5050
/// making manual throttling *not* necessary.
@@ -73,7 +73,7 @@ pub trait Progress {
7373
self.message(MessageLevel::Failure, message)
7474
}
7575
/// A shorthand to print throughput information
76-
fn show_throughput(&mut self, start: Instant, total_items: u32, item_name: &str) {
76+
fn show_throughput(&mut self, start: Instant, total_items: usize, item_name: &str) {
7777
let elapsed = start.elapsed().as_secs_f32();
7878
self.info(format!(
7979
"done {} {} in {:.02}s ({} {}/s)",
@@ -95,11 +95,11 @@ impl Progress for Discard {
9595
Discard
9696
}
9797

98-
fn init(&mut self, _max: Option<u32>, _unit: Option<&'static str>) {}
98+
fn init(&mut self, _max: Option<usize>, _unit: Option<&'static str>) {}
9999

100-
fn set(&mut self, _step: u32) {}
100+
fn set(&mut self, _step: usize) {}
101101

102-
fn inc_by(&mut self, _step: u32) {}
102+
fn inc_by(&mut self, _step: usize) {}
103103

104104
fn message(&mut self, _level: MessageLevel, _message: impl Into<String>) {}
105105
}
@@ -123,21 +123,21 @@ where
123123
}
124124
}
125125

126-
fn init(&mut self, max: Option<u32>, unit: Option<&'static str>) {
126+
fn init(&mut self, max: Option<usize>, unit: Option<&'static str>) {
127127
match self {
128128
Either::Left(l) => l.init(max, unit),
129129
Either::Right(r) => r.init(max, unit),
130130
}
131131
}
132132

133-
fn set(&mut self, step: u32) {
133+
fn set(&mut self, step: usize) {
134134
match self {
135135
Either::Left(l) => l.set(step),
136136
Either::Right(r) => r.set(step),
137137
}
138138
}
139139

140-
fn inc_by(&mut self, step: u32) {
140+
fn inc_by(&mut self, step: usize) {
141141
match self {
142142
Either::Left(l) => l.inc_by(step),
143143
Either::Right(r) => r.inc_by(step),
@@ -184,15 +184,15 @@ where
184184
DoOrDiscard(self.0.add_child(name))
185185
}
186186

187-
fn init(&mut self, max: Option<u32>, unit: Option<&'static str>) {
187+
fn init(&mut self, max: Option<usize>, unit: Option<&'static str>) {
188188
self.0.init(max, unit)
189189
}
190190

191-
fn set(&mut self, step: u32) {
191+
fn set(&mut self, step: usize) {
192192
self.0.set(step)
193193
}
194194

195-
fn inc_by(&mut self, step: u32) {
195+
fn inc_by(&mut self, step: usize) {
196196
self.0.inc_by(step)
197197
}
198198

@@ -214,7 +214,7 @@ where
214214
{
215215
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
216216
let bytes_read = self.reader.read(buf)?;
217-
self.progress.inc_by(bytes_read as u32);
217+
self.progress.inc_by(bytes_read as usize);
218218
Ok(bytes_read)
219219
}
220220
}

Diff for: git-features/src/progress/prodash.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ impl Progress for Item {
99
Item::add_child(self, name)
1010
}
1111

12-
fn init(&mut self, max: Option<u32>, unit: Option<&'static str>) {
13-
Item::init(self, max, unit)
12+
fn init(&mut self, max: Option<usize>, unit: Option<&'static str>) {
13+
Item::init(self, max, unit.map(|u| u.into()))
1414
}
1515

16-
fn set(&mut self, step: u32) {
16+
fn set(&mut self, step: usize) {
1717
Item::set(self, step)
1818
}
1919

20-
fn inc_by(&mut self, step: u32) {
20+
fn inc_by(&mut self, step: usize) {
2121
self.inc_by(step)
2222
}
2323

Diff for: git-odb/src/pack/bundle/write/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl pack::Bundle {
4040
<<P as Progress>::SubProgress as Progress>::SubProgress: Send,
4141
{
4242
let mut read_progress = progress.add_child("read pack");
43-
read_progress.init(pack_size.map(|s| s as u32), Some("bytes"));
43+
read_progress.init(pack_size.map(|s| s as usize), Some("bytes"));
4444
let pack = progress::Read {
4545
reader: pack,
4646
progress: read_progress,

Diff for: git-odb/src/pack/index/traverse/lookup.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl index::File {
3939
let input_chunks = index_entries.chunks(chunk_size.max(chunk_size));
4040
let reduce_progress = parking_lot::Mutex::new({
4141
let mut p = root.add_child("Traversing");
42-
p.init(Some(self.num_objects()), Some("objects"));
42+
p.init(Some(self.num_objects() as usize), Some("objects"));
4343
p
4444
});
4545
let state_per_thread = |index| {
@@ -59,7 +59,7 @@ impl index::File {
5959
|entries: &[index::Entry],
6060
(cache, ref mut processor, buf, progress)|
6161
-> Result<Vec<decode::Outcome>, Error> {
62-
progress.init(Some(entries.len() as u32), Some("entries"));
62+
progress.init(Some(entries.len()), Some("entries"));
6363
let mut stats = Vec::with_capacity(entries.len());
6464
let mut header_buf = [0u8; 64];
6565
for index_entry in entries.iter() {

Diff for: git-odb/src/pack/index/traverse/reduce.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Reducer<'a, P> {
2222
progress: &'a parking_lot::Mutex<P>,
2323
check: traverse::SafetyCheck,
2424
then: Instant,
25-
entries_seen: u32,
25+
entries_seen: usize,
2626
stats: traverse::Outcome,
2727
}
2828

@@ -63,7 +63,7 @@ where
6363
}
6464
res => res,
6565
}?;
66-
self.entries_seen += chunk_stats.len() as u32;
66+
self.entries_seen += chunk_stats.len();
6767

6868
let chunk_total = chunk_stats.into_iter().fold(
6969
decode::Outcome::default_from_kind(git_object::Kind::Tree),

Diff for: git-odb/src/pack/index/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub(crate) fn index_entries_sorted_by_offset_ascending(
66
idx: &pack::index::File,
77
mut progress: impl Progress,
88
) -> Vec<pack::index::Entry> {
9-
progress.init(Some(idx.num_objects), Some("entries"));
9+
progress.init(Some(idx.num_objects as usize), Some("entries"));
1010
let start = Instant::now();
1111

1212
let mut v = Vec::with_capacity(idx.num_objects as usize);
@@ -16,7 +16,7 @@ pub(crate) fn index_entries_sorted_by_offset_ascending(
1616
}
1717
v.sort_by_key(|e| e.pack_offset);
1818

19-
progress.show_throughput(start, idx.num_objects, "entries");
19+
progress.show_throughput(start, idx.num_objects as usize, "entries");
2020
v
2121
}
2222

Diff for: git-odb/src/pack/index/write/encode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub(crate) fn to_write(
114114
out.inner.inner.flush()?;
115115

116116
progress.inc();
117-
progress.show_throughput(start, out.bytes as u32, "bytes");
117+
progress.show_throughput(start, out.bytes as usize, "bytes");
118118

119119
Ok(index_hash)
120120
}

Diff for: git-odb/src/pack/index/write/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl pack::index::File {
6868

6969
root_progress.init(Some(4), Some("steps"));
7070
let mut progress = root_progress.add_child("indexing");
71-
progress.init(entries.size_hint().1.map(|l| l as u32), Some("objects"));
71+
progress.init(entries.size_hint().1, Some("objects"));
7272
let mut pack_entries_end: u64 = 0;
7373

7474
for (eid, entry) in entries.enumerate() {
@@ -133,7 +133,7 @@ impl pack::index::File {
133133
.try_into()
134134
.map_err(|_| Error::IteratorInvariantTooManyObjects(num_objects))?;
135135
last_base_index.ok_or(Error::IteratorInvariantBasesPresent)?;
136-
progress.show_throughput(indexing_start, num_objects, "objects");
136+
progress.show_throughput(indexing_start, num_objects as usize, "objects");
137137
drop(progress);
138138

139139
root_progress.inc();
@@ -174,7 +174,7 @@ impl pack::index::File {
174174
kind,
175175
root_progress.add_child("writing index file"),
176176
)?;
177-
root_progress.show_throughput(indexing_start, num_objects, "objects");
177+
root_progress.show_throughput(indexing_start, num_objects as usize, "objects");
178178
Ok(Outcome {
179179
index_kind: kind,
180180
index_hash,

Diff for: git-odb/src/pack/tree/from_offsets.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T> Tree<T> {
4747
);
4848

4949
let anticpiated_num_objects = if let Some(num_objects) = data_sorted_by_offsets.size_hint().1 {
50-
progress.init(Some(num_objects as u32), Some("objects"));
50+
progress.init(Some(num_objects), Some("objects"));
5151
num_objects
5252
} else {
5353
0

Diff for: git-odb/src/pack/tree/traverse/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ where
9494
P: Progress,
9595
{
9696
pub fn new(num_objects: u32, progress: &'a parking_lot::Mutex<P>) -> Self {
97-
progress.lock().init(Some(num_objects), Some("objects"));
97+
progress.lock().init(Some(num_objects as usize), Some("objects"));
9898
Reducer {
9999
item_count: 0,
100100
progress,
@@ -114,7 +114,7 @@ where
114114
fn feed(&mut self, input: Self::Input) -> Result<(), Self::Error> {
115115
let input = input?;
116116
self.item_count += input;
117-
self.progress.lock().set(self.item_count as u32);
117+
self.progress.lock().set(self.item_count);
118118
if is_interrupted() {
119119
return Err(Error::Interrupted);
120120
}
@@ -124,7 +124,7 @@ where
124124
fn finalize(self) -> Result<Self::Output, Self::Error> {
125125
self.progress
126126
.lock()
127-
.show_throughput(self.start, self.item_count as u32, "objects");
127+
.show_throughput(self.start, self.item_count, "objects");
128128
Ok(())
129129
}
130130
}

Diff for: tasks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* [x] use usize for progress counting
4545
* [x] Unit conversion probably using a new Unit enum (to support more than just bare strings)
4646
* [x] percentages somewhere near the progress bar
47-
* [ ] Find a way to measure live throughput (in line renderer and tui renderer)
47+
* [x] Find a way to measure live throughput (in line renderer and tui renderer)
4848
* [ ] ~~a way to measure throughput on drop~~ - we don't know if the operation was successful, should not be automatic, ever
4949
* **asciinemas**
5050
* [ ] explode

0 commit comments

Comments
 (0)