Skip to content

Commit ed327f6

Browse files
committed
chore!: update to the latest prodash
It makes proper usage of `Progress` types easier and allows them to be used as `dyn` traits as well.
1 parent 04494c6 commit ed327f6

File tree

56 files changed

+214
-277
lines changed

Some content is hidden

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

56 files changed

+214
-277
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: Cargo.toml

+1-1
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 = "25.0.0", optional = true, default-features = false }
171+
prodash = { version = "26.0.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 }

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

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66

77
use anyhow::{bail, Context};
88
use bytesize::ByteSize;
9-
use gix::Progress;
9+
use gix::{Count, NestedProgress, Progress};
1010
use rusqlite::params;
1111

1212
use super::db;
@@ -55,7 +55,7 @@ impl Engine {
5555
pub fn refresh(&mut self, corpus_path: PathBuf) -> anyhow::Result<()> {
5656
let (corpus_path, corpus_id) = self.prepare_corpus_path(corpus_path)?;
5757
let repos = self.refresh_repos(&corpus_path, corpus_id)?;
58-
self.state.progress.set_name("refresh repos");
58+
self.state.progress.set_name("refresh repos".into());
5959
self.state.progress.info(format!(
6060
"Added or updated {} repositories under {corpus_path:?}",
6161
repos.len()
@@ -87,7 +87,7 @@ impl Engine {
8787
repo_progress.init(Some(repos.len()), gix::progress::count("repos"));
8888
if task.execute_exclusive || threads == 1 || dry_run {
8989
if dry_run {
90-
repo_progress.set_name("WOULD run");
90+
repo_progress.set_name("WOULD run".into());
9191
for repo in &repos {
9292
repo_progress.info(format!(
9393
"{}",
@@ -202,13 +202,11 @@ impl Engine {
202202
task.perform(&mut run, &repo.path, progress, Some(1), should_interrupt);
203203
});
204204
if let Some(err) = run.error.as_deref() {
205-
num_errors.fetch_add(1, Ordering::SeqCst);
205+
num_errors.fetch_add(1, Ordering::Relaxed);
206206
progress.fail(err.to_owned());
207207
}
208208
Self::update_run(con, run)?;
209-
if let Some(counter) = counter.as_ref() {
210-
counter.fetch_add(1, Ordering::SeqCst);
211-
}
209+
counter.fetch_add(1, Ordering::Relaxed);
212210
Ok(())
213211
},
214212
|| (!gix::interrupt::is_triggered()).then(|| Duration::from_millis(100)),
@@ -243,7 +241,7 @@ impl Engine {
243241
corpus_id: db::Id,
244242
sql_suffix: Option<&str>,
245243
) -> anyhow::Result<Vec<db::Repo>> {
246-
self.state.progress.set_name("query db-repos");
244+
self.state.progress.set_name("query db-repos".into());
247245
self.state.progress.init(None, gix::progress::count("repos"));
248246

249247
Ok(self
@@ -267,7 +265,7 @@ impl Engine {
267265

268266
fn refresh_repos(&mut self, corpus_path: &Path, corpus_id: db::Id) -> anyhow::Result<Vec<db::Repo>> {
269267
let start = Instant::now();
270-
self.state.progress.set_name("refresh");
268+
self.state.progress.set_name("refresh".into());
271269
self.state.progress.init(None, gix::progress::count("repos"));
272270

273271
let repos = std::thread::scope({
@@ -302,7 +300,7 @@ impl Engine {
302300

303301
let find_progress = progress.add_child("find");
304302
let write_db = scope.spawn(move || -> anyhow::Result<Vec<db::Repo>> {
305-
progress.set_name("write to DB");
303+
progress.set_name("write to DB".into());
306304
progress.init(None, gix::progress::count("repos"));
307305

308306
let mut out = Vec::new();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ impl tracing_forest::printer::Formatter for StoreTreeToDb {
5151
use gix::Progress;
5252
if self.reverse_lines {
5353
for line in tree.lines().rev() {
54-
progress.info(line);
54+
progress.info(line.into());
5555
}
5656
} else {
5757
for line in tree.lines() {
58-
progress.info(line);
58+
progress.info(line.into());
5959
}
6060
}
6161
}

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

+9-24
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ pub fn estimate_hours(
6767
}
6868
}
6969

70-
type CommitChangeLineCounters = (
71-
Option<Arc<AtomicUsize>>,
72-
Option<Arc<AtomicUsize>>,
73-
Option<Arc<AtomicUsize>>,
74-
);
70+
type CommitChangeLineCounters = (Arc<AtomicUsize>, Arc<AtomicUsize>, Arc<AtomicUsize>);
7571

7672
type SpawnResultWithReturnChannelAndWorkers<'scope> = (
7773
crossbeam_channel::Sender<Vec<(CommitIdx, Option<gix::hash::ObjectId>, gix::hash::ObjectId)>>,
@@ -95,7 +91,7 @@ pub fn spawn_tree_delta_threads<'scope>(
9591
let rx = rx.clone();
9692
move || -> Result<_, anyhow::Error> {
9793
let mut out = Vec::new();
98-
let (commit_counter, change_counter, lines_counter) = stats_counters;
94+
let (commits, changes, lines_count) = stats_counters;
9995
let mut attributes = line_stats
10096
.then(|| -> anyhow::Result<_> {
10197
repo.index_or_load_from_head().map_err(Into::into).and_then(|index| {
@@ -115,9 +111,7 @@ pub fn spawn_tree_delta_threads<'scope>(
115111
.transpose()?;
116112
for chunk in rx {
117113
for (commit_idx, parent_commit, commit) in chunk {
118-
if let Some(c) = commit_counter.as_ref() {
119-
c.fetch_add(1, Ordering::SeqCst);
120-
}
114+
commits.fetch_add(1, Ordering::Relaxed);
121115
if gix::interrupt::is_triggered() {
122116
return Ok(out);
123117
}
@@ -139,23 +133,21 @@ pub fn spawn_tree_delta_threads<'scope>(
139133
.track_rewrites(None)
140134
.for_each_to_obtain_tree(&to, |change| {
141135
use gix::object::tree::diff::change::Event::*;
142-
if let Some(c) = change_counter.as_ref() {
143-
c.fetch_add(1, Ordering::SeqCst);
144-
}
136+
changes.fetch_add(1, Ordering::Relaxed);
145137
match change.event {
146138
Rewrite { .. } => {
147139
unreachable!("we turned that off")
148140
}
149141
Addition { entry_mode, id } => {
150142
if entry_mode.is_no_tree() {
151143
files.added += 1;
152-
add_lines(line_stats, lines_counter.as_deref(), &mut lines, id);
144+
add_lines(line_stats, &lines_count, &mut lines, id);
153145
}
154146
}
155147
Deletion { entry_mode, id } => {
156148
if entry_mode.is_no_tree() {
157149
files.removed += 1;
158-
remove_lines(line_stats, lines_counter.as_deref(), &mut lines, id);
150+
remove_lines(line_stats, &lines_count, &mut lines, id);
159151
}
160152
}
161153
Modification {
@@ -168,16 +160,11 @@ pub fn spawn_tree_delta_threads<'scope>(
168160
(false, false) => {}
169161
(false, true) => {
170162
files.added += 1;
171-
add_lines(line_stats, lines_counter.as_deref(), &mut lines, id);
163+
add_lines(line_stats, &lines_count, &mut lines, id);
172164
}
173165
(true, false) => {
174166
files.removed += 1;
175-
remove_lines(
176-
line_stats,
177-
lines_counter.as_deref(),
178-
&mut lines,
179-
previous_id,
180-
);
167+
remove_lines(line_stats, &lines_count, &mut lines, previous_id);
181168
}
182169
(true, true) => {
183170
files.modified += 1;
@@ -203,9 +190,7 @@ pub fn spawn_tree_delta_threads<'scope>(
203190
nl += counts.insertions as usize + counts.removals as usize;
204191
lines.added += counts.insertions as usize;
205192
lines.removed += counts.removals as usize;
206-
if let Some(c) = lines_counter.as_ref() {
207-
c.fetch_add(nl, Ordering::SeqCst);
208-
}
193+
lines_count.fetch_add(nl, Ordering::Relaxed);
209194
}
210195
}
211196
}

Diff for: gitoxide-core/src/hours/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use gix::{
55
actor,
66
bstr::{BStr, ByteSlice},
77
prelude::*,
8-
progress, Progress,
8+
progress, Count, NestedProgress, Progress,
99
};
1010

1111
/// Additional configuration for the hours estimation functionality.
@@ -49,7 +49,7 @@ pub fn estimate<W, P>(
4949
) -> anyhow::Result<()>
5050
where
5151
W: io::Write,
52-
P: Progress,
52+
P: NestedProgress,
5353
{
5454
let repo = gix::discover(working_dir)?;
5555
let commit_id = repo.rev_parse_single(rev_spec)?.detach();

Diff for: gitoxide-core/src/hours/util.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,18 @@ impl LineStats {
158158
/// An index able to address any commit
159159
pub type CommitIdx = u32;
160160

161-
pub fn add_lines(line_stats: bool, lines_counter: Option<&AtomicUsize>, lines: &mut LineStats, id: gix::Id<'_>) {
161+
pub fn add_lines(line_stats: bool, lines_counter: &AtomicUsize, lines: &mut LineStats, id: gix::Id<'_>) {
162162
if let Some(Ok(blob)) = line_stats.then(|| id.object()) {
163163
let nl = blob.data.lines_with_terminator().count();
164164
lines.added += nl;
165-
if let Some(c) = lines_counter {
166-
c.fetch_add(nl, Ordering::SeqCst);
167-
}
165+
lines_counter.fetch_add(nl, Ordering::Relaxed);
168166
}
169167
}
170168

171-
pub fn remove_lines(line_stats: bool, lines_counter: Option<&AtomicUsize>, lines: &mut LineStats, id: gix::Id<'_>) {
169+
pub fn remove_lines(line_stats: bool, lines_counter: &AtomicUsize, lines: &mut LineStats, id: gix::Id<'_>) {
172170
if let Some(Ok(blob)) = line_stats.then(|| id.object()) {
173171
let nl = blob.data.lines_with_terminator().count();
174172
lines.removed += nl;
175-
if let Some(c) = lines_counter {
176-
c.fetch_add(nl, Ordering::SeqCst);
177-
}
173+
lines_counter.fetch_add(nl, Ordering::Relaxed);
178174
}
179175
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
};
55

66
use anyhow::bail;
7-
use gix::{odb::FindExt, worktree::state::checkout, Progress};
7+
use gix::{odb::FindExt, worktree::state::checkout, NestedProgress, Progress};
88

99
use crate::{
1010
index,
@@ -16,7 +16,7 @@ pub fn checkout_exclusive(
1616
dest_directory: impl AsRef<Path>,
1717
repo: Option<PathBuf>,
1818
mut err: impl std::io::Write,
19-
mut progress: impl Progress,
19+
mut progress: impl NestedProgress,
2020
should_interrupt: &AtomicBool,
2121
index::checkout_exclusive::Options {
2222
index: Options { object_hash, .. },

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
path::{Path, PathBuf},
44
};
55

6-
use gix::{objs::bstr::ByteSlice, progress, Progress};
6+
use gix::{objs::bstr::ByteSlice, progress, NestedProgress, Progress};
77

88
#[derive(Default, Copy, Clone, Eq, PartialEq)]
99
pub enum Mode {
@@ -207,7 +207,7 @@ fn handle(
207207
}
208208

209209
/// Find all working directories in the given `source_dir` and print them to `out` while providing `progress`.
210-
pub fn discover<P: Progress>(
210+
pub fn discover<P: NestedProgress>(
211211
source_dir: impl AsRef<Path>,
212212
mut out: impl std::io::Write,
213213
mut progress: P,
@@ -222,7 +222,7 @@ pub fn discover<P: Progress>(
222222
Ok(())
223223
}
224224

225-
pub fn run<P: Progress>(
225+
pub fn run<P: NestedProgress>(
226226
mode: Mode,
227227
source_dir: impl AsRef<Path>,
228228
destination: impl AsRef<Path>,

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use gix::{
99
odb::{pack, pack::FindExt},
1010
parallel::InOrderIter,
1111
prelude::Finalize,
12-
progress, traverse, Progress,
12+
progress, traverse, Count, NestedProgress, Progress,
1313
};
1414

1515
use crate::OutputFormat;
@@ -109,7 +109,7 @@ pub fn create<W, P>(
109109
) -> anyhow::Result<()>
110110
where
111111
W: std::io::Write,
112-
P: Progress,
112+
P: NestedProgress,
113113
P::SubProgress: 'static,
114114
{
115115
let repo = gix::discover(repository_path)?.into_sync();
@@ -179,7 +179,7 @@ where
179179
Some(1)
180180
};
181181
if nondeterministic_thread_count.is_some() && !may_use_multiple_threads {
182-
progress.fail("Cannot use multi-threaded counting in tree-diff object expansion mode as it may yield way too many objects.");
182+
progress.fail("Cannot use multi-threaded counting in tree-diff object expansion mode as it may yield way too many objects.".into());
183183
}
184184
let (_, _, thread_count) = gix::parallel::optimize_chunk_size_and_thread_limit(50, None, thread_limit, None);
185185
let progress = progress::ThroughputOnDrop::new(progress);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use gix::{
1010
hash::ObjectId,
1111
object, objs, odb,
1212
odb::{loose, pack, Write},
13-
Progress,
13+
NestedProgress,
1414
};
1515

1616
#[derive(Default, Clone, Eq, PartialEq, Debug)]
@@ -137,7 +137,7 @@ pub fn pack_or_pack_index(
137137
pack_path: impl AsRef<Path>,
138138
object_path: Option<impl AsRef<Path>>,
139139
check: SafetyCheck,
140-
progress: impl Progress,
140+
progress: impl NestedProgress,
141141
Context {
142142
thread_limit,
143143
delete_pack,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fs, io, path::PathBuf, str::FromStr, sync::atomic::AtomicBool};
22

3-
use gix::{odb::pack, Progress};
3+
use gix::{odb::pack, NestedProgress};
44

55
use crate::OutputFormat;
66

@@ -77,7 +77,7 @@ pub fn from_pack<P>(
7777
ctx: Context<'static, impl io::Write>,
7878
) -> anyhow::Result<()>
7979
where
80-
P: Progress,
80+
P: NestedProgress,
8181
P::SubProgress: 'static,
8282
{
8383
use anyhow::Context;

0 commit comments

Comments
 (0)