Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 28, 2020
1 parent 29b9c23 commit 0a33b24
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
3 changes: 3 additions & 0 deletions git-odb/src/pack/data/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ impl File {

let last_result_size = last_result_size.expect("at least one delta chain item");
// uneven chains leave the target buffer after the source buffer
// FIXME(Performance) If delta-chains are uneven, we know we will have to copy bytes over here
// Instead we could use a different start buffer, to naturally end up with the result in the
// right one.
if chain.len() % 2 == 1 {
// this seems inverted, but remember: we swapped the buffers on the last iteration
target_buf[..last_result_size].copy_from_slice(&source_buf[..last_result_size]);
Expand Down
8 changes: 4 additions & 4 deletions git-odb/src/pack/index/traverse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ impl Default for Algorithm {

#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Context {
pub struct Options {
pub algorithm: Algorithm,
pub thread_limit: Option<usize>,
pub check: SafetyCheck,
}

impl Default for Context {
impl Default for Options {
fn default() -> Self {
Self {
algorithm: Algorithm::Lookup,
Expand All @@ -159,11 +159,11 @@ impl index::File {
pub fn traverse<P, C, Processor>(
&self,
pack: &pack::data::File,
Context {
Options {
algorithm,
thread_limit,
check,
}: Context,
}: Options,
progress: Option<P>,
new_processor: impl Fn() -> Processor + Send + Sync,
make_cache: impl Fn() -> C + Send + Sync,
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/pack/index/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl index::File {
Some((pack, mode, algorithm)) => self
.traverse(
pack,
index::traverse::Context {
index::traverse::Options {
algorithm,
thread_limit,
check: index::traverse::SafetyCheck::All,
Expand Down
26 changes: 18 additions & 8 deletions gitoxide-core/src/pack/explode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, Result};
use git_features::progress::{self, Progress};
use git_object::{owned, HashKind};
use git_odb::{loose, pack, Write};
Expand Down Expand Up @@ -124,19 +124,29 @@ impl OutputWriter {
}
}

pub struct Context {
pub thread_limit: Option<usize>,
pub delete_pack: bool,
pub sink_compress: bool,
}

pub fn pack_or_pack_index<P>(
pack_path: impl AsRef<Path>,
object_path: Option<impl AsRef<Path>>,
check: SafetyCheck,
thread_limit: Option<usize>,
progress: Option<P>,
delete_pack: bool,
sink_compress: bool,
Context {
thread_limit,
delete_pack,
sink_compress,
}: Context,
) -> Result<()>
where
P: Progress,
<P as Progress>::SubProgress: Send,
{
use anyhow::Context;

let path = pack_path.as_ref();
let bundle = pack::Bundle::at(path).with_context(|| {
format!(
Expand All @@ -154,17 +164,17 @@ where

let algorithm = object_path
.as_ref()
.map(|_| {
.map(|_| pack::index::traverse::Algorithm::Lookup)
.unwrap_or_else(|| {
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 {
pack::index::traverse::Options {
algorithm,
thread_limit,
check: check.into(),
Expand Down
8 changes: 5 additions & 3 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ pub fn main() -> Result<()> {
pack_path,
object_path,
check.unwrap_or(core::pack::explode::SafetyCheck::All),
thread_limit,
progress,
delete_pack,
sink_compress,
core::pack::explode::Context {
thread_limit,
delete_pack,
sink_compress,
},
)
}
SubCommands::PackVerify(PackVerify {
Expand Down
8 changes: 5 additions & 3 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,12 @@ pub fn main() -> Result<()> {
pack_path,
object_path,
check,
thread_limit,
progress,
delete_pack,
sink_compress,
core::pack::explode::Context {
thread_limit,
delete_pack,
sink_compress,
},
)
},
),
Expand Down
3 changes: 2 additions & 1 deletion tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
* [x] to sink
* [x] to disk
* [x] progress
* [ ] option to compress sink input too
* [x] option to compress sink input too
* [ ] unrelated: see if delta-decode buffer optimization can work easily
* [ ] --verify
* [ ] statistics

Expand Down

0 comments on commit 0a33b24

Please sign in to comment.