Showing the changes to git-commitgraph/src (1 of 1 file). Show all
Unified · Split
| @@ -114,8 +114,8 @@ impl TryFrom<&Path> for File { · 113 unmodified lines | ||
| 114 | 114 | |
| 115 | 115 | let chunks = git_chunk::file::Index::from_bytes(&data, ofs, chunk_count as u32)?; |
| 116 | 116 | |
| 117 | − let base_graphs_list_offset = match chunks.usize_offset_by_id(BASE_GRAPHS_LIST_CHUNK_ID).ok() { | |
| 118 | − Some(chunk_range) => { | |
| 117 | + let base_graphs_list_offset = chunks | |
| 118 | + .validated_usize_offset_by_id(BASE_GRAPHS_LIST_CHUNK_ID, |chunk_range| { | |
| 119 | 119 | let chunk_size = chunk_range.len(); |
| 120 | 120 | if chunk_size % SHA1_SIZE != 0 { |
| 121 | 121 | return Err(Error::InvalidChunkSize { |
| @@ -132,38 +132,33 @@ impl TryFrom<&Path> for File { · 10 unmodified lines | ||
| 132 | 132 | from_header: base_graph_count, |
| 133 | 133 | }); |
| 134 | 134 | } |
| 135 | − Some(chunk_range.start) | |
| 136 | − } | |
| 137 | − None => None, | |
| 138 | − }; | |
| 139 | − let (commit_data_offset, commit_data_count) = { | |
| 140 | − let chunk_range = chunks.usize_offset_by_id(COMMIT_DATA_CHUNK_ID)?; | |
| 141 | − let chunk_size = chunk_range.len(); | |
| 142 | − | |
| 143 | − if chunk_size % COMMIT_DATA_ENTRY_SIZE != 0 { | |
| 144 | − return Err(Error::InvalidChunkSize { | |
| 145 | − id: COMMIT_DATA_CHUNK_ID, | |
| 146 | − msg: format!( | |
| 147 | − "chunk size {} is not a multiple of {}", | |
| 148 | − chunk_size, COMMIT_DATA_ENTRY_SIZE | |
| 149 | − ), | |
| 150 | − }); | |
| 151 | − } | |
| 152 | − ( | |
| 153 | − chunk_range.start, | |
| 154 | − (chunk_size / COMMIT_DATA_ENTRY_SIZE) | |
| 155 | − .try_into() | |
| 156 | − .expect("number of commits in CDAT chunk to fit in 32 bits"), | |
| 157 | − ) | |
| 158 | − }; | |
| 159 | − | |
| 160 | − let extra_edges_list_range = chunks | |
| 161 | − .offset_by_id(EXTENDED_EDGES_LIST_CHUNK_ID) | |
| 135 | + Ok(chunk_range.start) | |
| 136 | + }) | |
| 162 | 137 | .ok() |
| 163 | − .and_then(git_chunk::range::into_usize); | |
| 138 | + .transpose()?; | |
| 164 | 139 | |
| 165 | − let fan_offset = { | |
| 166 | − let chunk_range = chunks.usize_offset_by_id(OID_FAN_CHUNK_ID)?; | |
| 140 | + let (commit_data_offset, commit_data_count) = | |
| 141 | + chunks.validated_usize_offset_by_id(COMMIT_DATA_CHUNK_ID, |chunk_range| { | |
| 142 | + let chunk_size = chunk_range.len(); | |
| 143 | + | |
| 144 | + if chunk_size % COMMIT_DATA_ENTRY_SIZE != 0 { | |
| 145 | + return Err(Error::InvalidChunkSize { | |
| 146 | + id: COMMIT_DATA_CHUNK_ID, | |
| 147 | + msg: format!( | |
| 148 | + "chunk size {} is not a multiple of {}", | |
| 149 | + chunk_size, COMMIT_DATA_ENTRY_SIZE | |
| 150 | + ), | |
| 151 | + }); | |
| 152 | + } | |
| 153 | + Ok(( | |
| 154 | + chunk_range.start, | |
| 155 | + (chunk_size / COMMIT_DATA_ENTRY_SIZE) | |
| 156 | + .try_into() | |
| 157 | + .expect("number of commits in CDAT chunk to fit in 32 bits"), | |
| 158 | + )) | |
| 159 | + })??; | |
| 160 | + | |
| 161 | + let fan_offset = chunks.validated_usize_offset_by_id(OID_FAN_CHUNK_ID, |chunk_range| { | |
| 167 | 162 | let chunk_size = chunk_range.len(); |
| 168 | 163 | |
| 169 | 164 | let expected_size = 4 * FAN_LEN; |
| @@ -173,29 +168,31 @@ impl TryFrom<&Path> for File { · 3 unmodified lines | ||
| 173 | 168 | msg: format!("expected chunk length {}, got {}", expected_size, chunk_size), |
| 174 | 169 | }); |
| 175 | 170 | } |
| 176 | − chunk_range.start | |
| 177 | − }; | |
| 171 | + Ok(chunk_range.start) | |
| 172 | + })??; | |
| 178 | 173 | |
| 179 | − let (oid_lookup_offset, oid_lookup_count) = { | |
| 180 | − let chunk_range = chunks.usize_offset_by_id(OID_LOOKUP_CHUNK_ID)?; | |
| 181 | − let chunk_size = chunk_range.len(); | |
| 174 | + let (oid_lookup_offset, oid_lookup_count) = | |
| 175 | + chunks.validated_usize_offset_by_id(OID_LOOKUP_CHUNK_ID, |chunk_range| { | |
| 176 | + let chunk_size = chunk_range.len(); | |
| 182 | 177 | |
| 183 | − if chunk_size % OID_LOOKUP_ENTRY_SIZE != 0 { | |
| 184 | − return Err(Error::InvalidChunkSize { | |
| 185 | − id: OID_LOOKUP_CHUNK_ID, | |
| 186 | − msg: format!( | |
| 187 | − "chunk size {} is not a multiple of {}", | |
| 188 | − chunk_size, OID_LOOKUP_ENTRY_SIZE | |
| 189 | − ), | |
| 190 | − }); | |
| 191 | − } | |
| 192 | − ( | |
| 193 | − chunk_range.start, | |
| 194 | − (chunk_size / OID_LOOKUP_ENTRY_SIZE) | |
| 195 | − .try_into() | |
| 196 | − .expect("number of commits in OIDL chunk to fit in 32 bits"), | |
| 197 | − ) | |
| 198 | − }; | |
| 178 | + if chunk_size % OID_LOOKUP_ENTRY_SIZE != 0 { | |
| 179 | + return Err(Error::InvalidChunkSize { | |
| 180 | + id: OID_LOOKUP_CHUNK_ID, | |
| 181 | + msg: format!( | |
| 182 | + "chunk size {} is not a multiple of {}", | |
| 183 | + chunk_size, OID_LOOKUP_ENTRY_SIZE | |
| 184 | + ), | |
| 185 | + }); | |
| 186 | + } | |
| 187 | + Ok(( | |
| 188 | + chunk_range.start, | |
| 189 | + (chunk_size / OID_LOOKUP_ENTRY_SIZE) | |
| 190 | + .try_into() | |
| 191 | + .expect("number of commits in OIDL chunk to fit in 32 bits"), | |
| 192 | + )) | |
| 193 | + })??; | |
| 194 | + | |
| 195 | + let extra_edges_list_range = chunks.usize_offset_by_id(EXTENDED_EDGES_LIST_CHUNK_ID).ok(); | |
| 199 | 196 | |
| 200 | 197 | let trailer = &data[chunks.highest_offset() as usize..]; |
| 201 | 198 | if trailer.len() != TRAILER_LEN { |