| @@ -1,5 +1,7 @@ |
| 1 | #![allow(missing_docs, unused)] | 1 | #![allow(missing_docs, unused)] |
| | 2 | |
| 2 | use filebuffer::FileBuffer; | 3 | use filebuffer::FileBuffer; |
| | 4 | use std::ops::Range; |
| 3 | | 5 | |
| 4 | /// Known multi-index file versions | 6 | /// Known multi-index file versions |
| 5 | #[derive(PartialEq, Eq, Ord, PartialOrd, Debug, Hash, Clone, Copy)] | 7 | #[derive(PartialEq, Eq, Ord, PartialOrd, Debug, Hash, Clone, Copy)] |
| @@ -25,6 +27,7 @@ pub struct File { · 19 unmodified lines |
| 25 | num_chunks: u8, | 27 | num_chunks: u8, |
| 26 | /// The amount of pack files contained within | 28 | /// The amount of pack files contained within |
| 27 | num_packs: u32, | 29 | num_packs: u32, |
| | 30 | fanout: Range<git_chunk::file::Offset>, |
| 28 | } | 31 | } |
| 29 | | 32 | |
| 30 | /// | 33 | /// |
| @@ -41,9 +44,27 @@ pub mod access { · 10 unmodified lines |
| 41 | } | 44 | } |
| 42 | } | 45 | } |
| 43 | | 46 | |
| | 47 | mod chunk { |
| | 48 | pub mod pack_names { |
| | 49 | pub const ID: git_chunk::Kind = 0x504e414d; /* "PNAM" */ |
| | 50 | } |
| | 51 | pub mod fanout { |
| | 52 | pub const ID: git_chunk::Kind = 0x4f494446; /* "OIDF" */ |
| | 53 | } |
| | 54 | pub mod lookup { |
| | 55 | pub const ID: git_chunk::Kind = 0x4f49444c; /* "OIDL" */ |
| | 56 | } |
| | 57 | pub mod offsets { |
| | 58 | pub const ID: git_chunk::Kind = 0x4f4f4646; /* "OOFF" */ |
| | 59 | } |
| | 60 | pub mod large_offsets { |
| | 61 | pub const ID: git_chunk::Kind = 0x4c4f4646; /* "LOFF" */ |
| | 62 | } |
| | 63 | } |
| | 64 | |
| 44 | /// | 65 | /// |
| 45 | pub mod init { | 66 | pub mod init { |
| 46 | use crate::multi_index::{File, Version}; | 67 | use crate::multi_index::{chunk, File, Version}; |
| 47 | use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; | 68 | use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; |
| 48 | use filebuffer::FileBuffer; | 69 | use filebuffer::FileBuffer; |
| 49 | use std::convert::{TryFrom, TryInto}; | 70 | use std::convert::{TryFrom, TryInto}; |
| @@ -65,6 +86,8 @@ pub mod init { · 15 unmodified lines |
| 65 | UnsupportedHashKind { kind: u8 }, | 86 | UnsupportedHashKind { kind: u8 }, |
| 66 | #[error(transparent)] | 87 | #[error(transparent)] |
| 67 | ChunkFileDecode(#[from] git_chunk::file::decode::Error), | 88 | ChunkFileDecode(#[from] git_chunk::file::decode::Error), |
| | 89 | #[error(transparent)] |
| | 90 | MissingChunk(#[from] git_chunk::file::index::not_found::Error), |
| 68 | } | 91 | } |
| 69 | } | 92 | } |
| 70 | pub use error::Error; | 93 | pub use error::Error; |
| @@ -128,12 +151,18 @@ pub mod init { · 57 unmodified lines |
| 128 | }; | 151 | }; |
| 129 | | 152 | |
| 130 | let chunks = git_chunk::file::Index::from_bytes(&data, HEADER_LEN, num_chunks as u32)?; | 153 | let chunks = git_chunk::file::Index::from_bytes(&data, HEADER_LEN, num_chunks as u32)?; |
| | 154 | let pack_names = chunks.offset_by_kind(chunk::pack_names::ID, "PNAM")?; |
| | 155 | let fanout = chunks.offset_by_kind(chunk::fanout::ID, "OIDF")?; |
| | 156 | let lookup = chunks.offset_by_kind(chunk::lookup::ID, "OIDL")?; |
| | 157 | let offsets = chunks.offset_by_kind(chunk::offsets::ID, "OOFF")?; |
| | 158 | let large_offsets = chunks.offset_by_kind(chunk::large_offsets::ID, "LOFF").ok(); |
| 131 | | 159 | |
| 132 | Ok(File { | 160 | Ok(File { |
| 133 | data, | 161 | data, |
| 134 | path: path.to_owned(), | 162 | path: path.to_owned(), |
| 135 | version, | 163 | version, |
| 136 | hash_kind, | 164 | hash_kind, |
| | 165 | fanout, |
| 137 | num_chunks, | 166 | num_chunks, |
| 138 | num_packs, | 167 | num_packs, |
| 139 | }) | 168 | }) |