diff --git a/Cargo.toml b/Cargo.toml index 21857e9d8e2..32518b75620 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,9 +76,7 @@ lto = "fat" panic = 'abort' codegen-units = 1 incremental = false - -[profile.release.build-override] -opt-level = 0 +build-override = { opt-level = 0 } [workspace] members = [ diff --git a/gitoxide-core/src/lib.rs b/gitoxide-core/src/lib.rs index 4f024436854..a273693d106 100644 --- a/gitoxide-core/src/lib.rs +++ b/gitoxide-core/src/lib.rs @@ -1,6 +1,6 @@ #![forbid(unsafe_code)] -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, Context as AnyhowContext, Result}; use bytesize::ByteSize; use git_features::progress::Progress; use git_object::Kind; @@ -39,20 +39,33 @@ impl FromStr for OutputFormat { } } +pub struct Context { + /// If set, provide statistics to `out` in the given format + pub output_statistics: Option, + /// A stream to which to output operation results + pub out: W1, + /// A stream to which to errors + pub err: W2, +} + pub fn init() -> Result<()> { git_repository::init::repository().with_context(|| "Repository initialization failed") } -pub fn verify_pack_or_pack_index

( +pub fn verify_pack_or_pack_index( path: impl AsRef, progress: Option

, - output_statistics: Option, - mut out: impl io::Write, - mut err: impl io::Write, + Context { + mut out, + mut err, + output_statistics, + }: Context, ) -> Result<(git_object::Id, Option)> where P: Progress,

::SubProgress: Send, + W1: io::Write, + W2: io::Write, { let path = path.as_ref(); let ext = path.extension().and_then(|ext| ext.to_str()).ok_or_else(|| { diff --git a/src/plumbing/lean.rs b/src/plumbing/lean.rs index 749b9a2ac36..965f25db834 100644 --- a/src/plumbing/lean.rs +++ b/src/plumbing/lean.rs @@ -79,13 +79,15 @@ pub fn main() -> Result<()> { core::verify_pack_or_pack_index( path, progress, - if statistics { - Some(core::OutputFormat::Human) - } else { - None + core::Context { + output_statistics: if statistics { + Some(core::OutputFormat::Human) + } else { + None + }, + out: stdout(), + err: stderr(), }, - stdout(), - stderr(), ) .map(|_| ()) } diff --git a/src/plumbing/pretty.rs b/src/plumbing/pretty.rs index 4ad090be317..fa34284b87d 100644 --- a/src/plumbing/pretty.rs +++ b/src/plumbing/pretty.rs @@ -161,7 +161,15 @@ pub fn main() -> Result<()> { progress, progress_keep_open, move |progress, out, err| { - core::verify_pack_or_pack_index(path, progress, if statistics { Some(format) } else { None }, out, err) + core::verify_pack_or_pack_index( + path, + progress, + core::Context { + output_statistics: if statistics { Some(format) } else { None }, + out, + err, + }, + ) }, ) .map(|_| ()), diff --git a/tests/stateless-journey.sh b/tests/stateless-journey.sh index 623ff82bb5e..5bca00f890d 100755 --- a/tests/stateless-journey.sh +++ b/tests/stateless-journey.sh @@ -65,7 +65,7 @@ title "CLI ${kind}" (with "statistics (JSON)" it "verifies the pack index successfully and with desired output" && { WITH_SNAPSHOT="$snapshot/plumbing-verify-pack-index-with-statistics-json-success" \ - expect_run $SUCCESSFULLY "$exe_plumbing" verify-pack --statistics --format json "$PACK_INDEX_FILE" + expect_run $SUCCESSFULLY "$exe_plumbing" --threads 1 verify-pack --statistics --format json "$PACK_INDEX_FILE" } ) fi