Skip to content

Commit

Permalink
Pass option for safety checks down to explode(…)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 27, 2020
1 parent 0416666 commit 0bcb790
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 deletions.
56 changes: 55 additions & 1 deletion gitoxide-core/src/pack/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,61 @@ use git_features::progress::Progress;
use git_odb::pack;
use std::path::Path;

pub fn pack_or_pack_index<P>(path: impl AsRef<Path>, _progress: Option<P>, _delete_pack: bool) -> Result<()>
#[derive(PartialEq, Debug)]
pub enum SafetyCheck {
SkipFileChecksumVerification,
SkipFileAndObjectChecksumVerification,
SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError,
All,
}

impl SafetyCheck {
pub fn variants() -> &'static [&'static str] {
&[
"all",
"skip-file-checksum",
"skip-file-and-object-checksum",
"skip-file-and-object-checksum-and-no-abort-on-decode",
]
}
}

impl std::str::FromStr for SafetyCheck {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"skip-file-checksum" => SafetyCheck::SkipFileChecksumVerification,
"skip-file-and-object-checksum" => SafetyCheck::SkipFileAndObjectChecksumVerification,
"skip-file-and-object-checksum-and-no-abort-on-decode" => {
SafetyCheck::SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError
}
"all" => SafetyCheck::All,
_ => return Err(format!("Unknown value for safety check: '{}'", s)),
})
}
}

impl From<SafetyCheck> for pack::index::traverse::SafetyCheck {
fn from(v: SafetyCheck) -> Self {
use pack::index::traverse::SafetyCheck::*;
match v {
SafetyCheck::All => All,
SafetyCheck::SkipFileChecksumVerification => SkipFileChecksumVerification,
SafetyCheck::SkipFileAndObjectChecksumVerification => SkipFileAndObjectChecksumVerification,
SafetyCheck::SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError => {
SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError
}
}
}
}

pub fn pack_or_pack_index<P>(
path: impl AsRef<Path>,
_check: SafetyCheck,
_progress: Option<P>,
_delete_pack: bool,
) -> Result<()>
where
P: Progress,
{
Expand Down
24 changes: 20 additions & 4 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ mod options {
#[argh(switch, short = 'v')]
pub verbose: bool,

/// the amount of checks to run. Defaults to 'all'.
///
/// Allowed values:
/// all
/// skip-file-checksum
/// skip-file-and-object-checksum
/// skip-file-and-object-checksum-and-no-abort-on-decode
#[argh(option, short = 'c')]
pub check: Option<core::pack::explode::SafetyCheck>,

/// the '.pack' or '.idx' file to explode into loose objects
#[argh(positional)]
pub path: PathBuf,
Expand Down Expand Up @@ -116,18 +126,23 @@ fn prepare(verbose: bool, name: &str) -> (Option<prodash::line::JoinHandle>, Opt
}

pub fn main() -> Result<()> {
use gitoxide_core::pack::verify;
pub use options::*;
let cli: Args = crate::shared::from_env();
let thread_limit = cli.threads;
match cli.subcommand {
SubCommands::PackExplode(PackExplode {
path,
verbose,
check,
delete_pack,
}) => {
let (_handle, progress) = prepare(verbose, "pack-explode");
core::pack::explode::pack_or_pack_index(path, progress, delete_pack)
core::pack::explode::pack_or_pack_index(
path,
check.unwrap_or(core::pack::explode::SafetyCheck::All),
progress,
delete_pack,
)
}
SubCommands::PackVerify(PackVerify {
path,
Expand All @@ -137,11 +152,12 @@ pub fn main() -> Result<()> {
decode,
re_encode,
}) => {
use self::core::pack::verify;
let (_handle, progress) = prepare(verbose, "pack-verify");
verify::pack_or_pack_index(
core::pack::verify::pack_or_pack_index(
path,
progress,
verify::Context {
core::pack::verify::Context {
output_statistics: if statistics {
Some(core::OutputFormat::Human)
} else {
Expand Down
12 changes: 11 additions & 1 deletion src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ mod options {
#[structopt(long)]
delete_pack: bool,

/// The amount of checks to run. Defaults to 'all'.
#[structopt(
long,
short = "c",
default_value = "all",
possible_values(core::pack::explode::SafetyCheck::variants())
)]
check: core::pack::explode::SafetyCheck,

/// Display verbose messages and progress information
#[structopt(long, short = "v")]
verbose: bool,
Expand Down Expand Up @@ -208,6 +217,7 @@ pub fn main() -> Result<()> {
match args.cmd {
Subcommands::PackExplode {
verbose,
check,
progress,
progress_keep_open,
delete_pack,
Expand All @@ -217,7 +227,7 @@ pub fn main() -> Result<()> {
verbose,
progress,
progress_keep_open,
move |progress, _out, _err| core::pack::explode::pack_or_pack_index(path, progress, delete_pack),
move |progress, _out, _err| core::pack::explode::pack_or_pack_index(path, check, progress, delete_pack),
),
Subcommands::PackVerify {
path,
Expand Down

0 comments on commit 0bcb790

Please sign in to comment.