Skip to content

Commit 0bcb790

Browse files
committed
Pass option for safety checks down to explode(…)
1 parent 0416666 commit 0bcb790

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

gitoxide-core/src/pack/explode.rs

+55-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,61 @@ use git_features::progress::Progress;
33
use git_odb::pack;
44
use std::path::Path;
55

6-
pub fn pack_or_pack_index<P>(path: impl AsRef<Path>, _progress: Option<P>, _delete_pack: bool) -> Result<()>
6+
#[derive(PartialEq, Debug)]
7+
pub enum SafetyCheck {
8+
SkipFileChecksumVerification,
9+
SkipFileAndObjectChecksumVerification,
10+
SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError,
11+
All,
12+
}
13+
14+
impl SafetyCheck {
15+
pub fn variants() -> &'static [&'static str] {
16+
&[
17+
"all",
18+
"skip-file-checksum",
19+
"skip-file-and-object-checksum",
20+
"skip-file-and-object-checksum-and-no-abort-on-decode",
21+
]
22+
}
23+
}
24+
25+
impl std::str::FromStr for SafetyCheck {
26+
type Err = String;
27+
28+
fn from_str(s: &str) -> Result<Self, Self::Err> {
29+
Ok(match s {
30+
"skip-file-checksum" => SafetyCheck::SkipFileChecksumVerification,
31+
"skip-file-and-object-checksum" => SafetyCheck::SkipFileAndObjectChecksumVerification,
32+
"skip-file-and-object-checksum-and-no-abort-on-decode" => {
33+
SafetyCheck::SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError
34+
}
35+
"all" => SafetyCheck::All,
36+
_ => return Err(format!("Unknown value for safety check: '{}'", s)),
37+
})
38+
}
39+
}
40+
41+
impl From<SafetyCheck> for pack::index::traverse::SafetyCheck {
42+
fn from(v: SafetyCheck) -> Self {
43+
use pack::index::traverse::SafetyCheck::*;
44+
match v {
45+
SafetyCheck::All => All,
46+
SafetyCheck::SkipFileChecksumVerification => SkipFileChecksumVerification,
47+
SafetyCheck::SkipFileAndObjectChecksumVerification => SkipFileAndObjectChecksumVerification,
48+
SafetyCheck::SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError => {
49+
SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError
50+
}
51+
}
52+
}
53+
}
54+
55+
pub fn pack_or_pack_index<P>(
56+
path: impl AsRef<Path>,
57+
_check: SafetyCheck,
58+
_progress: Option<P>,
59+
_delete_pack: bool,
60+
) -> Result<()>
761
where
862
P: Progress,
963
{

src/plumbing/lean.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ mod options {
4242
#[argh(switch, short = 'v')]
4343
pub verbose: bool,
4444

45+
/// the amount of checks to run. Defaults to 'all'.
46+
///
47+
/// Allowed values:
48+
/// all
49+
/// skip-file-checksum
50+
/// skip-file-and-object-checksum
51+
/// skip-file-and-object-checksum-and-no-abort-on-decode
52+
#[argh(option, short = 'c')]
53+
pub check: Option<core::pack::explode::SafetyCheck>,
54+
4555
/// the '.pack' or '.idx' file to explode into loose objects
4656
#[argh(positional)]
4757
pub path: PathBuf,
@@ -116,18 +126,23 @@ fn prepare(verbose: bool, name: &str) -> (Option<prodash::line::JoinHandle>, Opt
116126
}
117127

118128
pub fn main() -> Result<()> {
119-
use gitoxide_core::pack::verify;
120129
pub use options::*;
121130
let cli: Args = crate::shared::from_env();
122131
let thread_limit = cli.threads;
123132
match cli.subcommand {
124133
SubCommands::PackExplode(PackExplode {
125134
path,
126135
verbose,
136+
check,
127137
delete_pack,
128138
}) => {
129139
let (_handle, progress) = prepare(verbose, "pack-explode");
130-
core::pack::explode::pack_or_pack_index(path, progress, delete_pack)
140+
core::pack::explode::pack_or_pack_index(
141+
path,
142+
check.unwrap_or(core::pack::explode::SafetyCheck::All),
143+
progress,
144+
delete_pack,
145+
)
131146
}
132147
SubCommands::PackVerify(PackVerify {
133148
path,
@@ -137,11 +152,12 @@ pub fn main() -> Result<()> {
137152
decode,
138153
re_encode,
139154
}) => {
155+
use self::core::pack::verify;
140156
let (_handle, progress) = prepare(verbose, "pack-verify");
141-
verify::pack_or_pack_index(
157+
core::pack::verify::pack_or_pack_index(
142158
path,
143159
progress,
144-
verify::Context {
160+
core::pack::verify::Context {
145161
output_statistics: if statistics {
146162
Some(core::OutputFormat::Human)
147163
} else {

src/plumbing/pretty.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ mod options {
3434
#[structopt(long)]
3535
delete_pack: bool,
3636

37+
/// The amount of checks to run. Defaults to 'all'.
38+
#[structopt(
39+
long,
40+
short = "c",
41+
default_value = "all",
42+
possible_values(core::pack::explode::SafetyCheck::variants())
43+
)]
44+
check: core::pack::explode::SafetyCheck,
45+
3746
/// Display verbose messages and progress information
3847
#[structopt(long, short = "v")]
3948
verbose: bool,
@@ -208,6 +217,7 @@ pub fn main() -> Result<()> {
208217
match args.cmd {
209218
Subcommands::PackExplode {
210219
verbose,
220+
check,
211221
progress,
212222
progress_keep_open,
213223
delete_pack,
@@ -217,7 +227,7 @@ pub fn main() -> Result<()> {
217227
verbose,
218228
progress,
219229
progress_keep_open,
220-
move |progress, _out, _err| core::pack::explode::pack_or_pack_index(path, progress, delete_pack),
230+
move |progress, _out, _err| core::pack::explode::pack_or_pack_index(path, check, progress, delete_pack),
221231
),
222232
Subcommands::PackVerify {
223233
path,

0 commit comments

Comments
 (0)