Skip to content

Commit

Permalink
Upgrade to prodash 19
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 20, 2022
1 parent 8ab19a6 commit 90c6c5a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ lean-async = ["fast", "pretty-cli", "gitoxide-core-tools", "gitoxide-core-async-

## As small as it can possibly be, no threading, no fast sha1, log based progress only, rust based zlib implementation.
## no networking, local operations only.
small = ["pretty-cli", "git-features/rustsha1", "git-features/zlib-rust-backend", "prodash/progress-log", "atty"]
small = ["pretty-cli", "git-features/rustsha1", "git-features/zlib-rust-backend", "prodash/progress-log", "atty", "env_logger"]

#! ### `gitoxide-core` Configuration

Expand Down Expand Up @@ -89,7 +89,7 @@ git-repository = { version = "^0.15.0", path = "git-repository", default-feature
git-transport-for-configuration-only = { package = "git-transport", optional = true, version = "^0.15.0", path = "git-transport" }

clap = { version = "3.0.0", features = ["derive", "cargo"] }
prodash = { version = "18.0.0", optional = true, default-features = false }
prodash = { version = "19.0.0", optional = true, default-features = false }
atty = { version = "0.2.14", optional = true, default-features = false }
env_logger = { version = "0.9.0", optional = true, default-features = false, features = ["humantime", "termcolor", "atty"] }
crosstermion = { version = "0.9.0", optional = true, default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion git-features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ crc32fast = { version = "1.2.1", optional = true }
sha-1 = { version = "0.10.0", optional = true }

# progress
prodash = { version = "18.0.0", optional = true, default-features = false, features = ["unit-bytes", "unit-human"] }
prodash = { version = "19.0.0", optional = true, default-features = false, features = ["unit-bytes", "unit-human"] }

# pipe
bytes = { version = "1.0.0", optional = true }
Expand Down
12 changes: 4 additions & 8 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ pub mod async_util {
range: impl Into<Option<ProgressRange>>,
) -> (Option<prodash::render::line::JoinHandle>, Option<prodash::tree::Item>) {
use crate::shared::{self, STANDARD_RANGE};
crate::shared::init_env_logger(false);
crate::shared::init_env_logger();

if verbose {
let progress = crate::shared::progress_tree();
let sub_progress = progress.add_child(name);
let ui_handle = shared::setup_line_renderer_range(progress, range.into().unwrap_or(STANDARD_RANGE));
let ui_handle = shared::setup_line_renderer_range(&progress, range.into().unwrap_or(STANDARD_RANGE));
(Some(ui_handle), Some(sub_progress))
} else {
(None, None)
Expand Down Expand Up @@ -425,11 +425,7 @@ pub fn main() -> Result<()> {
progress_keep_open,
core::pack::multi_index::PROGRESS_RANGE,
move |progress, _out, _err| {
core::pack::multi_index::verify(
multi_index_path,
progress,
&git_repository::interrupt::IS_INTERRUPTED,
)
core::pack::multi_index::verify(multi_index_path, progress, &should_interrupt)
},
),
pack::multi_index::Subcommands::Create { index_paths } => prepare_and_run(
Expand All @@ -443,7 +439,7 @@ pub fn main() -> Result<()> {
index_paths,
multi_index_path,
progress,
&git_repository::interrupt::IS_INTERRUPTED,
&should_interrupt,
object_hash,
)
},
Expand Down
25 changes: 11 additions & 14 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub const STANDARD_RANGE: ProgressRange = 2..=2;
/// will just be initialized.
#[cfg(feature = "env_logger")]
#[allow(unused)] // Squelch warning because it's used in porcelain as well and we can't know that at compile time
pub fn init_env_logger(verbose: bool) {
if verbose {
pub fn init_env_logger() {
if cfg!(feature = "small") {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.format_module_path(false)
.init();
Expand All @@ -21,7 +21,7 @@ pub fn init_env_logger(verbose: bool) {
}

#[cfg(feature = "prodash-render-line")]
pub fn progress_tree() -> prodash::Tree {
pub fn progress_tree() -> std::sync::Arc<prodash::Tree> {
prodash::TreeOptions {
message_buffer_capacity: 200,
..Default::default()
Expand Down Expand Up @@ -74,7 +74,7 @@ pub mod pretty {
+ std::panic::UnwindSafe
+ 'static,
) -> Result<T> {
crate::shared::init_env_logger(false);
crate::shared::init_env_logger();

match (verbose, progress) {
(false, false) => {
Expand All @@ -91,12 +91,10 @@ pub mod pretty {
{
let stdout = stdout();
let mut stdout_lock = stdout.lock();
let stderr = stderr();
let mut stderr_lock = stderr.lock();
run(
progress::DoOrDiscard::from(Some(sub_progress)),
&mut stdout_lock,
&mut stderr_lock,
&mut stderr(),
)
}
#[cfg(feature = "prodash-render-line")]
Expand All @@ -108,7 +106,8 @@ pub mod pretty {
}
use crate::shared::{self, STANDARD_RANGE};
let (tx, rx) = std::sync::mpsc::sync_channel::<Event<T>>(1);
let ui_handle = shared::setup_line_renderer_range(progress, range.into().unwrap_or(STANDARD_RANGE));
let ui_handle =
shared::setup_line_renderer_range(&progress, range.into().unwrap_or(STANDARD_RANGE));
std::thread::spawn({
let tx = tx.clone();
move || loop {
Expand All @@ -119,8 +118,6 @@ pub mod pretty {
}
}
});
// LIMITATION: This will hang if the thread panics as no message is send and the renderer thread will wait forever.
// `catch_unwind` can't be used as a parking lot mutex is not unwind safe, coming from prodash.
let join_handle = std::thread::spawn(move || {
let mut out = Vec::<u8>::new();
let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
Expand Down Expand Up @@ -171,11 +168,11 @@ pub mod pretty {
let sub_progress = progress.add_child(name);
let render_tui = prodash::render::tui(
stdout(),
progress,
std::sync::Arc::downgrade(&progress),
prodash::render::tui::Options {
title: "gitoxide".into(),
frames_per_second: shared::DEFAULT_FRAME_RATE,
stop_if_empty_progress: !progress_keep_open,
stop_if_progress_missing: !progress_keep_open,
throughput: true,
..Default::default()
},
Expand Down Expand Up @@ -219,12 +216,12 @@ pub mod pretty {
#[allow(unused)]
#[cfg(feature = "prodash-render-line")]
pub fn setup_line_renderer_range(
progress: prodash::Tree,
progress: &std::sync::Arc<prodash::Tree>,
levels: std::ops::RangeInclusive<prodash::progress::key::Level>,
) -> prodash::render::line::JoinHandle {
prodash::render::line(
std::io::stderr(),
progress,
std::sync::Arc::downgrade(progress),
prodash::render::line::Options {
level_filter: Some(levels),
frames_per_second: DEFAULT_FRAME_RATE,
Expand Down

0 comments on commit 90c6c5a

Please sign in to comment.