History

Adapt to changes in git-chunk (#279)

Sebastian Thiel committed 4 years ago

Commit 44ea5c31 parent dda26a42 files · +14 −13Browse files

Unified · Split

2 files
  1. git-pack/src/multi_index/chunk.rs +6 −6
  2. git-pack/src/multi_index/init.rs +8 −7
git-pack/src/multi_index/chunk.rs+6−6
@@ -1,9 +1,9 @@
1pub mod pack_names {1pub mod index_names {
2 use git_object::bstr::{BString, ByteSlice};2 use git_object::bstr::{BString, ByteSlice};
3 use os_str_bytes::OsStrBytes;3 use os_str_bytes::OsStrBytes;
4 use std::path::{Path, PathBuf};4 use std::path::{Path, PathBuf};
5 5
6 pub const ID: git_chunk::Kind = *b"PNAM";6 pub const ID: git_chunk::Id = *b"PNAM";
7 7
8 pub mod from_slice {8 pub mod from_slice {
9 use git_object::bstr::BString;9 use git_object::bstr::BString;
@@ -50,7 +50,7 @@ pub mod pack_names { · 40 unmodified lines
50pub mod fanout {50pub mod fanout {
51 use std::convert::TryInto;51 use std::convert::TryInto;
52 52
53 pub const ID: git_chunk::Kind = *b"OIDF";53 pub const ID: git_chunk::Id = *b"OIDF";
54 54
55 pub fn from_slice(chunk: &[u8]) -> Option<[u32; 256]> {55 pub fn from_slice(chunk: &[u8]) -> Option<[u32; 256]> {
56 if chunk.len() != 4 * 256 {56 if chunk.len() != 4 * 256 {
@@ -69,7 +69,7 @@ pub mod lookup { · 12 unmodified lines
69 use git_hash::Kind;69 use git_hash::Kind;
70 use std::ops::Range;70 use std::ops::Range;
71 71
72 pub const ID: git_chunk::Kind = *b"OIDL";72 pub const ID: git_chunk::Id = *b"OIDL";
73 73
74 pub fn is_valid(offset: &Range<Offset>, hash: git_hash::Kind, num_objects: u32) -> bool {74 pub fn is_valid(offset: &Range<Offset>, hash: git_hash::Kind, num_objects: u32) -> bool {
75 (offset.end - offset.start) as usize / hash.len_in_bytes() == num_objects as usize75 (offset.end - offset.start) as usize / hash.len_in_bytes() == num_objects as usize
@@ -80,7 +80,7 @@ pub mod offsets { · 4 unmodified lines
80 use git_chunk::file::Offset;80 use git_chunk::file::Offset;
81 use std::ops::Range;81 use std::ops::Range;
82 82
83 pub const ID: git_chunk::Kind = *b"OOFF";83 pub const ID: git_chunk::Id = *b"OOFF";
84 84
85 pub fn is_valid(offset: &Range<Offset>, num_objects: u32) -> bool {85 pub fn is_valid(offset: &Range<Offset>, num_objects: u32) -> bool {
86 let entry_size = 4 /* pack-id */ + 4 /* pack-offset */;86 let entry_size = 4 /* pack-id */ + 4 /* pack-offset */;
@@ -92,7 +92,7 @@ pub mod large_offsets { · 5 unmodified lines
92 use git_chunk::file::Offset;92 use git_chunk::file::Offset;
93 use std::ops::Range;93 use std::ops::Range;
94 94
95 pub const ID: git_chunk::Kind = *b"LOFF";95 pub const ID: git_chunk::Id = *b"LOFF";
96 pub fn is_valid(offset: Option<&Range<Offset>>) -> bool {96 pub fn is_valid(offset: Option<&Range<Offset>>) -> bool {
97 offset97 offset
98 .map(|offset| (offset.end - offset.start) as usize % 8 == 0)98 .map(|offset| (offset.end - offset.start) as usize % 8 == 0)
git-pack/src/multi_index/init.rs+8−7
@@ -29,7 +29,7 @@ mod error { · 28 unmodified lines
29 #[error("The multi-pack fan doesn't have the correct size of 256 * 4 bytes")]29 #[error("The multi-pack fan doesn't have the correct size of 256 * 4 bytes")]
30 MultiPackFanSize,30 MultiPackFanSize,
31 #[error(transparent)]31 #[error(transparent)]
32 PackNames(#[from] chunk::pack_names::from_slice::Error),32 PackNames(#[from] chunk::index_names::from_slice::Error),
33 #[error("The chunk with alphabetically ordered object ids doesn't have the correct size")]33 #[error("The chunk with alphabetically ordered object ids doesn't have the correct size")]
34 OidLookupSize,34 OidLookupSize,
35 #[error("The chunk with offsets into the pack doesn't have the correct size")]35 #[error("The chunk with offsets into the pack doesn't have the correct size")]
@@ -100,22 +100,23 @@ impl TryFrom<&Path> for File { · 64 unmodified lines
100 };100 };
101 101
102 let chunks = git_chunk::file::Index::from_bytes(&data, HEADER_LEN, num_chunks as u32)?;102 let chunks = git_chunk::file::Index::from_bytes(&data, HEADER_LEN, num_chunks as u32)?;
103 let pack_names = chunks.data_by_kind(&data, chunk::pack_names::ID)?;
104 let index_names = chunk::pack_names::from_slice(pack_names, num_packs)?;
105 103
106 let fan = chunks.data_by_kind(&data, chunk::fanout::ID)?;104 let index_names = chunks.data_by_id(&data, chunk::index_names::ID)?;
105 let index_names = chunk::index_names::from_slice(index_names, num_packs)?;
106
107 let fan = chunks.data_by_id(&data, chunk::fanout::ID)?;
107 let fan = chunk::fanout::from_slice(fan).ok_or(Error::MultiPackFanSize)?;108 let fan = chunk::fanout::from_slice(fan).ok_or(Error::MultiPackFanSize)?;
108 let num_objects = fan[255];109 let num_objects = fan[255];
109 110
110 let lookup = chunks.offset_by_kind(chunk::lookup::ID)?;111 let lookup = chunks.offset_by_id(chunk::lookup::ID)?;
111 if !chunk::lookup::is_valid(&lookup, hash_kind, num_objects) {112 if !chunk::lookup::is_valid(&lookup, hash_kind, num_objects) {
112 return Err(Error::OidLookupSize);113 return Err(Error::OidLookupSize);
113 }114 }
114 let offsets = chunks.offset_by_kind(chunk::offsets::ID)?;115 let offsets = chunks.offset_by_id(chunk::offsets::ID)?;
115 if !chunk::offsets::is_valid(&offsets, num_objects) {116 if !chunk::offsets::is_valid(&offsets, num_objects) {
116 return Err(Error::OffsetsSize);117 return Err(Error::OffsetsSize);
117 }118 }
118 let large_offsets = chunks.offset_by_kind(chunk::large_offsets::ID).ok();119 let large_offsets = chunks.offset_by_id(chunk::large_offsets::ID).ok();
119 if !chunk::large_offsets::is_valid(large_offsets.as_ref()) {120 if !chunk::large_offsets::is_valid(large_offsets.as_ref()) {
120 return Err(Error::LargeOffsetsSize);121 return Err(Error::LargeOffsetsSize);
121 }122 }