Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 80a4a7a

Browse files
committed
Very rough version of repository verification (#287)
1 parent 53d835a commit 80a4a7a

15 files changed

Lines changed: 128 additions & 39 deletions

File tree

git-hash/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
mod borrowed;
88

9-
use std::convert::TryFrom;
10-
use std::str::FromStr;
9+
use std::{convert::TryFrom, str::FromStr};
1110

1211
pub use borrowed::oid;
1312

git-odb/src/store_impls/dynamic/verify.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
use crate::pack;
2-
use crate::store::verify::integrity::{IndexStatistics, SingleOrMultiStatistics};
3-
use crate::types::IndexAndPacks;
1+
use std::{
2+
ops::Deref,
3+
sync::atomic::{AtomicBool, Ordering},
4+
};
5+
46
use git_features::progress::Progress;
5-
use std::ops::Deref;
6-
use std::sync::atomic::{AtomicBool, Ordering};
7+
8+
use crate::{
9+
pack,
10+
store::verify::integrity::{IndexStatistics, SingleOrMultiStatistics},
11+
types::IndexAndPacks,
12+
};
713

814
///
915
pub mod integrity {
10-
use crate::pack;
1116
use std::path::PathBuf;
1217

18+
use crate::pack;
19+
20+
/// Options for use in [`Store::verify_integrity()`][crate::Store::verify_integrity()].
21+
pub type Options<F> = pack::index::verify::integrity::Options<F>;
22+
1323
/// Returned by [`Store::verify_integrity()`][crate::Store::verify_integrity()].
1424
#[derive(Debug, thiserror::Error)]
1525
#[allow(missing_docs)]
@@ -81,7 +91,7 @@ impl super::Store {
8191
&self,
8292
mut progress: P,
8393
should_interrupt: &AtomicBool,
84-
options: pack::index::verify::integrity::Options<F>,
94+
options: integrity::Options<F>,
8595
) -> Result<integrity::Outcome<P>, integrity::Error>
8696
where
8797
P: Progress,

git-odb/src/store_impls/loose/verify.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
use crate::loose::Store;
2-
use crate::Write;
1+
use std::{
2+
sync::atomic::{AtomicBool, Ordering},
3+
time::Instant,
4+
};
5+
36
use git_features::progress::Progress;
4-
use std::sync::atomic::{AtomicBool, Ordering};
7+
8+
use crate::{loose::Store, Write};
59

610
///
711
pub mod integrity {
@@ -47,6 +51,7 @@ impl Store {
4751
let sink = crate::sink(self.object_hash);
4852

4953
let mut num_objects = 0;
54+
let start = Instant::now();
5055
let mut progress = progress.add_child("validating");
5156
progress.init(None, git_features::progress::count("objects"));
5257
for id in self.iter().filter_map(Result::ok) {
@@ -74,6 +79,7 @@ impl Store {
7479
return Err(integrity::Error::Interrupted);
7580
}
7681
}
82+
progress.show_throughput(start);
7783

7884
Ok(integrity::Statistics { num_objects })
7985
}

git-odb/tests/odb/store/dynamic.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,12 @@ fn auto_refresh_with_and_without_id_stability() -> crate::Result {
569569
}
570570

571571
mod verify {
572-
use crate::store::dynamic::db;
572+
use std::sync::atomic::AtomicBool;
573+
573574
use git_features::progress;
574575
use git_testtools::fixture_path;
575-
use std::sync::atomic::AtomicBool;
576+
577+
use crate::store::dynamic::db;
576578

577579
#[test]
578580
fn integrity() {

git-odb/tests/odb/store/loose.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use git_actor::{Sign, Time};
2-
use git_object::bstr::ByteSlice;
31
use std::sync::atomic::AtomicBool;
42

3+
use git_actor::{Sign, Time};
54
use git_features::progress;
5+
use git_object::bstr::ByteSlice;
66
use git_odb::loose::Store;
77
use pretty_assertions::assert_eq;
88

@@ -77,9 +77,7 @@ mod locate {
7777

7878
use crate::{
7979
hex_to_id,
80-
store::loose::{
81-
signature, {ldb, locate_oid},
82-
},
80+
store::loose::{ldb, locate_oid, signature},
8381
};
8482

8583
fn locate<'a>(hex: &str, buf: &'a mut Vec<u8>) -> git_object::Data<'a> {

git-pack/src/index/traverse/with_lookup.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use std::sync::atomic::{AtomicBool, Ordering};
2+
13
use git_features::{
24
parallel::{self, in_parallel_if},
35
progress::{self, unit, Progress},
46
};
5-
use std::sync::atomic::{AtomicBool, Ordering};
67

78
use super::{Error, Reducer};
89
use crate::{data, index, index::util};

git-pack/src/multi_index/chunk.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ pub mod lookup {
176176

177177
/// Information about the offsets table.
178178
pub mod offsets {
179-
use std::convert::TryInto;
180-
use std::ops::Range;
179+
use std::{convert::TryInto, ops::Range};
181180

182181
use byteorder::{BigEndian, WriteBytesExt};
183182

git-pack/src/multi_index/verify.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use std::time::Instant;
2-
use std::{cmp::Ordering, sync::atomic::AtomicBool};
1+
use std::{cmp::Ordering, sync::atomic::AtomicBool, time::Instant};
32

4-
use crate::index;
53
use git_features::progress::Progress;
64

7-
use crate::multi_index::File;
5+
use crate::{index, multi_index::File};
86

97
///
108
pub mod integrity {

git-pack/src/multi_index/write.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use std::sync::atomic::Ordering;
21
use std::{
32
convert::TryInto,
43
path::PathBuf,
5-
sync::atomic::AtomicBool,
4+
sync::atomic::{AtomicBool, Ordering},
65
time::{Instant, SystemTime},
76
};
87

gitoxide-core/src/pack/multi_index.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use git_repository::Progress;
2-
use std::io::BufWriter;
3-
use std::path::PathBuf;
4-
use std::sync::atomic::AtomicBool;
1+
use std::{io::BufWriter, path::PathBuf, sync::atomic::AtomicBool};
52

63
use git_repository as git;
4+
use git_repository::Progress;
75

86
pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=3;
97

0 commit comments

Comments
 (0)