]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: compute and use the index CRC offset
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 25 May 2020 19:59:10 +0000 (19:59 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 May 2020 17:07:07 +0000 (10:07 -0700)
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 <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/index-pack.c
object-store.h
packfile.c

index f176dd28c870d5e417b373f2bb0d39b4fa1a0c29..7bea1fba52a9d3762ffb376f35f4773117fa4f4e 100644 (file)
@@ -1555,13 +1555,9 @@ static void read_v2_anomalous_offsets(struct packed_git *p,
 {
        const uint32_t *idx1, *idx2;
        uint32_t i;
-       const uint32_t hashwords = the_hash_algo->rawsz / sizeof(uint32_t);
 
        /* The address of the 4-byte offset table */
-       idx1 = (((const uint32_t *)p->index_data)
-               + 2 /* 8-byte header */
-               + 256 /* fan out */
-               + hashwords * p->num_objects /* object ID table */
+       idx1 = (((const uint32_t *)((const uint8_t *)p->index_data + p->crc_offset))
                + p->num_objects /* CRC32 table */
                );
 
index d1e490f2035d2f48583a30eb7a44cc4613a662fd..f439d47af81d1b8772b181cead999bba28980e21 100644 (file)
@@ -70,6 +70,7 @@ struct packed_git {
        size_t index_size;
        uint32_t num_objects;
        uint32_t num_bad_objects;
+       uint32_t crc_offset;
        unsigned char *bad_object_sha1;
        int index_version;
        time_t mtime;
index f4e752996dbcca3778c42de1d55d856a28be974d..6ab5233613e2417f8ee9ce0991ae532726b59b20 100644 (file)
@@ -178,6 +178,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
                     */
                    (sizeof(off_t) <= 4))
                        return error("pack too large for current definition of off_t in %s", path);
+               p->crc_offset = 8 + 4 * 256 + nr * hashsz;
        }
 
        p->index_version = version;