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
52pub mod find;52pub mod find;
53///53///
54pub mod iter;54pub mod iter;
55///
56pub mod verify;
55 57
56/// The type for an iterator over `Result<git_hash::ObjectId, Error>)`58/// The type for an iterator over `Result<git_hash::ObjectId, Error>)`
57pub struct Iter {59pub struct Iter {
git-odb/src/store_impls/loose/verify.rs+34−0
@@ -0,0 +1,34 @@
1#![allow(missing_docs)]
2use crate::loose::Store;
3
4///
5pub 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
30impl 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 @@
1use git_odb::Write;1use git_odb::Write;
2 2
3use crate::store::loose::backend::{locate_oid, object_ids};3use crate::store::loose::{locate_oid, object_ids};
4 4
5#[test]5#[test]
6fn write() -> Result<(), Box<dyn std::error::Error>> {6fn 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 @@
1use git_actor::{Sign, Time};
2use git_object::bstr::ByteSlice;
3
1use git_odb::loose::Store;4use git_odb::loose::Store;
2use pretty_assertions::assert_eq;5use pretty_assertions::assert_eq;
3 6
@@ -29,10 +32,18 @@ pub fn locate_oid(id: git_hash::ObjectId, buf: &mut Vec<u8>) -> git_object::Data · 25 unmodified lines
29 ldb().try_find(id, buf).expect("read success").expect("id present")32 ldb().try_find(id, buf).expect("read success").expect("id present")
30}33}
31 34
35#[test]
36#[ignore]
37fn verify_integrity() {
38 let db = ldb();
39 let outcome = db.verify_integrity().unwrap();
40 assert_eq!(outcome.num_objects, 42);
41}
42
32mod write {43mod write {
33 use git_odb::{loose, Write};44 use git_odb::{loose, Write};
34 45
35 use crate::store::loose::backend::{locate_oid, object_ids};46 use crate::store::loose::{locate_oid, object_ids};
36 47
37 #[test]48 #[test]
38 fn read_and_write() -> Result<(), Box<dyn std::error::Error>> {49 fn read_and_write() -> Result<(), Box<dyn std::error::Error>> {
@@ -66,8 +77,7 @@ mod locate { · 27 unmodified lines
66 use crate::{77 use crate::{
67 hex_to_id,78 hex_to_id,
68 store::loose::{79 store::loose::{
69 backend::{ldb, locate_oid},80 signature, {ldb, locate_oid},
70 signature,
71 },81 },
72 };82 };
73 83
@@ -210,3 +220,15 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB · 136 unmodified lines
210 Ok(())220 Ok(())
211 }221 }
212}222}
223
224fn 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 @@
1use git_actor::{Sign, Time};
2use git_object::bstr::ByteSlice;
3
4pub mod backend;
5
6fn 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
163 match path.file_name() {163 match path.file_name() {
164 Some(file_name) if file_name == "multi-pack-index" => {164 Some(file_name) if file_name == "multi-pack-index" => {
165 let multi_index = git::odb::pack::multi_index::File::at(path)?;165 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{
167 verify_mode: mode,167 verify_mode: mode,
168 traversal: algorithm.into(),168 traversal: algorithm.into(),
169 thread_limit,169 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