Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29b9c23

Browse files
committed
Allow sink-compress configuration; choose best algorithm
1 parent 70562fa commit 29b9c23

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

gitoxide-core/src/pack/explode.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ impl git_odb::Write for OutputWriter {
116116
}
117117

118118
impl OutputWriter {
119-
fn new(path: Option<impl AsRef<Path>>) -> Self {
119+
fn new(path: Option<impl AsRef<Path>>, compress: bool) -> Self {
120120
match path {
121121
Some(path) => OutputWriter::Loose(loose::Db::at(path.as_ref())),
122-
None => OutputWriter::Sink(git_odb::sink().compress(true)),
122+
None => OutputWriter::Sink(git_odb::sink().compress(compress)),
123123
}
124124
}
125125
}
@@ -131,6 +131,7 @@ pub fn pack_or_pack_index<P>(
131131
thread_limit: Option<usize>,
132132
progress: Option<P>,
133133
delete_pack: bool,
134+
sink_compress: bool,
134135
) -> Result<()>
135136
where
136137
P: Progress,
@@ -151,18 +152,28 @@ where
151152
));
152153
}
153154

155+
let algorithm = object_path
156+
.as_ref()
157+
.map(|_| {
158+
if sink_compress {
159+
pack::index::traverse::Algorithm::Lookup
160+
} else {
161+
pack::index::traverse::Algorithm::DeltaTreeLookup
162+
}
163+
})
164+
.unwrap_or(pack::index::traverse::Algorithm::Lookup);
154165
let mut progress = bundle.index.traverse(
155166
&bundle.pack,
156167
pack::index::traverse::Context {
157-
algorithm: pack::index::traverse::Algorithm::Lookup,
168+
algorithm,
158169
thread_limit,
159170
check: check.into(),
160171
},
161172
progress,
162173
{
163174
let object_path = object_path.map(|p| p.as_ref().to_owned());
164175
move || {
165-
let out = OutputWriter::new(object_path.clone());
176+
let out = OutputWriter::new(object_path.clone(), sink_compress);
166177
move |object_kind, buf, index_entry, _entry_stats, progress| {
167178
let written_id = out
168179
.write_buf(object_kind, buf, HashKind::Sha1)

src/plumbing/lean.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ mod options {
4242
#[argh(switch, short = 'v')]
4343
pub verbose: bool,
4444

45+
/// compress bytes even when using the sink, i.e. no object directory is specified
46+
///
47+
/// This helps to determine overhead related to compression. If unset, the sink will
48+
/// only create hashes from bytes, which is usually limited by the speed at which input
49+
/// can be obtained.
50+
#[argh(switch)]
51+
pub sink_compress: bool,
52+
4553
/// the amount of checks to run. Defaults to 'all'.
4654
///
4755
/// Allowed values:
@@ -136,6 +144,7 @@ pub fn main() -> Result<()> {
136144
match cli.subcommand {
137145
SubCommands::PackExplode(PackExplode {
138146
pack_path,
147+
sink_compress,
139148
object_path,
140149
verbose,
141150
check,
@@ -149,6 +158,7 @@ pub fn main() -> Result<()> {
149158
thread_limit,
150159
progress,
151160
delete_pack,
161+
sink_compress,
152162
)
153163
}
154164
SubCommands::PackVerify(PackVerify {

src/plumbing/pretty.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ mod options {
4343
)]
4444
check: core::pack::explode::SafetyCheck,
4545

46+
/// Compress bytes even when using the sink, i.e. no object directory is specified
47+
///
48+
/// This helps to determine overhead related to compression. If unset, the sink will
49+
/// only create hashes from bytes, which is usually limited by the speed at which input
50+
/// can be obtained.
51+
#[structopt(long)]
52+
sink_compress: bool,
53+
4654
/// Display verbose messages and progress information
4755
#[structopt(long, short = "v")]
4856
verbose: bool,
@@ -224,6 +232,7 @@ pub fn main() -> Result<()> {
224232
check,
225233
progress,
226234
progress_keep_open,
235+
sink_compress,
227236
delete_pack,
228237
pack_path,
229238
object_path,
@@ -240,6 +249,7 @@ pub fn main() -> Result<()> {
240249
thread_limit,
241250
progress,
242251
delete_pack,
252+
sink_compress,
243253
)
244254
},
245255
),

tests/stateless-journey.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ title "CLI ${kind}"
8585
it "does explode the file" && {
8686
WITH_SNAPSHOT="$snapshot/plumbing-broken-pack-explode-delete-pack-to-sink-skip-checks-success" \
8787
expect_run $SUCCESSFULLY "$exe_plumbing" pack-explode --check skip-file-and-object-checksum-and-no-abort-on-decode \
88-
--delete-pack "${PACK_FILE}.pack" .
88+
--delete-pack --sink-compress "${PACK_FILE}.pack" .
8989
}
9090

9191
it "removes the original files" && {

0 commit comments

Comments
 (0)