Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 1, 2020
1 parent 3b927e5 commit 7add82c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 37 deletions.
2 changes: 1 addition & 1 deletion git-features/src/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub trait Reducer {
type Output;
type Error;
fn feed(&mut self, input: Self::Input) -> Result<(), Self::Error>;
fn finalize(&mut self) -> Result<Self::Output, Self::Error>;
fn finalize(self) -> Result<Self::Output, Self::Error>;
}

mod serial {
Expand Down
4 changes: 2 additions & 2 deletions git-odb/src/pack/file/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ struct Delta {
data_offset: u64,
}

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
pub enum ResolvedBase {
InPack(Entry),
OutOfPack { kind: object::Kind, end: usize },
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
pub struct DecodeEntryResult {
pub kind: object::Kind,
pub num_deltas: u32,
Expand Down
70 changes: 37 additions & 33 deletions git-odb/src/pack/index/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{pack, pack::index};
use git_features::progress::{self, Progress};
use git_object::SHA1_SIZE;
use quick_error::quick_error;
use smallvec::alloc::collections::BTreeMap;
use std::time::Instant;

quick_error! {
Expand Down Expand Up @@ -59,6 +60,14 @@ impl Into<String> for TimeThroughput {
}
}

#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
pub struct FileChecksumResult {
/// The sha1 over the whole index file
id: git_object::Id,
average: DecodeEntryResult,
objects_per_chain_length: BTreeMap<u32, u32>,
}

/// Methods to verify and validate the content of the index file
impl index::File {
pub fn checksum_of_index(&self) -> git_object::Id {
Expand Down Expand Up @@ -133,40 +142,34 @@ impl index::File {

fn add_decode_result(
DecodeEntryResult {
kind,
num_deltas,
decompressed_size,
compressed_size,
object_size,
}: DecodeEntryResult,
kind: _,
mut num_deltas,
mut decompressed_size,
mut compressed_size,
mut object_size,
}: &mut DecodeEntryResult,
rhs: DecodeEntryResult,
) -> DecodeEntryResult {
DecodeEntryResult {
kind,
num_deltas: num_deltas + rhs.num_deltas,
decompressed_size: decompressed_size + rhs.decompressed_size,
compressed_size: compressed_size + rhs.compressed_size,
object_size: object_size + rhs.object_size,
}
) {
num_deltas += rhs.num_deltas;
decompressed_size += rhs.decompressed_size;
compressed_size += rhs.compressed_size;
object_size += rhs.object_size;
}

fn div_decode_result(
DecodeEntryResult {
kind,
num_deltas,
decompressed_size,
compressed_size,
object_size,
}: DecodeEntryResult,
kind: _,
mut num_deltas,
mut decompressed_size,
mut compressed_size,
mut object_size,
}: &mut DecodeEntryResult,
div: usize,
) -> DecodeEntryResult {
DecodeEntryResult {
kind,
num_deltas: num_deltas / div as u32,
decompressed_size: decompressed_size / div as u64,
compressed_size: compressed_size / div,
object_size: object_size / div as u64,
}
) {
num_deltas /= div as u32;
decompressed_size /= div as u64;
compressed_size /= div;
object_size /= div as u64;
}

struct Reducer<'a, P> {
Expand All @@ -189,14 +192,15 @@ impl index::File {
self.entries_seen += num_entries as u32;
self.chunks_seen += 1;

self.stats = add_decode_result(self.stats, chunk_stats);
add_decode_result(&mut self.stats, chunk_stats);
self.progress.lock().unwrap().set(self.entries_seen);
Ok(())
}

fn finalize(&mut self) -> Result<Self::Output, Self::Error> {
fn finalize(mut self) -> Result<Self::Output, Self::Error> {
self.progress.lock().unwrap().done("finished");
Ok(div_decode_result(self.stats, self.chunks_seen))
div_decode_result(&mut self.stats, self.chunks_seen);
Ok(self.stats)
}
}

Expand Down Expand Up @@ -256,7 +260,7 @@ impl index::File {
})?;
let object_kind = entry_stats.kind;
let consumed_input = entry_stats.compressed_size;
stats = add_decode_result(stats, entry_stats);
add_decode_result(&mut stats, entry_stats);

let mut header_buf = [0u8; 64];
let header_size = crate::loose::db::serde::write_header(
Expand Down Expand Up @@ -294,7 +298,7 @@ impl index::File {
}
progress.set(idx as u32);
}
stats = div_decode_result(stats, entries.len());
div_decode_result(&mut stats, entries.len());
Ok((entries.len(), stats))
},
Reducer {
Expand Down
9 changes: 8 additions & 1 deletion src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ mod options {
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "verify-pack")]
pub struct VerifyPack {
/// if set, output statistical information about the pack
#[argh(switch, short = 's')]
pub statistics: bool,
/// if set, verbose progress messages are printed line by line
#[argh(switch, short = 'v')]
pub verbose: bool,
Expand All @@ -37,7 +40,11 @@ pub fn main() -> Result<()> {
pub use options::*;
let cli: Args = argh::from_env();
match cli.subcommand {
SubCommands::VerifyPack(VerifyPack { path, verbose }) => {
SubCommands::VerifyPack(VerifyPack {
path,
verbose,
statistics,
}) => {
super::init_env_logger(verbose);
core::verify_pack_or_pack_index(
path,
Expand Down

0 comments on commit 7add82c

Please sign in to comment.