Skip to content

Commit

Permalink
Add simple pack verification to gio
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jun 25, 2020
1 parent 7cec2b6 commit 8c0e0b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "gitoxide"
description = "A command-line application for interacting with git repositories"
version = "1.0.0"
authors = ["Sebastian Thiel <[email protected]>"]
publish = false
Expand All @@ -14,6 +15,7 @@ doctest = false

[dependencies]
git-repository = { version = "0.1.0", path = "git-repository" }
git-odb = { version = "0.1.0", path = "git-odb" }
anyhow = "1.0.31"
structopt = "0.3.14"

Expand Down
29 changes: 29 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::{Context, Result};
use structopt::StructOpt;

mod options {
use std::path::PathBuf;
use structopt::clap::AppSettings;
use structopt::StructOpt;

Expand All @@ -16,12 +17,31 @@ mod options {
pub cmd: Subcommands,
}

/// Low-level commands that are not used every day
#[derive(Debug, StructOpt)]
pub enum Plumbing {
/// Verify the integrity of a pack or index file
#[structopt(setting = AppSettings::ColoredHelp)]
VerifyPack {
/// The '.pack' file whose checksum to validate.
///
/// '.pack' files have a 20 byte trailer representing the Sha1 over all the bytes that
/// preceded it.
#[structopt(parse(from_os_str))]
path: PathBuf,
},
}

#[derive(Debug, StructOpt)]
pub enum Subcommands {
/// Initialize the repository in the current directory.
#[structopt(alias = "initialize")]
#[structopt(setting = AppSettings::ColoredHelp)]
Init,

#[structopt(alias = "p")]
#[structopt(setting = AppSettings::ColoredHelp)]
Plumbing(Plumbing),
}
}

Expand All @@ -31,6 +51,15 @@ fn main() -> Result<()> {
options::Subcommands::Init => {
git_repository::init::repository().with_context(|| "Repository initialization failed")
}
options::Subcommands::Plumbing(cmd) => match cmd {
options::Plumbing::VerifyPack { path } => {
let pack =
git_odb::pack::File::at(path).with_context(|| "Could not open pack file")?;
pack.verify_checksum().with_context(|| "Failed")?;
println!("OK");
Ok(())
}
},
}?;
Ok(())
}

0 comments on commit 8c0e0b5

Please sign in to comment.