Skip to content

Commit

Permalink
Change course and do pack streaming first
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 20, 2020
1 parent 7c2f60a commit bcb275e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
13 changes: 13 additions & 0 deletions git-odb/src/pack/index/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ pub enum Mode {
Sha1CRC32DecodeEncode,
}

/// The way of performing the pack verification
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
pub enum Algorithm {
/// Lookup each object similarly to what would happen during normal repository use.
///
/// Uses more compute resources as it will resolve delta chains from back to front, potentially
/// redoing a lot of work across multiple objects.
Lookup,
/// Read the pack sequentially (without the need for an index) and resolve pack objects from the base towards their deltas,
/// doing the necessary work only once.
Stream,
}

/// Verify and validate the content of the index file
impl index::File {
pub fn checksum_of_index(&self) -> owned::Id {
Expand Down
37 changes: 37 additions & 0 deletions gitoxide-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@ impl FromStr for OutputFormat {
}
}

#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
pub enum VerifyAlgorithm {
Lookup,
Stream,
}

impl VerifyAlgorithm {
pub fn variants() -> &'static [&'static str] {
&["lookup", "stream"]
}
}

impl FromStr for VerifyAlgorithm {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let s_lc = s.to_ascii_lowercase();
Ok(match s_lc.as_str() {
"lookup" => VerifyAlgorithm::Lookup,
"stream" => VerifyAlgorithm::Stream,
_ => return Err(format!("Invalid verification algorithm: '{}'", s)),
})
}
}

impl From<VerifyAlgorithm> for index::verify::Algorithm {
fn from(v: VerifyAlgorithm) -> Self {
match v {
VerifyAlgorithm::Lookup => index::verify::Algorithm::Lookup,
VerifyAlgorithm::Stream => index::verify::Algorithm::Stream,
}
}
}

/// A general purpose context for many operations provided here
pub struct Context<W1: io::Write, W2: io::Write> {
/// If set, provide statistics to `out` in the given format
Expand All @@ -54,6 +88,7 @@ pub struct Context<W1: io::Write, W2: io::Write> {
/// A value of 0 is interpreted as no-limit
pub thread_limit: Option<usize>,
pub mode: index::verify::Mode,
pub algorithm: index::verify::Algorithm,
}

impl Default for Context<Vec<u8>, Vec<u8>> {
Expand All @@ -62,6 +97,7 @@ impl Default for Context<Vec<u8>, Vec<u8>> {
output_statistics: None,
thread_limit: None,
mode: index::verify::Mode::Sha1CRC32,
algorithm: index::verify::Algorithm::Lookup,
out: Vec::new(),
err: Vec::new(),
}
Expand Down Expand Up @@ -102,6 +138,7 @@ pub fn verify_pack_or_pack_index<P, W1, W2>(
mode,
output_statistics,
thread_limit,
algorithm: _,
}: Context<W1, W2>,
) -> Result<(owned::Id, Option<index::verify::Outcome>)>
where
Expand Down
9 changes: 9 additions & 0 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod options {
use argh::FromArgs;
use gitoxide_core as core;
use std::path::PathBuf;

#[derive(FromArgs)]
Expand Down Expand Up @@ -46,6 +47,12 @@ mod options {
/// owned objects, causing plenty of allocation to occour.
pub re_encode: bool,

#[argh(option)]
/// the algorithm used to verify the pack. They differ in costs.
///
/// Possible values are "lookup" and "stream". Default is "stream".
pub algorithm: Option<core::VerifyAlgorithm>,

/// output statistical information about the pack
#[argh(switch, short = 's')]
pub statistics: bool,
Expand Down Expand Up @@ -97,6 +104,7 @@ pub fn main() -> Result<()> {
path,
verbose,
statistics,
algorithm,
decode,
re_encode,
}) => {
Expand All @@ -110,6 +118,7 @@ pub fn main() -> Result<()> {
} else {
None
},
algorithm: algorithm.unwrap_or(core::VerifyAlgorithm::Lookup).into(),
thread_limit,
mode: match (decode, re_encode) {
(true, false) => core::VerifyMode::Sha1CRC32Decode,
Expand Down
11 changes: 11 additions & 0 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ mod options {
)]
format: core::OutputFormat,

/// The algorithm used to verify the pack. They differ in costs.
#[structopt(
long,
short = "a",
default_value = "lookup",
possible_values(core::VerifyAlgorithm::variants())
)]
algorithm: core::VerifyAlgorithm,

/// verbose progress messages are printed line by line
#[structopt(long, short = "v")]
verbose: bool,
Expand Down Expand Up @@ -173,6 +182,7 @@ pub fn main() -> Result<()> {
match args.cmd {
Subcommands::VerifyPack {
path,
algorithm,
verbose,
progress,
format,
Expand All @@ -198,6 +208,7 @@ pub fn main() -> Result<()> {
core::Context {
output_statistics,
thread_limit,
algorithm: algorithm.into(),
mode,
out,
err,
Expand Down
4 changes: 4 additions & 0 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
* [x] The Rust repo verifies `--decode` and `--re-encode`
* [x] add re-encode to all stress tests
* [x] support easy access to merge-tags and the signature
* **stream pack for verify-pack**
* [ ] stream packs and feed information into a delegate to allow doing anything™️
* [ ] support for multi-threading
* [ ] use pack streaming in pack-verify
* **plumbing - explode pack**
* [ ] write loose object
* [ ] single threaded
Expand Down

0 comments on commit bcb275e

Please sign in to comment.