Skip to content

Commit

Permalink
chore!: update to the latest prodash
Browse files Browse the repository at this point in the history
It makes proper usage of `Progress` types easier and allows them to be used
as `dyn` traits as well.
  • Loading branch information
Byron committed Sep 4, 2023
1 parent 04494c6 commit 70e8e77
Show file tree
Hide file tree
Showing 56 changed files with 213 additions and 275 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ gix = { version = "^0.53.0", path = "gix", default-features = false }
time = "0.3.23"

clap = { version = "4.1.1", features = ["derive", "cargo"] }
prodash = { version = "25.0.0", optional = true, default-features = false }
prodash = { version = "26.0.0", optional = true, default-features = false }
is-terminal = { version = "0.4.0", optional = true }
env_logger = { version = "0.10.0", default-features = false }
crosstermion = { version = "0.11.0", optional = true, default-features = false }
Expand Down
18 changes: 8 additions & 10 deletions gitoxide-core/src/corpus/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use anyhow::{bail, Context};
use bytesize::ByteSize;
use gix::Progress;
use gix::{Count, NestedProgress, Progress};
use rusqlite::params;

use super::db;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl Engine {
pub fn refresh(&mut self, corpus_path: PathBuf) -> anyhow::Result<()> {
let (corpus_path, corpus_id) = self.prepare_corpus_path(corpus_path)?;
let repos = self.refresh_repos(&corpus_path, corpus_id)?;
self.state.progress.set_name("refresh repos");
self.state.progress.set_name("refresh repos".into());
self.state.progress.info(format!(
"Added or updated {} repositories under {corpus_path:?}",
repos.len()
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Engine {
repo_progress.init(Some(repos.len()), gix::progress::count("repos"));
if task.execute_exclusive || threads == 1 || dry_run {
if dry_run {
repo_progress.set_name("WOULD run");
repo_progress.set_name("WOULD run".into());
for repo in &repos {
repo_progress.info(format!(
"{}",
Expand Down Expand Up @@ -202,13 +202,11 @@ impl Engine {
task.perform(&mut run, &repo.path, progress, Some(1), should_interrupt);
});
if let Some(err) = run.error.as_deref() {
num_errors.fetch_add(1, Ordering::SeqCst);
num_errors.fetch_add(1, Ordering::Relaxed);
progress.fail(err.to_owned());
}
Self::update_run(con, run)?;
if let Some(counter) = counter.as_ref() {
counter.fetch_add(1, Ordering::SeqCst);
}
counter.fetch_add(1, Ordering::Relaxed);
Ok(())
},
|| (!gix::interrupt::is_triggered()).then(|| Duration::from_millis(100)),
Expand Down Expand Up @@ -243,7 +241,7 @@ impl Engine {
corpus_id: db::Id,
sql_suffix: Option<&str>,
) -> anyhow::Result<Vec<db::Repo>> {
self.state.progress.set_name("query db-repos");
self.state.progress.set_name("query db-repos".into());
self.state.progress.init(None, gix::progress::count("repos"));

Ok(self
Expand All @@ -267,7 +265,7 @@ impl Engine {

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

let repos = std::thread::scope({
Expand Down Expand Up @@ -302,7 +300,7 @@ impl Engine {

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

let mut out = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/corpus/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ impl tracing_forest::printer::Formatter for StoreTreeToDb {
use gix::Progress;
if self.reverse_lines {
for line in tree.lines().rev() {
progress.info(line);
progress.info(line.into());
}
} else {
for line in tree.lines() {
progress.info(line);
progress.info(line.into());
}
}
}
Expand Down
33 changes: 9 additions & 24 deletions gitoxide-core/src/hours/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ pub fn estimate_hours(
}
}

type CommitChangeLineCounters = (
Option<Arc<AtomicUsize>>,
Option<Arc<AtomicUsize>>,
Option<Arc<AtomicUsize>>,
);
type CommitChangeLineCounters = (Arc<AtomicUsize>, Arc<AtomicUsize>, Arc<AtomicUsize>);

type SpawnResultWithReturnChannelAndWorkers<'scope> = (
crossbeam_channel::Sender<Vec<(CommitIdx, Option<gix::hash::ObjectId>, gix::hash::ObjectId)>>,
Expand All @@ -95,7 +91,7 @@ pub fn spawn_tree_delta_threads<'scope>(
let rx = rx.clone();
move || -> Result<_, anyhow::Error> {
let mut out = Vec::new();
let (commit_counter, change_counter, lines_counter) = stats_counters;
let (commits, changes, lines_count) = stats_counters;
let mut attributes = line_stats
.then(|| -> anyhow::Result<_> {
repo.index_or_load_from_head().map_err(Into::into).and_then(|index| {
Expand All @@ -115,9 +111,7 @@ pub fn spawn_tree_delta_threads<'scope>(
.transpose()?;
for chunk in rx {
for (commit_idx, parent_commit, commit) in chunk {
if let Some(c) = commit_counter.as_ref() {
c.fetch_add(1, Ordering::SeqCst);
}
commits.fetch_add(1, Ordering::Relaxed);
if gix::interrupt::is_triggered() {
return Ok(out);
}
Expand All @@ -139,23 +133,21 @@ pub fn spawn_tree_delta_threads<'scope>(
.track_rewrites(None)
.for_each_to_obtain_tree(&to, |change| {
use gix::object::tree::diff::change::Event::*;
if let Some(c) = change_counter.as_ref() {
c.fetch_add(1, Ordering::SeqCst);
}
changes.fetch_add(1, Ordering::Relaxed);
match change.event {
Rewrite { .. } => {
unreachable!("we turned that off")
}
Addition { entry_mode, id } => {
if entry_mode.is_no_tree() {
files.added += 1;
add_lines(line_stats, lines_counter.as_deref(), &mut lines, id);
add_lines(line_stats, &lines_count, &mut lines, id);
}
}
Deletion { entry_mode, id } => {
if entry_mode.is_no_tree() {
files.removed += 1;
remove_lines(line_stats, lines_counter.as_deref(), &mut lines, id);
remove_lines(line_stats, &lines_count, &mut lines, id);
}
}
Modification {
Expand All @@ -168,16 +160,11 @@ pub fn spawn_tree_delta_threads<'scope>(
(false, false) => {}
(false, true) => {
files.added += 1;
add_lines(line_stats, lines_counter.as_deref(), &mut lines, id);
add_lines(line_stats, &lines_count, &mut lines, id);
}
(true, false) => {
files.removed += 1;
remove_lines(
line_stats,
lines_counter.as_deref(),
&mut lines,
previous_id,
);
remove_lines(line_stats, &lines_count, &mut lines, previous_id);
}
(true, true) => {
files.modified += 1;
Expand All @@ -203,9 +190,7 @@ pub fn spawn_tree_delta_threads<'scope>(
nl += counts.insertions as usize + counts.removals as usize;
lines.added += counts.insertions as usize;
lines.removed += counts.removals as usize;
if let Some(c) = lines_counter.as_ref() {
c.fetch_add(nl, Ordering::SeqCst);
}
lines_count.fetch_add(nl, Ordering::Relaxed);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/hours/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gix::{
actor,
bstr::{BStr, ByteSlice},
prelude::*,
progress, Progress,
progress, Count, NestedProgress, Progress,
};

/// Additional configuration for the hours estimation functionality.
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn estimate<W, P>(
) -> anyhow::Result<()>
where
W: io::Write,
P: Progress,
P: NestedProgress,
{
let repo = gix::discover(working_dir)?;
let commit_id = repo.rev_parse_single(rev_spec)?.detach();
Expand Down
12 changes: 4 additions & 8 deletions gitoxide-core/src/hours/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,18 @@ impl LineStats {
/// An index able to address any commit
pub type CommitIdx = u32;

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

pub fn remove_lines(line_stats: bool, lines_counter: Option<&AtomicUsize>, lines: &mut LineStats, id: gix::Id<'_>) {
pub fn remove_lines(line_stats: bool, lines_counter: &AtomicUsize, lines: &mut LineStats, id: gix::Id<'_>) {
if let Some(Ok(blob)) = line_stats.then(|| id.object()) {
let nl = blob.data.lines_with_terminator().count();
lines.removed += nl;
if let Some(c) = lines_counter {
c.fetch_add(nl, Ordering::SeqCst);
}
lines_counter.fetch_add(nl, Ordering::Relaxed);
}
}
4 changes: 2 additions & 2 deletions gitoxide-core/src/index/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use anyhow::bail;
use gix::{odb::FindExt, worktree::state::checkout, Progress};
use gix::{odb::FindExt, worktree::state::checkout, NestedProgress, Progress};

use crate::{
index,
Expand All @@ -16,7 +16,7 @@ pub fn checkout_exclusive(
dest_directory: impl AsRef<Path>,
repo: Option<PathBuf>,
mut err: impl std::io::Write,
mut progress: impl Progress,
mut progress: impl NestedProgress,
should_interrupt: &AtomicBool,
index::checkout_exclusive::Options {
index: Options { object_hash, .. },
Expand Down
6 changes: 3 additions & 3 deletions gitoxide-core/src/organize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use gix::{objs::bstr::ByteSlice, progress, Progress};
use gix::{objs::bstr::ByteSlice, progress, NestedProgress, Progress};

#[derive(Default, Copy, Clone, Eq, PartialEq)]
pub enum Mode {
Expand Down Expand Up @@ -207,7 +207,7 @@ fn handle(
}

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

pub fn run<P: Progress>(
pub fn run<P: NestedProgress>(
mode: Mode,
source_dir: impl AsRef<Path>,
destination: impl AsRef<Path>,
Expand Down
6 changes: 3 additions & 3 deletions gitoxide-core/src/pack/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use gix::{
odb::{pack, pack::FindExt},
parallel::InOrderIter,
prelude::Finalize,
progress, traverse, Progress,
progress, traverse, Count, NestedProgress, Progress,
};

use crate::OutputFormat;
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn create<W, P>(
) -> anyhow::Result<()>
where
W: std::io::Write,
P: Progress,
P: NestedProgress,
P::SubProgress: 'static,
{
let repo = gix::discover(repository_path)?.into_sync();
Expand Down Expand Up @@ -179,7 +179,7 @@ where
Some(1)
};
if nondeterministic_thread_count.is_some() && !may_use_multiple_threads {
progress.fail("Cannot use multi-threaded counting in tree-diff object expansion mode as it may yield way too many objects.");
progress.fail("Cannot use multi-threaded counting in tree-diff object expansion mode as it may yield way too many objects.".into());
}
let (_, _, thread_count) = gix::parallel::optimize_chunk_size_and_thread_limit(50, None, thread_limit, None);
let progress = progress::ThroughputOnDrop::new(progress);
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/pack/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use gix::{
hash::ObjectId,
object, objs, odb,
odb::{loose, pack, Write},
Progress,
NestedProgress,
};

#[derive(Default, Clone, Eq, PartialEq, Debug)]
Expand Down Expand Up @@ -137,7 +137,7 @@ pub fn pack_or_pack_index(
pack_path: impl AsRef<Path>,
object_path: Option<impl AsRef<Path>>,
check: SafetyCheck,
progress: impl Progress,
progress: impl NestedProgress,
Context {
thread_limit,
delete_pack,
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/pack/index.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fs, io, path::PathBuf, str::FromStr, sync::atomic::AtomicBool};

use gix::{odb::pack, Progress};
use gix::{odb::pack, NestedProgress};

use crate::OutputFormat;

Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn from_pack<P>(
ctx: Context<'static, impl io::Write>,
) -> anyhow::Result<()>
where
P: Progress,
P: NestedProgress,
P::SubProgress: 'static,
{
use anyhow::Context;
Expand Down
Loading

0 comments on commit 70e8e77

Please sign in to comment.