Skip to content

Commit

Permalink
Allow sink-compress configuration; choose best algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 28, 2020
1 parent 70562fa commit 29b9c23
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
19 changes: 15 additions & 4 deletions gitoxide-core/src/pack/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ impl git_odb::Write for OutputWriter {
}

impl OutputWriter {
fn new(path: Option<impl AsRef<Path>>) -> Self {
fn new(path: Option<impl AsRef<Path>>, compress: bool) -> Self {
match path {
Some(path) => OutputWriter::Loose(loose::Db::at(path.as_ref())),
None => OutputWriter::Sink(git_odb::sink().compress(true)),
None => OutputWriter::Sink(git_odb::sink().compress(compress)),
}
}
}
Expand All @@ -131,6 +131,7 @@ pub fn pack_or_pack_index<P>(
thread_limit: Option<usize>,
progress: Option<P>,
delete_pack: bool,
sink_compress: bool,
) -> Result<()>
where
P: Progress,
Expand All @@ -151,18 +152,28 @@ where
));
}

let algorithm = object_path
.as_ref()
.map(|_| {
if sink_compress {
pack::index::traverse::Algorithm::Lookup
} else {
pack::index::traverse::Algorithm::DeltaTreeLookup
}
})
.unwrap_or(pack::index::traverse::Algorithm::Lookup);
let mut progress = bundle.index.traverse(
&bundle.pack,
pack::index::traverse::Context {
algorithm: pack::index::traverse::Algorithm::Lookup,
algorithm,
thread_limit,
check: check.into(),
},
progress,
{
let object_path = object_path.map(|p| p.as_ref().to_owned());
move || {
let out = OutputWriter::new(object_path.clone());
let out = OutputWriter::new(object_path.clone(), sink_compress);
move |object_kind, buf, index_entry, _entry_stats, progress| {
let written_id = out
.write_buf(object_kind, buf, HashKind::Sha1)
Expand Down
10 changes: 10 additions & 0 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ mod options {
#[argh(switch, short = 'v')]
pub verbose: bool,

/// compress bytes even when using the sink, i.e. no object directory is specified
///
/// This helps to determine overhead related to compression. If unset, the sink will
/// only create hashes from bytes, which is usually limited by the speed at which input
/// can be obtained.
#[argh(switch)]
pub sink_compress: bool,

/// the amount of checks to run. Defaults to 'all'.
///
/// Allowed values:
Expand Down Expand Up @@ -136,6 +144,7 @@ pub fn main() -> Result<()> {
match cli.subcommand {
SubCommands::PackExplode(PackExplode {
pack_path,
sink_compress,
object_path,
verbose,
check,
Expand All @@ -149,6 +158,7 @@ pub fn main() -> Result<()> {
thread_limit,
progress,
delete_pack,
sink_compress,
)
}
SubCommands::PackVerify(PackVerify {
Expand Down
10 changes: 10 additions & 0 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ mod options {
)]
check: core::pack::explode::SafetyCheck,

/// Compress bytes even when using the sink, i.e. no object directory is specified
///
/// This helps to determine overhead related to compression. If unset, the sink will
/// only create hashes from bytes, which is usually limited by the speed at which input
/// can be obtained.
#[structopt(long)]
sink_compress: bool,

/// Display verbose messages and progress information
#[structopt(long, short = "v")]
verbose: bool,
Expand Down Expand Up @@ -224,6 +232,7 @@ pub fn main() -> Result<()> {
check,
progress,
progress_keep_open,
sink_compress,
delete_pack,
pack_path,
object_path,
Expand All @@ -240,6 +249,7 @@ pub fn main() -> Result<()> {
thread_limit,
progress,
delete_pack,
sink_compress,
)
},
),
Expand Down
2 changes: 1 addition & 1 deletion tests/stateless-journey.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ title "CLI ${kind}"
it "does explode the file" && {
WITH_SNAPSHOT="$snapshot/plumbing-broken-pack-explode-delete-pack-to-sink-skip-checks-success" \
expect_run $SUCCESSFULLY "$exe_plumbing" pack-explode --check skip-file-and-object-checksum-and-no-abort-on-decode \
--delete-pack "${PACK_FILE}.pack" .
--delete-pack --sink-compress "${PACK_FILE}.pack" .
}

it "removes the original files" && {
Expand Down

0 comments on commit 29b9c23

Please sign in to comment.