Skip to content

Commit

Permalink
refactor (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 1, 2022
1 parent f223ecb commit 91e6d38
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
23 changes: 18 additions & 5 deletions git-pack/src/multi_index/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,26 @@ pub mod integrity {
}

/// Additional options to define how the integrity should be verified.
#[derive(Default)]
pub struct Options {
pub struct Options<F> {
/// The thoroughness of the verification
pub verify_mode: crate::index::verify::Mode,
/// The way to traverse packs
pub traversal: crate::index::traverse::Algorithm,
/// The amount of theads to use of `Some(N)`, with `None|Some(0)` using all available cores are used.
pub thread_limit: Option<usize>,
/// A function to create a pack cache
pub make_pack_lookup_cache: F,
}

impl Default for Options<fn() -> crate::cache::Never> {
fn default() -> Self {
Options {
verify_mode: Default::default(),
traversal: Default::default(),
thread_limit: None,
make_pack_lookup_cache: || crate::cache::Never,
}
}
}
}

Expand Down Expand Up @@ -89,20 +101,21 @@ impl File {
///
/// Note that it's considered a failure if an index doesn't have a corresponding pack.
#[allow(unused)]
pub fn verify_integrity<C, P>(
pub fn verify_integrity<C, P, F>(
&self,
make_pack_lookup_cache: impl Fn() -> C + Send + Clone,
mut progress: P,
should_interrupt: &AtomicBool,
integrity::Options {
verify_mode,
traversal,
thread_limit,
}: integrity::Options,
make_pack_lookup_cache,
}: integrity::Options<F>,
) -> Result<integrity::Outcome<P>, crate::index::traverse::Error<integrity::Error>>
where
P: Progress,
C: crate::cache::DecodeEntry,
F: Fn() -> C + Send + Clone,
{
let parent = self.path.parent().expect("must be in a directory");

Expand Down
18 changes: 4 additions & 14 deletions git-pack/tests/pack/multi_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ mod verify {
fn integrity() {
let (file, _) = multi_index();
let outcome = file
.verify_integrity(
|| git_pack::cache::Never,
progress::Discard,
&AtomicBool::new(false),
Default::default(),
)
.verify_integrity(progress::Discard, &AtomicBool::new(false), Default::default())
.unwrap();
assert_eq!(outcome.actual_index_checksum, file.checksum());
assert_eq!(
Expand Down Expand Up @@ -171,14 +166,9 @@ mod write {
}

assert_eq!(
file.verify_integrity(
|| git_pack::cache::Never,
progress::Discard,
&AtomicBool::new(false),
Default::default()
)
.unwrap()
.actual_index_checksum,
file.verify_integrity(progress::Discard, &AtomicBool::new(false), Default::default())
.unwrap()
.actual_index_checksum,
outcome.multi_index_checksum
);
}
Expand Down

0 comments on commit 91e6d38

Please sign in to comment.