Skip to content

Commit

Permalink
add new Context argument to support more configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 13, 2020
1 parent f9cd65c commit 7c5d8b8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
23 changes: 18 additions & 5 deletions gitoxide-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,20 +39,33 @@ impl FromStr for OutputFormat {
}
}

pub struct Context<W1: io::Write, W2: io::Write> {
/// If set, provide statistics to `out` in the given format
pub output_statistics: Option<OutputFormat>,
/// 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<P>(
pub fn verify_pack_or_pack_index<P, W1, W2>(
path: impl AsRef<Path>,
progress: Option<P>,
output_statistics: Option<OutputFormat>,
mut out: impl io::Write,
mut err: impl io::Write,
Context {
mut out,
mut err,
output_statistics,
}: Context<W1, W2>,
) -> Result<(git_object::Id, Option<index::PackFileChecksumResult>)>
where
P: Progress,
<P as 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(|| {
Expand Down
14 changes: 8 additions & 6 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| ())
}
Expand Down
10 changes: 9 additions & 1 deletion src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| ()),
Expand Down
2 changes: 1 addition & 1 deletion tests/stateless-journey.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c5d8b8

Please sign in to comment.