Skip to content

Commit a24307d

Browse files
committed
frame for loose-db validation (#287)
1 parent d63176f commit a24307d

File tree

6 files changed

+63
-21
lines changed

6 files changed

+63
-21
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ fn hash_path(id: &git_hash::oid, mut root: PathBuf) -> PathBuf {
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 {
+34
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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/backend.rs renamed to git-odb/tests/odb/store/loose.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -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
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 {
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
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"[email protected]".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

-16
This file was deleted.

gitoxide-core/src/pack/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ where
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,

0 commit comments

Comments
 (0)