Unified · Split
| @@ -23,6 +23,9 @@ quick_error! { · 22 unmodified lines | |||
| 23 | RefDelta { | 23 | RefDelta { |
| 24 | display("Ref delta objects are not supported as there is no way to look them up. Resolve them beforehand.") | 24 | display("Ref delta objects are not supported as there is no way to look them up. Resolve them beforehand.") |
| 25 | } | 25 | } |
| 26 | IteratorInvariantTrailer { | ||
| 27 | display("The iterator failed to set a trailing hash over all prior pack entries in the last provided entry") | ||
| 28 | } | ||
| 26 | } | 29 | } |
| 27 | } | 30 | } |
| 28 | 31 | ||
| @@ -60,6 +63,7 @@ impl pack::index::File { · 31 unmodified lines | |||
| 60 | let mut num_objects = 0; | 63 | let mut num_objects = 0; |
| 61 | // This array starts our sorted by pack-offset | 64 | // This array starts our sorted by pack-offset |
| 62 | let mut index_entries = Vec::with_capacity(entries.size_hint().0); | 65 | let mut index_entries = Vec::with_capacity(entries.size_hint().0); |
| 66 | let mut last_seen_trailer = None; | ||
| 63 | for entry in entries { | 67 | for entry in entries { |
| 64 | let pack::data::iter::Entry { | 68 | let pack::data::iter::Entry { |
| 65 | header, | 69 | header, |
| @@ -67,7 +71,7 @@ impl pack::index::File { · 1 unmodified line | |||
| 67 | header_size: _, | 71 | header_size: _, |
| 68 | compressed: _, | 72 | compressed: _, |
| 69 | decompressed, | 73 | decompressed, |
| 70 | trailer: _, | 74 | trailer, |
| 71 | } = entry?; | 75 | } = entry?; |
| 72 | use pack::data::Header::*; | 76 | use pack::data::Header::*; |
| 73 | num_objects += 1; | 77 | num_objects += 1; |
| @@ -93,20 +97,24 @@ impl pack::index::File { · 19 unmodified lines | |||
| 93 | _pack_offset: pack_offset, | 97 | _pack_offset: pack_offset, |
| 94 | _crc32: 0, // TBD | 98 | _crc32: 0, // TBD |
| 95 | _base_bytes: decompressed, | 99 | _base_bytes: decompressed, |
| 96 | }) | 100 | }); |
| 101 | last_seen_trailer = trailer; | ||
| 97 | } | 102 | } |
| 98 | 103 | ||
| 99 | out.write_all(V2_SIGNATURE)?; | 104 | out.write_all(V2_SIGNATURE)?; |
| 100 | 105 | ||
| 106 | // Write header | ||
| 101 | let mut buf = [0u8; 4]; | 107 | let mut buf = [0u8; 4]; |
| 102 | BigEndian::write_u32(&mut buf, kind as u32); | 108 | BigEndian::write_u32(&mut buf, kind as u32); |
| 103 | out.write_all(&buf)?; | 109 | out.write_all(&buf)?; |
| 104 | 110 | ||
| 111 | // todo: write fanout | ||
| 112 | |||
| 105 | let _index_hash = out.hash.digest(); | 113 | let _index_hash = out.hash.digest(); |
| 106 | Ok(Outcome { | 114 | Ok(Outcome { |
| 107 | index_kind: kind, | 115 | index_kind: kind, |
| 108 | index_hash: owned::Id::from([0u8; 20]), | 116 | 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)?, |
| 110 | num_objects, | 118 | num_objects, |
| 111 | }) | 119 | }) |
| 112 | } | 120 | } |