Showing the changes to git-commitgraph/src (1 of 1 file). Show all
Unified · Split
| @@ -44,6 +44,8 @@ pub enum Error { · 43 unmodified lines | ||
| 44 | 44 | }, |
| 45 | 45 | #[error("Missing required chunk {:?}", .0.as_bstr())] |
| 46 | 46 | MissingChunk(ChunkId), |
| 47 | + #[error(transparent)] | |
| 48 | + MissingChunk2(#[from] git_chunk::file::index::offset_by_kind::Error), | |
| 47 | 49 | #[error("{0}")] |
| 48 | 50 | Trailer(String), |
| 49 | 51 | #[error("Commit-graph file uses unsupported hash version: {0}")] |
| @@ -116,41 +118,30 @@ impl TryFrom<&Path> for File { · 66 unmodified lines | ||
| 116 | 118 | |
| 117 | 119 | let chunks = git_chunk::file::Index::from_bytes(&data, ofs, chunk_count as u32)?; |
| 118 | 120 | |
| 119 | − let mut base_graphs_list_offset: Option<usize> = None; | |
| 120 | − let mut commit_data_offset: Option<usize> = None; | |
| 121 | − let mut commit_data_count = 0u32; | |
| 122 | − let mut fan_offset: Option<usize> = None; | |
| 123 | − let mut oid_lookup_offset: Option<usize> = None; | |
| 124 | − let mut oid_lookup_count = 0u32; | |
| 125 | − | |
| 126 | − if let Some(chunk_range) = chunks | |
| 127 | − .offset_by_id(BASE_GRAPHS_LIST_CHUNK_ID) | |
| 128 | − .ok() | |
| 129 | − .and_then(git_chunk::range::into_usize) | |
| 130 | − { | |
| 131 | − let chunk_size = chunk_range.len(); | |
| 132 | − if chunk_size % SHA1_SIZE != 0 { | |
| 133 | − return Err(Error::InvalidChunkSize { | |
| 134 | − id: BASE_GRAPHS_LIST_CHUNK_ID, | |
| 135 | − msg: format!("chunk size {} is not a multiple of {}", chunk_size, SHA1_SIZE), | |
| 136 | − }); | |
| 137 | − } | |
| 138 | − let chunk_base_graph_count: u32 = (chunk_size / SHA1_SIZE) | |
| 139 | − .try_into() | |
| 140 | − .expect("base graph count to fit in 32-bits"); | |
| 141 | − if chunk_base_graph_count != u32::from(base_graph_count) { | |
| 142 | − return Err(Error::BaseGraphMismatch { | |
| 143 | − from_chunk: chunk_base_graph_count, | |
| 144 | − from_header: base_graph_count, | |
| 145 | − }); | |
| 121 | + let base_graphs_list_offset = match chunks.usize_offset_by_id(BASE_GRAPHS_LIST_CHUNK_ID).ok() { | |
| 122 | + Some(chunk_range) => { | |
| 123 | + let chunk_size = chunk_range.len(); | |
| 124 | + if chunk_size % SHA1_SIZE != 0 { | |
| 125 | + return Err(Error::InvalidChunkSize { | |
| 126 | + id: BASE_GRAPHS_LIST_CHUNK_ID, | |
| 127 | + msg: format!("chunk size {} is not a multiple of {}", chunk_size, SHA1_SIZE), | |
| 128 | + }); | |
| 129 | + } | |
| 130 | + let chunk_base_graph_count: u32 = (chunk_size / SHA1_SIZE) | |
| 131 | + .try_into() | |
| 132 | + .expect("base graph count to fit in 32-bits"); | |
| 133 | + if chunk_base_graph_count != u32::from(base_graph_count) { | |
| 134 | + return Err(Error::BaseGraphMismatch { | |
| 135 | + from_chunk: chunk_base_graph_count, | |
| 136 | + from_header: base_graph_count, | |
| 137 | + }); | |
| 138 | + } | |
| 139 | + Some(chunk_range.start) | |
| 146 | 140 | } |
| 147 | − base_graphs_list_offset = Some(chunk_range.start); | |
| 148 | − } | |
| 149 | − if let Some(chunk_range) = chunks | |
| 150 | − .offset_by_id(COMMIT_DATA_CHUNK_ID) | |
| 151 | − .ok() | |
| 152 | − .and_then(git_chunk::range::into_usize) | |
| 153 | − { | |
| 141 | + None => None, | |
| 142 | + }; | |
| 143 | + let (commit_data_offset, commit_data_count) = { | |
| 144 | + let chunk_range = chunks.usize_offset_by_id(COMMIT_DATA_CHUNK_ID)?; | |
| 154 | 145 | let chunk_size = chunk_range.len(); |
| 155 | 146 | |
| 156 | 147 | if chunk_size % COMMIT_DATA_ENTRY_SIZE != 0 { |
| @@ -162,22 +153,21 @@ impl TryFrom<&Path> for File { · 5 unmodified lines | ||
| 162 | 153 | ), |
| 163 | 154 | }); |
| 164 | 155 | } |
| 165 | − commit_data_offset = Some(chunk_range.start); | |
| 166 | − commit_data_count = (chunk_size / COMMIT_DATA_ENTRY_SIZE) | |
| 167 | − .try_into() | |
| 168 | − .expect("number of commits in CDAT chunk to fit in 32 bits"); | |
| 169 | − } | |
| 156 | + ( | |
| 157 | + chunk_range.start, | |
| 158 | + (chunk_size / COMMIT_DATA_ENTRY_SIZE) | |
| 159 | + .try_into() | |
| 160 | + .expect("number of commits in CDAT chunk to fit in 32 bits"), | |
| 161 | + ) | |
| 162 | + }; | |
| 170 | 163 | |
| 171 | 164 | let extra_edges_list_range = chunks |
| 172 | 165 | .offset_by_id(EXTENDED_EDGES_LIST_CHUNK_ID) |
| 173 | 166 | .ok() |
| 174 | 167 | .and_then(git_chunk::range::into_usize); |
| 175 | 168 | |
| 176 | − if let Some(chunk_range) = chunks | |
| 177 | − .offset_by_id(OID_FAN_CHUNK_ID) | |
| 178 | − .ok() | |
| 179 | − .and_then(git_chunk::range::into_usize) | |
| 180 | − { | |
| 169 | + let fan_offset = { | |
| 170 | + let chunk_range = chunks.usize_offset_by_id(OID_FAN_CHUNK_ID)?; | |
| 181 | 171 | let chunk_size = chunk_range.len(); |
| 182 | 172 | |
| 183 | 173 | let expected_size = 4 * FAN_LEN; |
| @@ -187,39 +177,29 @@ impl TryFrom<&Path> for File { · 3 unmodified lines | ||
| 187 | 177 | msg: format!("expected chunk length {}, got {}", expected_size, chunk_size), |
| 188 | 178 | }); |
| 189 | 179 | } |
| 190 | − fan_offset = Some(chunk_range.start); | |
| 191 | − } | |
| 180 | + chunk_range.start | |
| 181 | + }; | |
| 192 | 182 | |
| 193 | − if let Some(chunk_range) = chunks | |
| 194 | − .offset_by_id(OID_LOOKUP_CHUNK_ID) | |
| 195 | − .ok() | |
| 196 | − .and_then(git_chunk::range::into_usize) | |
| 197 | − { | |
| 183 | + let (oid_lookup_offset, oid_lookup_count) = { | |
| 184 | + let chunk_range = chunks.usize_offset_by_id(OID_LOOKUP_CHUNK_ID)?; | |
| 198 | 185 | let chunk_size = chunk_range.len(); |
| 199 | 186 | |
| 200 | 187 | if chunk_size % OID_LOOKUP_ENTRY_SIZE != 0 { |
| 201 | 188 | return Err(Error::InvalidChunkSize { |
| 202 | − id: OID_FAN_CHUNK_ID, | |
| 189 | + id: OID_LOOKUP_CHUNK_ID, | |
| 203 | 190 | msg: format!( |
| 204 | 191 | "chunk size {} is not a multiple of {}", |
| 205 | 192 | chunk_size, OID_LOOKUP_ENTRY_SIZE |
| 206 | 193 | ), |
| 207 | 194 | }); |
| 208 | 195 | } |
| 209 | − oid_lookup_offset = Some(chunk_range.start); | |
| 210 | − oid_lookup_count = (chunk_size / OID_LOOKUP_ENTRY_SIZE) | |
| 211 | − .try_into() | |
| 212 | − .expect("number of commits in OIDL chunk to fit in 32 bits"); | |
| 213 | − // TODO(ST): Figure out how to handle this. Don't know what to do with the commented code. | |
| 214 | − // git allows extra garbage in the extra edges list chunk? | |
| 215 | − // if oid_lookup_count > 0 { | |
| 216 | − // let last_edge = &data[next_chunk_offset - 4..next_chunk_offset]; | |
| 217 | − // let last_edge = BigEndian::read_u32(last_edge); | |
| 218 | − // if let ExtraEdge::Internal(_) = ExtraEdge::from_raw(last_edge) { | |
| 219 | − // return Err(Error::ExtraEdgesListOverflow); | |
| 220 | − // } | |
| 221 | − // } | |
| 222 | − } | |
| 196 | + ( | |
| 197 | + chunk_range.start, | |
| 198 | + (chunk_size / OID_LOOKUP_ENTRY_SIZE) | |
| 199 | + .try_into() | |
| 200 | + .expect("number of commits in OIDL chunk to fit in 32 bits"), | |
| 201 | + ) | |
| 202 | + }; | |
| 223 | 203 | |
| 224 | 204 | let trailer = &data[chunks.highest_offset() as usize..]; |
| 225 | 205 | if trailer.len() != TRAILER_LEN { |
| @@ -230,10 +210,7 @@ impl TryFrom<&Path> for File { · 4 unmodified lines | ||
| 230 | 210 | ))); |
| 231 | 211 | } |
| 232 | 212 | |
| 233 | − let fan_offset = fan_offset.ok_or(Error::MissingChunk(OID_FAN_CHUNK_ID))?; | |
| 234 | − let oid_lookup_offset = oid_lookup_offset.ok_or(Error::MissingChunk(OID_LOOKUP_CHUNK_ID))?; | |
| 235 | − let commit_data_offset = commit_data_offset.ok_or(Error::MissingChunk(COMMIT_DATA_CHUNK_ID))?; | |
| 236 | − if base_graph_count > 0 && base_graphs_list_offset == None { | |
| 213 | + if base_graph_count > 0 && base_graphs_list_offset.is_none() { | |
| 237 | 214 | return Err(Error::MissingChunk(BASE_GRAPHS_LIST_CHUNK_ID)); |
| 238 | 215 | } |
| 239 | 216 | |