pack-bitmap: switch hash tables to use struct object_id

Instead of storing unsigned char pointers in the hash tables, switch to storing instances of struct object_id. Update several internal functions and one external function to take pointers to struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 19, 2019 at 00:04 UTC 3c7714485dc8adc810b6c52058992cfc767dfcb5
3 files changed +33 -33
builtin/pack-objects.c
+3 -3
@@ -1487,6 +1487,7 @@ static int can_reuse_delta(const unsigned char *base_sha1,
1487 struct object_entry **base_out)
1488 {
1489 struct object_entry *base;
1490 + struct object_id base_oid;
1491
1492 if (!base_sha1)
1493 return 0;
@@ -1508,10 +1509,9 @@ static int can_reuse_delta(const unsigned char *base_sha1,
1509 * even if it was buried too deep in history to make it into the
1510 * packing list.
1511 */
1511 - if (thin && bitmap_has_sha1_in_uninteresting(bitmap_git, base_sha1)) {
1512 + oidread(&base_oid, base_sha1);
1513 + if (thin && bitmap_has_oid_in_uninteresting(bitmap_git, &base_oid)) {
1514 if (use_delta_islands) {
1513 - struct object_id base_oid;
1514 - hashcpy(base_oid.hash, base_sha1);
1515 if (!in_same_island(&delta->idx.oid, &base_oid))
1516 return 0;
1517 }
pack-bitmap.c
+29 -29
@@ -60,8 +60,8 @@ struct bitmap_index {
60 struct ewah_bitmap *blobs;
61 struct ewah_bitmap *tags;
62
63 - /* Map from SHA1 -> `stored_bitmap` for all the bitmapped commits */
64 - khash_sha1 *bitmaps;
63 + /* Map from object ID -> `stored_bitmap` for all the bitmapped commits */
64 + kh_oid_map_t *bitmaps;
65
66 /* Number of bitmapped commits */
67 uint32_t entry_count;
@@ -80,7 +80,7 @@ struct bitmap_index {
80 struct object **objects;
81 uint32_t *hashes;
82 uint32_t count, alloc;
83 - khash_sha1_pos *positions;
83 + kh_oid_pos_t *positions;
84 } ext_index;
85
86 /* Bitmap result of the last performed walk */
@@ -183,7 +183,7 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
183 stored->flags = flags;
184 oidread(&stored->oid, hash);
185
186 - hash_pos = kh_put_sha1(index->bitmaps, stored->oid.hash, &ret);
186 + hash_pos = kh_put_oid_map(index->bitmaps, stored->oid, &ret);
187
188 /* a 0 return code means the insertion succeeded with no changes,
189 * because the SHA1 already existed on the map. this is bad, there
@@ -306,8 +306,8 @@ static int load_pack_bitmap(struct bitmap_index *bitmap_git)
306 {
307 assert(bitmap_git->map);
308
309 - bitmap_git->bitmaps = kh_init_sha1();
310 - bitmap_git->ext_index.positions = kh_init_sha1_pos();
309 + bitmap_git->bitmaps = kh_init_oid_map();
310 + bitmap_git->ext_index.positions = kh_init_oid_pos();
311 load_pack_revindex(bitmap_git->pack);
312
313 if (!(bitmap_git->commits = read_bitmap_1(bitmap_git)) ||
@@ -362,10 +362,10 @@ struct include_data {
362 };
363
364 static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
365 - const unsigned char *sha1)
365 + const struct object_id *oid)
366 {
367 - khash_sha1_pos *positions = bitmap_git->ext_index.positions;
368 - khiter_t pos = kh_get_sha1_pos(positions, sha1);
367 + khash_oid_pos *positions = bitmap_git->ext_index.positions;
368 + khiter_t pos = kh_get_oid_pos(positions, *oid);
369
370 if (pos < kh_end(positions)) {
371 int bitmap_pos = kh_value(positions, pos);
@@ -376,9 +376,9 @@ static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
376 }
377
378 static inline int bitmap_position_packfile(struct bitmap_index *bitmap_git,
379 - const unsigned char *sha1)
379 + const struct object_id *oid)
380 {
381 - off_t offset = find_pack_entry_one(sha1, bitmap_git->pack);
381 + off_t offset = find_pack_entry_one(oid->hash, bitmap_git->pack);
382 if (!offset)
383 return -1;
384
@@ -386,10 +386,10 @@ static inline int bitmap_position_packfile(struct bitmap_index *bitmap_git,
386 }
387
388 static int bitmap_position(struct bitmap_index *bitmap_git,
389 - const unsigned char *sha1)
389 + const struct object_id *oid)
390 {
391 - int pos = bitmap_position_packfile(bitmap_git, sha1);
392 - return (pos >= 0) ? pos : bitmap_position_extended(bitmap_git, sha1);
391 + int pos = bitmap_position_packfile(bitmap_git, oid);
392 + return (pos >= 0) ? pos : bitmap_position_extended(bitmap_git, oid);
393 }
394
395 static int ext_index_add_object(struct bitmap_index *bitmap_git,
@@ -401,7 +401,7 @@ static int ext_index_add_object(struct bitmap_index *bitmap_git,
401 int hash_ret;
402 int bitmap_pos;
403
404 - hash_pos = kh_put_sha1_pos(eindex->positions, object->oid.hash, &hash_ret);
404 + hash_pos = kh_put_oid_pos(eindex->positions, object->oid, &hash_ret);
405 if (hash_ret > 0) {
406 if (eindex->count >= eindex->alloc) {
407 eindex->alloc = (eindex->alloc + 16) * 3 / 2;
@@ -431,7 +431,7 @@ static void show_object(struct object *object, const char *name, void *data_)
431 struct bitmap_show_data *data = data_;
432 int bitmap_pos;
433
434 - bitmap_pos = bitmap_position(data->bitmap_git, object->oid.hash);
434 + bitmap_pos = bitmap_position(data->bitmap_git, &object->oid);
435
436 if (bitmap_pos < 0)
437 bitmap_pos = ext_index_add_object(data->bitmap_git, object,
@@ -446,7 +446,7 @@ static void show_commit(struct commit *commit, void *data)
446
447 static int add_to_include_set(struct bitmap_index *bitmap_git,
448 struct include_data *data,
449 - const unsigned char *sha1,
449 + const struct object_id *oid,
450 int bitmap_pos)
451 {
452 khiter_t hash_pos;
@@ -457,7 +457,7 @@ static int add_to_include_set(struct bitmap_index *bitmap_git,
457 if (bitmap_get(data->base, bitmap_pos))
458 return 0;
459
460 - hash_pos = kh_get_sha1(bitmap_git->bitmaps, sha1);
460 + hash_pos = kh_get_oid_map(bitmap_git->bitmaps, *oid);
461 if (hash_pos < kh_end(bitmap_git->bitmaps)) {
462 struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, hash_pos);
463 bitmap_or_ewah(data->base, lookup_stored_bitmap(st));
@@ -473,13 +473,13 @@ static int should_include(struct commit *commit, void *_data)
473 struct include_data *data = _data;
474 int bitmap_pos;
475
476 - bitmap_pos = bitmap_position(data->bitmap_git, commit->object.oid.hash);
476 + bitmap_pos = bitmap_position(data->bitmap_git, &commit->object.oid);
477 if (bitmap_pos < 0)
478 bitmap_pos = ext_index_add_object(data->bitmap_git,
479 (struct object *)commit,
480 NULL);
481
482 - if (!add_to_include_set(data->bitmap_git, data, commit->object.oid.hash,
482 + if (!add_to_include_set(data->bitmap_git, data, &commit->object.oid,
483 bitmap_pos)) {
484 struct commit_list *parent = commit->parents;
485
@@ -517,7 +517,7 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
517 roots = roots->next;
518
519 if (object->type == OBJ_COMMIT) {
520 - khiter_t pos = kh_get_sha1(bitmap_git->bitmaps, object->oid.hash);
520 + khiter_t pos = kh_get_oid_map(bitmap_git->bitmaps, object->oid);
521
522 if (pos < kh_end(bitmap_git->bitmaps)) {
523 struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
@@ -559,7 +559,7 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
559 int pos;
560
561 roots = roots->next;
562 - pos = bitmap_position(bitmap_git, object->oid.hash);
562 + pos = bitmap_position(bitmap_git, &object->oid);
563
564 if (pos < 0 || base == NULL || !bitmap_get(base, pos)) {
565 object->flags &= ~UNINTERESTING;
@@ -925,7 +925,7 @@ static void test_show_object(struct object *object, const char *name,
925 struct bitmap_test_data *tdata = data;
926 int bitmap_pos;
927
928 - bitmap_pos = bitmap_position(tdata->bitmap_git, object->oid.hash);
928 + bitmap_pos = bitmap_position(tdata->bitmap_git, &object->oid);
929 if (bitmap_pos < 0)
930 die("Object not in bitmap: %s\n", oid_to_hex(&object->oid));
931
@@ -939,7 +939,7 @@ static void test_show_commit(struct commit *commit, void *data)
939 int bitmap_pos;
940
941 bitmap_pos = bitmap_position(tdata->bitmap_git,
942 - commit->object.oid.hash);
942 + &commit->object.oid);
943 if (bitmap_pos < 0)
944 die("Object not in bitmap: %s\n", oid_to_hex(&commit->object.oid));
945
@@ -966,7 +966,7 @@ void test_bitmap_walk(struct rev_info *revs)
966 bitmap_git->version, bitmap_git->entry_count);
967
968 root = revs->pending.objects[0].item;
969 - pos = kh_get_sha1(bitmap_git->bitmaps, root->oid.hash);
969 + pos = kh_get_oid_map(bitmap_git->bitmaps, root->oid);
970
971 if (pos < kh_end(bitmap_git->bitmaps)) {
972 struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
@@ -1108,7 +1108,7 @@ void free_bitmap_index(struct bitmap_index *b)
1108 ewah_pool_free(b->trees);
1109 ewah_pool_free(b->blobs);
1110 ewah_pool_free(b->tags);
1111 - kh_destroy_sha1(b->bitmaps);
1111 + kh_destroy_oid_map(b->bitmaps);
1112 free(b->ext_index.objects);
1113 free(b->ext_index.hashes);
1114 bitmap_free(b->result);
@@ -1116,8 +1116,8 @@ void free_bitmap_index(struct bitmap_index *b)
1116 free(b);
1117 }
1118
1119 -int bitmap_has_sha1_in_uninteresting(struct bitmap_index *bitmap_git,
1120 - const unsigned char *sha1)
1119 +int bitmap_has_oid_in_uninteresting(struct bitmap_index *bitmap_git,
1120 + const struct object_id *oid)
1121 {
1122 int pos;
1123
@@ -1126,7 +1126,7 @@ int bitmap_has_sha1_in_uninteresting(struct bitmap_index *bitmap_git,
1126 if (!bitmap_git->haves)
1127 return 0; /* walk had no "haves" */
1128
1129 - pos = bitmap_position_packfile(bitmap_git, sha1);
1129 + pos = bitmap_position_packfile(bitmap_git, oid);
1130 if (pos < 0)
1131 return 0;
1132
pack-bitmap.h
+1 -1
@@ -59,7 +59,7 @@ void free_bitmap_index(struct bitmap_index *);
59 * queried to see if a particular object was reachable from any of the
60 * objects flagged as UNINTERESTING.
61 */
62 -int bitmap_has_sha1_in_uninteresting(struct bitmap_index *, const unsigned char *sha1);
62 +int bitmap_has_oid_in_uninteresting(struct bitmap_index *, const struct object_id *oid);
63
64 void bitmap_writer_show_progress(int show);
65 void bitmap_writer_set_checksum(unsigned char *sha1);