History

keep track of the pack trailer

Sebastian Thiel committed 6 years ago

Commit cdba61e1 parent 1c2bcbd1 file · +11 −3Browse files

Unified · Split

git-odb/src/pack/index/write.rs+11−3
@@ -23,6 +23,9 @@ quick_error! { · 22 unmodified lines
2323 RefDelta {
2424 display("Ref delta objects are not supported as there is no way to look them up. Resolve them beforehand.")
2525 }
26+ IteratorInvariantTrailer {
27+ display("The iterator failed to set a trailing hash over all prior pack entries in the last provided entry")
28+ }
2629 }
2730 }
2831
@@ -60,6 +63,7 @@ impl pack::index::File { · 31 unmodified lines
6063 let mut num_objects = 0;
6164 // This array starts our sorted by pack-offset
6265 let mut index_entries = Vec::with_capacity(entries.size_hint().0);
66+ let mut last_seen_trailer = None;
6367 for entry in entries {
6468 let pack::data::iter::Entry {
6569 header,
@@ -67,7 +71,7 @@ impl pack::index::File { · 1 unmodified line
6771 header_size: _,
6872 compressed: _,
6973 decompressed,
70− trailer: _,
74+ trailer,
7175 } = entry?;
7276 use pack::data::Header::*;
7377 num_objects += 1;
@@ -93,20 +97,24 @@ impl pack::index::File { · 19 unmodified lines
9397 _pack_offset: pack_offset,
9498 _crc32: 0, // TBD
9599 _base_bytes: decompressed,
96− })
100+ });
101+ last_seen_trailer = trailer;
97102 }
98103
99104 out.write_all(V2_SIGNATURE)?;
100105
106+ // Write header
101107 let mut buf = [0u8; 4];
102108 BigEndian::write_u32(&mut buf, kind as u32);
103109 out.write_all(&buf)?;
104110
111+ // todo: write fanout
112+
105113 let _index_hash = out.hash.digest();
106114 Ok(Outcome {
107115 index_kind: kind,
108116 index_hash: owned::Id::from([0u8; 20]),
109− pack_hash: owned::Id::from([0u8; 20]),
117+ pack_hash: last_seen_trailer.ok_or(Error::IteratorInvariantTrailer)?,
110118 num_objects,
111119 })
112120 }