History

refactor; enable testing of reverse-delta lookup

Sebastian Thiel committed 6 years ago

Commit 512daf91 parent 051da155 files · +34 −30Browse files

Unified · Split

5 files
  1. git-odb/src/pack/bundle.rs +1 −3
  2. git-odb/src/pack/index/verify/mod.rs +2 −4
  3. git-odb/tests/pack/index.rs +22 −21
  4. gitoxide-core/src/lib.rs +7 −2
  5. tasks.md +2 −0
git-odb/src/pack/bundle.rs+1−3
@@ -87,10 +87,8 @@ impl Bundle { · 86 unmodified lines
8787 C: pack::cache::DecodeEntry,
8888 {
8989 self.index.verify_checksum_of_index(
90− Some(&self.pack),
90+ Some((&self.pack, mode, pack::index::verify::Algorithm::default())),
9191 thread_limit,
92− mode,
93− pack::index::verify::Algorithm::default(),
9492 progress,
9593 make_cache,
9694 )
git-odb/src/pack/index/verify/mod.rs+2−4
@@ -140,10 +140,8 @@ impl index::File { · 139 unmodified lines
140140 /// redoing a lot of work across multiple objects.
141141 pub fn verify_checksum_of_index<P, C>(
142142 &self,
143− pack: Option<&pack::data::File>,
143+ pack: Option<(&pack::data::File, Mode, Algorithm)>,
144144 thread_limit: Option<usize>,
145− mode: Mode,
146− algorithm: Algorithm,
147145 progress: Option<P>,
148146 make_cache: impl Fn() -> C + Send + Sync,
149147 ) -> Result<(owned::Id, Option<Outcome>), Error>
@@ -171,7 +169,7 @@ impl index::File { · 21 unmodified lines
171169 };
172170 match pack {
173171 None => verify_self().map(|id| (id, None)),
174− Some(pack) => {
172+ Some((pack, mode, algorithm)) => {
175173 if self.checksum_of_pack() != pack.checksum() {
176174 return Err(Error::PackMismatch {
177175 actual: pack.checksum(),
git-odb/tests/pack/index.rs+22−21
@@ -74,6 +74,17 @@ use common_macros::b_tree_map; · 73 unmodified lines
7474 use git_features::progress::Discard;
7575 use git_odb::pack::cache::DecodeEntryNoop;
7676
77+static ALGOS: &[index::verify::Algorithm] = &[
78+ index::verify::Algorithm::Lookup,
79+ index::verify::Algorithm::DeltaTreeLookup,
80+];
81+
82+static MODES: &[index::verify::Mode] = &[
83+ index::verify::Mode::Sha1CRC32,
84+ index::verify::Mode::Sha1CRC32Decode,
85+ index::verify::Mode::Sha1CRC32DecodeEncode,
86+];
87+
7788 #[test]
7889 fn pack_lookup() {
7990 for (index_path, pack_path, stats) in &[
@@ -152,18 +163,15 @@ fn pack_lookup() { · 72 unmodified lines
152163
153164 assert_eq!(pack.kind(), pack::data::Kind::V2);
154165 assert_eq!(pack.num_objects(), idx.num_objects());
155− assert_eq!(
156− idx.verify_checksum_of_index(
157− Some(&pack),
158− None,
159− index::verify::Mode::Sha1CRC32DecodeEncode,
160− index::verify::Algorithm::Lookup,
161− Discard.into(),
162− || DecodeEntryNoop
163− )
164− .unwrap(),
165− (idx.checksum_of_index(), Some(stats.to_owned()))
166− );
166+ for algo in ALGOS {
167+ for mode in MODES {
168+ assert_eq!(
169+ idx.verify_checksum_of_index(Some((&pack, *mode, *algo)), None, Discard.into(), || DecodeEntryNoop)
170+ .unwrap(),
171+ (idx.checksum_of_index(), Some(stats.to_owned()))
172+ );
173+ }
174+ }
167175 let num_objects = stats
168176 .objects_per_chain_length
169177 .values()
@@ -212,15 +220,8 @@ fn iter() { · 42 unmodified lines
212220 assert_eq!(idx.version(), *version);
213221 assert_eq!(idx.num_objects(), *num_objects);
214222 assert_eq!(
215− idx.verify_checksum_of_index(
216− None,
217− None,
218− index::verify::Mode::Sha1CRC32Decode,
219− index::verify::Algorithm::Lookup,
220− Discard.into(),
221− || { DecodeEntryNoop }
222− )
223− .unwrap(),
223+ idx.verify_checksum_of_index(None, None, Discard.into(), || { DecodeEntryNoop })
224+ .unwrap(),
224225 (idx.checksum_of_index(), None)
225226 );
226227 assert_eq!(idx.checksum_of_index(), hex_to_id(index_checksum));
gitoxide-core/src/lib.rs+7−2
@@ -183,8 +183,13 @@ where · 182 unmodified lines
183183 }
184184 };
185185
186− idx.verify_checksum_of_index(pack.as_ref(), thread_limit, mode, algorithm.into(), progress, cache)
187− .with_context(|| "Verification failure")?
186+ idx.verify_checksum_of_index(
187+ pack.as_ref().map(|p| (p, mode, algorithm.into())),
188+ thread_limit,
189+ progress,
190+ cache,
191+ )
192+ .with_context(|| "Verification failure")?
188193 }
189194 ext => return Err(anyhow!("Unknown extension {:?}, expecting 'idx' or 'pack'", ext)),
190195 };
tasks.md+2−0
@@ -29,6 +29,8 @@ · 28 unmodified lines
2929 * [ ] `inc_by(step)` method
3030 * [ ] a way to measure throughput on drop
3131 * **plumbing - explode pack**
32+ * _useful for receiving packs that are small enough to warrant living as loose objects for a while
33+ preventing pack buildup_
3234 * [ ] write loose object
3335 * [ ] single threaded
3436 * [ ] multi-threaded