Skip to content

Commit 629dffc

Browse files
bk2204gitster
authored andcommittedMay 27, 2020
packfile: compute and use the index CRC offset
Both v2 pack index files and the v3 format specified as part of the NewHash work have similar data starting at the CRC table. Much of the existing code wants to read either this table or the offset entries following it, and in doing so computes the offset each time. In order to share as much code between v2 and v3, compute the offset of the CRC table and store it when the pack is opened. Use this value to compute offsets to not only the CRC table, but to the offset entries beyond it. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49c9a2f commit 629dffc

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed
 

‎builtin/index-pack.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -1555,13 +1555,9 @@ static void read_v2_anomalous_offsets(struct packed_git *p,
15551555
{
15561556
const uint32_t *idx1, *idx2;
15571557
uint32_t i;
1558-
const uint32_t hashwords = the_hash_algo->rawsz / sizeof(uint32_t);
15591558

15601559
/* The address of the 4-byte offset table */
1561-
idx1 = (((const uint32_t *)p->index_data)
1562-
+ 2 /* 8-byte header */
1563-
+ 256 /* fan out */
1564-
+ hashwords * p->num_objects /* object ID table */
1560+
idx1 = (((const uint32_t *)((const uint8_t *)p->index_data + p->crc_offset))
15651561
+ p->num_objects /* CRC32 table */
15661562
);
15671563

‎object-store.h

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct packed_git {
7070
size_t index_size;
7171
uint32_t num_objects;
7272
uint32_t num_bad_objects;
73+
uint32_t crc_offset;
7374
unsigned char *bad_object_sha1;
7475
int index_version;
7576
time_t mtime;

‎packfile.c

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
178178
*/
179179
(sizeof(off_t) <= 4))
180180
return error("pack too large for current definition of off_t in %s", path);
181+
p->crc_offset = 8 + 4 * 256 + nr * hashsz;
181182
}
182183

183184
p->index_version = version;

0 commit comments

Comments
 (0)
Please sign in to comment.