]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pack-bitmap.c
travis-ci: build with GCC 4.8 as well
[thirdparty/git.git] / pack-bitmap.c
index 4695aaf6b4eda41ec2479a326ddbe7a0bed065ab..6069b2fe556aba213743b8ce44503a1c0925cb30 100644 (file)
@@ -18,7 +18,7 @@
  * commit.
  */
 struct stored_bitmap {
-       unsigned char sha1[20];
+       struct object_id oid;
        struct ewah_bitmap *root;
        struct stored_bitmap *xor;
        int flags;
@@ -60,8 +60,8 @@ struct bitmap_index {
        struct ewah_bitmap *blobs;
        struct ewah_bitmap *tags;
 
-       /* Map from SHA1 -> `stored_bitmap` for all the bitmapped commits */
-       khash_sha1 *bitmaps;
+       /* Map from object ID -> `stored_bitmap` for all the bitmapped commits */
+       kh_oid_map_t *bitmaps;
 
        /* Number of bitmapped commits */
        uint32_t entry_count;
@@ -80,7 +80,7 @@ struct bitmap_index {
                struct object **objects;
                uint32_t *hashes;
                uint32_t count, alloc;
-               khash_sha1_pos *positions;
+               kh_oid_pos_t *positions;
        } ext_index;
 
        /* Bitmap result of the last performed walk */
@@ -138,7 +138,7 @@ static int load_bitmap_header(struct bitmap_index *index)
 {
        struct bitmap_disk_header *header = (void *)index->map;
 
-       if (index->map_size < sizeof(*header) + 20)
+       if (index->map_size < sizeof(*header) + the_hash_algo->rawsz)
                return error("Corrupted bitmap index (missing header data)");
 
        if (memcmp(header->magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)) != 0)
@@ -157,19 +157,19 @@ static int load_bitmap_header(struct bitmap_index *index)
                                "(Git requires BITMAP_OPT_FULL_DAG)");
 
                if (flags & BITMAP_OPT_HASH_CACHE) {
-                       unsigned char *end = index->map + index->map_size - 20;
+                       unsigned char *end = index->map + index->map_size - the_hash_algo->rawsz;
                        index->hashes = ((uint32_t *)end) - index->pack->num_objects;
                }
        }
 
        index->entry_count = ntohl(header->entry_count);
-       index->map_pos += sizeof(*header);
+       index->map_pos += sizeof(*header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz;
        return 0;
 }
 
 static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
                                          struct ewah_bitmap *root,
