]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pack-check.c
Merge branch 'ma/list-object-filter-opt-msgfix'
[thirdparty/git.git] / pack-check.c
index e4ef71c67393f0c7a24eff6bc6aa32c938cec4d9..4b089fe8ec051af05044225c283ee5ff3c1dac84 100644 (file)
@@ -8,10 +8,6 @@
 
 struct idx_entry {
        off_t                offset;
-       union idx_entry_object {
-               const unsigned char *hash;
-               struct object_id *oid;
-       } oid;
        unsigned int nr;
 };
 
@@ -43,7 +39,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
        } while (len);
 
        index_crc = p->index_data;
-       index_crc += 2 + 256 + p->num_objects * (the_hash_algo->rawsz/4) + nr;
+       index_crc += 2 + 256 + (size_t)p->num_objects * (the_hash_algo->rawsz/4) + nr;
 
        return data_crc != ntohl(*index_crc);
 }
@@ -97,9 +93,6 @@ static int verify_packfile(struct repository *r,
        entries[nr_objects].offset = pack_sig_ofs;
        /* first sort entries by pack offset, since unpacking them is more efficient that way */
        for (i = 0; i < nr_objects; i++) {
-               entries[i].oid.hash = nth_packed_object_sha1(p, i);
-               if (!entries[i].oid.hash)
-                       die("internal error pack-check nth-packed-object");
                entries[i].offset = nth_packed_object_offset(p, i);
                entries[i].nr = i;
        }
@@ -107,11 +100,16 @@ static int verify_packfile(struct repository *r,
 
        for (i = 0; i < nr_objects; i++) {
                void *data;
+               struct object_id oid;
                enum object_type type;
                unsigned long size;
                off_t curpos;
                int data_valid;
 
+               if (nth_packed_object_id(&oid, p, entries[i].nr) < 0)
+                       BUG("unable to get oid of object %lu from %s",
+                           (unsigned long)entries[i].nr, p->pack_name);
+
                if (p->index_version > 1) {
                        off_t offset = entries[i].offset;
                        off_t len = entries[i+1].offset - offset;
@@ -119,7 +117,7 @@ static int verify_packfile(struct repository *r,
                        if (check_pack_crc(p, w_curs, offset, len, nr))
                                err = error("index CRC mismatch for object %s "
                                            "from %s at offset %"PRIuMAX"",
-                                           oid_to_hex(entries[i].oid.oid),
+                                           oid_to_hex(&oid),
                                            p->pack_name, (uintmax_t)offset);
                }
 
@@ -142,14 +140,14 @@ static int verify_packfile(struct repository *r,
 
                if (data_valid && !data)
                        err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
-                                   oid_to_hex(entries[i].oid.oid), p->pack_name,
+                                   oid_to_hex(&oid), p->pack_name,
                                    (uintmax_t)entries[i].offset);
-               else if (check_object_signature(r, entries[i].oid.oid, data, size, type_name(type)))
+               else if (check_object_signature(r, &oid, data, size, type_name(type)))
                        err = error("packed %s from %s is corrupt",
-                                   oid_to_hex(entries[i].oid.oid), p->pack_name);
+                                   oid_to_hex(&oid), p->pack_name);
                else if (fn) {
                        int eaten = 0;
-                       err |= fn(entries[i].oid.oid, type, size, data, &eaten);
+                       err |= fn(&oid, type, size, data, &eaten);
                        if (eaten)
                                data = NULL;
                }
@@ -166,7 +164,7 @@ static int verify_packfile(struct repository *r,
 
 int verify_pack_index(struct packed_git *p)
 {
-       off_t index_size;
+       size_t len;
        const unsigned char *index_base;
        git_hash_ctx ctx;
        unsigned char hash[GIT_MAX_RAWSZ];
@@ -174,14 +172,14 @@ int verify_pack_index(struct packed_git *p)
 
        if (open_pack_index(p))
                return error("packfile %s index not opened", p->pack_name);
-       index_size = p->index_size;
        index_base = p->index_data;
+       len = p->index_size - the_hash_algo->rawsz;
 
        /* Verify SHA1 sum of the index file */
        the_hash_algo->init_fn(&ctx);
-       the_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz));
+       the_hash_algo->update_fn(&ctx, index_base, len);
        the_hash_algo->final_fn(hash, &ctx);
-       if (!hasheq(hash, index_base + index_size - the_hash_algo->rawsz))
+       if (!hasheq(hash, index_base + len))
                err = error("Packfile index for %s hash mismatch",
                            p->pack_name);
        return err;