History

frame for loose-db validation (#287)

Sebastian Thiel committed 4 years ago

Commit a24307d1 parent d63176f6 files · +63 −21Browse files

Unified · Split

6 files
  1. git-odb/src/store_impls/loose/mod.rs +2 −0
  2. git-odb/src/store_impls/loose/verify.rs +34 −0
  3. git-odb/tests/odb/sink/mod.rs +1 −1
  4. git-odb/tests/odb/store/loose.rs +25 −3
  5. git-odb/tests/odb/store/loose/mod.rs +0 −16
  6. gitoxide-core/src/pack/verify.rs +1 −1
git-odb/src/store_impls/loose/mod.rs+2−0
@@ -52,6 +52,8 @@ fn hash_path(id: &git_hash::oid, mut root: PathBuf) -> PathBuf { · 51 unmodified lines
5252 pub mod find;
5353 ///
5454 pub mod iter;
55+///
56+pub mod verify;
5557
5658 /// The type for an iterator over `Result<git_hash::ObjectId, Error>)`
5759 pub struct Iter {
git-odb/src/store_impls/loose/verify.rs+34−0
@@ -0,0 +1,34 @@
1+#![allow(missing_docs)]
2+use crate::loose::Store;
3+
4+///
5+pub mod integrity {
6+ /// The error returned by [`verify_integrity()`][super::Store::verify_integrity()].
7+ #[derive(Debug, thiserror::Error)]
8+ #[allow(missing_docs)]
9+ pub enum Error {
10+ #[error("{kind} object {id} could not be decoded")]
11+ ObjectDecode {
12+ source: git_object::decode::Error,
13+ kind: git_object::Kind,
14+ id: git_hash::ObjectId,
15+ },
16+ #[error("{kind} object {expected} wasn't re-encoded without change - new hash is {actual}")]
17+ ObjectEncodeMismatch {
18+ kind: git_object::Kind,
19+ actual: git_hash::ObjectId,
20+ expected: git_hash::ObjectId,
21+ },
22+ }
23+
24+ pub struct Outcome {
25+ /// The amount of loose objects we checked.
26+ pub num_objects: usize,
27+ }
28+}
29+
30+impl Store {
31+ pub fn verify_integrity(&self) -> Result<integrity::Outcome, integrity::Error> {
32+ todo!()
33+ }
34+}
git-odb/tests/odb/sink/mod.rs+1−1
@@ -1,6 +1,6 @@
11 use git_odb::Write;
22
3−use crate::store::loose::backend::{locate_oid, object_ids};
3+use crate::store::loose::{locate_oid, object_ids};
44
55 #[test]
66 fn write() -> Result<(), Box<dyn std::error::Error>> {
git-odb/tests/odb/store/loose.rsrenamed from git-odb/tests/odb/store/loose/backend.rs+25−3
@@ -1,3 +1,6 @@
1+use git_actor::{Sign, Time};
2+use git_object::bstr::ByteSlice;
3+
14 use git_odb::loose::Store;
25 use pretty_assertions::assert_eq;
36
@@ -29,10 +32,18 @@ pub fn locate_oid(id: git_hash::ObjectId, buf: &mut Vec<u8>) -> git_object::Data · 25 unmodified lines
2932 ldb().try_find(id, buf).expect("read success").expect("id present")
3033 }
3134
35+#[test]
36+#[ignore]
37+fn verify_integrity() {
38+ let db = ldb();
39+ let outcome = db.verify_integrity().unwrap();
40+ assert_eq!(outcome.num_objects, 42);
41+}
42+
3243 mod write {
3344 use git_odb::{loose, Write};
3445
35− use crate::store::loose::backend::{locate_oid, object_ids};
46+ use crate::store::loose::{locate_oid, object_ids};
3647
3748 #[test]
3849 fn read_and_write() -> Result<(), Box<dyn std::error::Error>> {
@@ -66,8 +77,7 @@ mod locate { · 27 unmodified lines
6677 use crate::{
6778 hex_to_id,
6879 store::loose::{
69− backend::{ldb, locate_oid},
70− signature,
80+ signature, {ldb, locate_oid},
7181 },
7282 };
7383
@@ -210,3 +220,15 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB · 136 unmodified lines
210220 Ok(())
211221 }
212222 }
223+
224+fn signature(time: u32) -> git_actor::SignatureRef<'static> {
225+ git_actor::SignatureRef {
226+ name: b"Sebastian Thiel".as_bstr(),
227+ email: b"byronimo@gmail.com".as_bstr(),
228+ time: Time {
229+ time,
230+ offset: 7200,
231+ sign: Sign::Plus,
232+ },
233+ }
234+}
git-odb/tests/odb/store/loose/mod.rs+0−16
@@ -1,16 +0,0 @@
1−use git_actor::{Sign, Time};
2−use git_object::bstr::ByteSlice;
3−
4−pub mod backend;
5−
6−fn signature(time: u32) -> git_actor::SignatureRef<'static> {
7− git_actor::SignatureRef {
8− name: b"Sebastian Thiel".as_bstr(),
9− email: b"byronimo@gmail.com".as_bstr(),
10− time: Time {
11− time,
12− offset: 7200,
13− sign: Sign::Plus,
14− },
15− }
16−}
gitoxide-core/src/pack/verify.rs+1−1
@@ -163,7 +163,7 @@ where · 162 unmodified lines
163163 match path.file_name() {
164164 Some(file_name) if file_name == "multi-pack-index" => {
165165 let multi_index = git::odb::pack::multi_index::File::at(path)?;
166− let res = multi_index.verify_integrity(progress, should_interrupt, git::odb::pack::multi_index::verify::integrity::Options{
166+ let res = multi_index.verify_integrity(progress, should_interrupt, git::odb::pack::index::verify::integrity::Options{
167167 verify_mode: mode,
168168 traversal: algorithm.into(),
169169 thread_limit,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t