-                                         const unsigned char *sha1,
+                                         const unsigned char *hash,
                                          struct stored_bitmap *xor_with,
                                          int flags)
 {
@@ -181,15 +181,15 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
        stored->root = root;
        stored->xor = xor_with;
        stored->flags = flags;
-       hashcpy(stored->sha1, sha1);
+       oidread(&stored->oid, hash);
 
-       hash_pos = kh_put_sha1(index->bitmaps, stored->sha1, &ret);
+       hash_pos = kh_put_oid_map(index->bitmaps, stored->oid, &ret);
 
        /* a 0 return code means the insertion succeeded with no changes,
         * because the SHA1 already existed on the map. this is bad, there
         * shouldn't be duplicated commits in the index */
        if (ret == 0) {
-               error("Duplicate entry in bitmap index: %s", sha1_to_hex(sha1));
+               error("Duplicate entry in bitmap index: %s", hash_to_hex(hash));
                return NULL;
        }
 
@@ -306,9 +306,10 @@ static int load_pack_bitmap(struct bitmap_index *bitmap_git)
 {
        assert(bitmap_git->map);
 
-       bitmap_git->bitmaps = kh_init_sha1();
-       bitmap_git->ext_index.positions = kh_init_sha1_pos();
-       load_pack_revindex(bitmap_git->pack);
+       bitmap_git->bitmaps = kh_init_oid_map();
+       bitmap_git->ext_index.positions = kh_init_oid_pos();
+       if (load_pack_revindex(bitmap_git->pack))
+               goto failed;
 
        if (!(bitmap_git->commits = read_bitmap_1(bitmap_git)) ||
                !(bitmap_git->trees = read_bitmap_1(bitmap_git)) ||
@@ -362,10 +363,10 @@ struct include_data {
 };
 
 static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
-                                          const unsigned char *sha1)
+                                          const struct object_id *oid)
 {
-       khash_sha1_pos *positions = bitmap_git->ext_index.positions;
-       khiter_t pos = kh_get_sha1_pos(positions, sha1);
+       khash_oid_pos *positions = bitmap_git->ext_index.positions;
+       khiter_t pos = kh_get_oid_pos(positions, *oid);
 
        if (pos < kh_end(positions)) {
                int bitmap_pos = kh_value(positions, pos);
@@ -376,9 +377,9 @@ static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
 }
 
 static inline int bitmap_position_packfile(struct bitmap_index *bitmap_git,
-                                          const unsigned char *sha1)
+                                          const struct object_id *oid)
 {
-       off_t offset = find_pack_entry_one(sha1, bitmap_git->pack);
+       off_t offset = find_pack_entry_one(oid->hash, bitmap_git->pack);
        if (!offset)
                return -1;
 
@@ -386,10 +387,10 @@ static inline int bitmap_position_packfile(struct bitmap_index *bitmap_git,
 }
 
 static int bitmap_position(struct bitmap_index *bitmap_git,
-                          const unsigned char *sha1)
+                          const struct object_id *oid)
 {
-       int pos = bitmap_position_packfile(bitmap_git, sha1);
-       return (pos >= 0) ? pos : bitmap_position_extended(bitmap_git, sha1);
+       int pos = bitmap_position_packfile(bitmap_git, oid);
+       return (pos >= 0) ? pos : bitmap_position_extended(bitmap_git, oid);
 }
 
 static int ext_index_add_object(struct bitmap_index *bitmap_git,
@@ -401,7 +402,7 @@ static int ext_index_add_object(struct bitmap_index *bitmap_git,
        int hash_ret;
        int bitmap_pos;
 
-       hash_pos = kh_put_sha1_pos(eindex->positions, object->oid.hash, &hash_ret);
+       hash_pos = kh_put_oid_pos(eindex->positions, object->oid, &hash_ret);
        if (hash_ret > 0) {
                if (eindex->count >= eindex->alloc) {
                        eindex->alloc = (eindex->alloc + 16) * 3 / 2;
@@ -431,7 +432,7 @@ static void show_object(struct object *object, const char *name, void *data_)
        struct bitmap_show_data *data = data_;
        int bitmap_pos;
 
-       bitmap_pos = bitmap_position(data->bitmap_git, object->oid.hash);
+       bitmap_pos = bitmap_position(data->bitmap_git, &object->oid);
 
        if (bitmap_pos < 0)
                bitmap_pos = ext_index_add_object(data->bitmap_git, object,
@@ -446,7 +447,7 @@ static void show_commit(struct commit *commit, void *data)
 
 static int add_to_include_set(struct bitmap_index *bitmap_git,
                              struct include_data *data,
-                             const unsigned char *sha1,
+                             const struct object_id *oid,
                              int bitmap_pos)
 {
        khiter_t hash_pos;
@@ -457,7 +458,7 @@ static int add_to_include_set(struct bitmap_index *bitmap_git,
        if (bitmap_get(data->base, bitmap_pos))
                return 0;
 
-       hash_pos = kh_get_sha1(bitmap_git->bitmaps, sha1);
+       hash_pos = kh_get_oid_map(bitmap_git->bitmaps, *oid);
        if (hash_pos < kh_end(bitmap_git->bitmaps)) {
                struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, hash_pos);
                bitmap_or_ewah(data->base, lookup_stored_bitmap(st));
@@ -473,13 +474,13 @@ static int should_include(struct commit *commit, void *_data)
        struct include_data *data = _data;
        int bitmap_pos;
 
-       bitmap_pos = bitmap_position(data->bitmap_git, commit->object.oid.hash);
+       bitmap_pos = bitmap_position(data->bitmap_git, &commit->object.oid);
        if (bitmap_pos < 0)
                bitmap_pos = ext_index_add_object(data->bitmap_git,
                                                  (struct object *)commit,
                                                  NULL);
 
-       if (!add_to_include_set(data->bitmap_git, data, commit->object.oid.hash,
+       if (!add_to_include_set(data->bitmap_git, data, &commit->object.oid,
                                bitmap_pos)) {
                struct commit_list *parent = commit->parents;
 
@@ -517,7 +518,7 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
                roots = roots->next;
 
                if (object->type == OBJ_COMMIT) {
-                       khiter_t pos = kh_get_sha1(bitmap_git->bitmaps, object->oid.hash);
+                       khiter_t pos = kh_get_oid_map(bitmap_git->bitmaps, object->oid);
 
                        if (pos < kh_end(bitmap_git->bitmaps)) {
                                struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
@@ -559,7 +560,7 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
                int pos;
 
                roots = roots->next;
-               pos = bitmap_position(bitmap_git, object->oid.hash);
+               pos = bitmap_position(bitmap_git, &object->oid);
 
                if (pos < 0 || base == NULL || !bitmap_get(base, pos)) {
                        object->flags &= ~UNINTERESTING;
@@ -805,7 +806,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
 
                fprintf(stderr, "Failed to reuse at %d (%016llx)\n",
                        reuse_objects, result->words[i]);
-               fprintf(stderr, " %s\n", sha1_to_hex(sha1));
+               fprintf(stderr, " %s\n", hash_to_hex(sha1));
        }
 #endif
 
@@ -925,7 +926,7 @@ static void test_show_object(struct object *object, const char *name,
        struct bitmap_test_data *tdata = data;
        int bitmap_pos;
 
-       bitmap_pos = bitmap_position(tdata->bitmap_git, object->oid.hash);
+       bitmap_pos = bitmap_position(tdata->bitmap_git, &object->oid);
        if (bitmap_pos < 0)
                die("Object not in bitmap: %s\n", oid_to_hex(&object->oid));
 
@@ -939,7 +940,7 @@ static void test_show_commit(struct commit *commit, void *data)
        int bitmap_pos;
 
        bitmap_pos = bitmap_position(tdata->bitmap_git,
-                                    commit->object.oid.hash);
+                                    &commit->object.oid);
        if (bitmap_pos < 0)
                die("Object not in bitmap: %s\n", oid_to_hex(&commit->object.oid));
 
@@ -966,7 +967,7 @@ void test_bitmap_walk(struct rev_info *revs)
                bitmap_git->version, bitmap_git->entry_count);
 
        root = revs->pending.objects[0].item;
-       pos = kh_get_sha1(bitmap_git->bitmaps, root->oid.hash);
+       pos = kh_get_oid_map(bitmap_git->bitmaps, root->oid);
 
        if (pos < kh_end(bitmap_git->bitmaps)) {
                struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
@@ -1080,7 +1081,7 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
                                            lookup_stored_bitmap(stored),
                                            rebuild)) {
                                hash_pos = kh_put_sha1(reused_bitmaps,
-                                                      stored->sha1,
+                                                      stored->oid.hash,
                                                       &hash_ret);
                                kh_value(reused_bitmaps, hash_pos) =
                                        bitmap_to_ewah(rebuild);
@@ -1108,7 +1109,7 @@ void free_bitmap_index(struct bitmap_index *b)
        ewah_pool_free(b->trees);
        ewah_pool_free(b->blobs);
        ewah_pool_free(b->tags);
-       kh_destroy_sha1(b->bitmaps);
+       kh_destroy_oid_map(b->bitmaps);
        free(b->ext_index.objects);
        free(b->ext_index.hashes);
        bitmap_free(b->result);
@@ -1116,8 +1117,8 @@ void free_bitmap_index(struct bitmap_index *b)
        free(b);
 }
 
-int bitmap_has_sha1_in_uninteresting(struct bitmap_index *bitmap_git,
-                                    const unsigned char *sha1)
+int bitmap_has_oid_in_uninteresting(struct bitmap_index *bitmap_git,
+                                   const struct object_id *oid)
 {
        int pos;
 
@@ -1126,7 +1127,7 @@ int bitmap_has_sha1_in_uninteresting(struct bitmap_index *bitmap_git,
        if (!bitmap_git->haves)
                return 0; /* walk had no "haves" */
 
-       pos = bitmap_position_packfile(bitmap_git, sha1);
+       pos = bitmap_position_packfile(bitmap_git, oid);
        if (pos < 0)
                return 0;