Skip to content

Commit 7c5d8b8

Browse files
committed
add new Context argument to support more configuration options
1 parent f9cd65c commit 7c5d8b8

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

Diff for: Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ lto = "fat"
7676
panic = 'abort'
7777
codegen-units = 1
7878
incremental = false
79-
80-
[profile.release.build-override]
81-
opt-level = 0
79+
build-override = { opt-level = 0 }
8280

8381
[workspace]
8482
members = [

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![forbid(unsafe_code)]
22

3-
use anyhow::{anyhow, Context, Result};
3+
use anyhow::{anyhow, Context as AnyhowContext, Result};
44
use bytesize::ByteSize;
55
use git_features::progress::Progress;
66
use git_object::Kind;
@@ -39,20 +39,33 @@ impl FromStr for OutputFormat {
3939
}
4040
}
4141

42+
pub struct Context<W1: io::Write, W2: io::Write> {
43+
/// If set, provide statistics to `out` in the given format
44+
pub output_statistics: Option<OutputFormat>,
45+
/// A stream to which to output operation results
46+
pub out: W1,
47+
/// A stream to which to errors
48+
pub err: W2,
49+
}
50+
4251
pub fn init() -> Result<()> {
4352
git_repository::init::repository().with_context(|| "Repository initialization failed")
4453
}
4554

46-
pub fn verify_pack_or_pack_index<P>(
55+
pub fn verify_pack_or_pack_index<P, W1, W2>(
4756
path: impl AsRef<Path>,
4857
progress: Option<P>,
49-
output_statistics: Option<OutputFormat>,
50-
mut out: impl io::Write,
51-
mut err: impl io::Write,
58+
Context {
59+
mut out,
60+
mut err,
61+
output_statistics,
62+
}: Context<W1, W2>,
5263
) -> Result<(git_object::Id, Option<index::PackFileChecksumResult>)>
5364
where
5465
P: Progress,
5566
<P as Progress>::SubProgress: Send,
67+
W1: io::Write,
68+
W2: io::Write,
5669
{
5770
let path = path.as_ref();
5871
let ext = path.extension().and_then(|ext| ext.to_str()).ok_or_else(|| {

Diff for: src/plumbing/lean.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ pub fn main() -> Result<()> {
7979
core::verify_pack_or_pack_index(
8080
path,
8181
progress,
82-
if statistics {
83-
Some(core::OutputFormat::Human)
84-
} else {
85-
None
82+
core::Context {
83+
output_statistics: if statistics {
84+
Some(core::OutputFormat::Human)
85+
} else {
86+
None
87+
},
88+
out: stdout(),
89+
err: stderr(),
8690
},
87-
stdout(),
88-
stderr(),
8991
)
9092
.map(|_| ())
9193
}

Diff for: src/plumbing/pretty.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,15 @@ pub fn main() -> Result<()> {
161161
progress,
162162
progress_keep_open,
163163
move |progress, out, err| {
164-
core::verify_pack_or_pack_index(path, progress, if statistics { Some(format) } else { None }, out, err)
164+
core::verify_pack_or_pack_index(
165+
path,
166+
progress,
167+
core::Context {
168+
output_statistics: if statistics { Some(format) } else { None },
169+
out,
170+
err,
171+
},
172+
)
165173
},
166174
)
167175
.map(|_| ()),

Diff for: tests/stateless-journey.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ title "CLI ${kind}"
6565
(with "statistics (JSON)"
6666
it "verifies the pack index successfully and with desired output" && {
6767
WITH_SNAPSHOT="$snapshot/plumbing-verify-pack-index-with-statistics-json-success" \
68-
expect_run $SUCCESSFULLY "$exe_plumbing" verify-pack --statistics --format json "$PACK_INDEX_FILE"
68+
expect_run $SUCCESSFULLY "$exe_plumbing" --threads 1 verify-pack --statistics --format json "$PACK_INDEX_FILE"
6969
}
7070
)
7171
fi

0 commit comments

Comments
 (0)