pack-objects: convert packlist_find() to use object_id

We take a raw hash pointer, but most of our callers have a "struct object_id" already. Let's switch to taking the full struct, which will let us continue removing uses of raw sha1 buffers. There are two callers that do need special attention: - in rebuild_existing_bitmaps(), we need to switch to nth_packed_object_oid(). This incurs an extra hash copy over pointing straight to the mmap'd sha1, but it shouldn't be measurable compared to the rest of the operation. - in can_reuse_delta() we already spent the effort to copy the sha1 into a "struct object_id", but now we just have to do so a little earlier in the function (we can't easily convert that function's callers because they may be pointing at mmap'd REF_DELTA blocks). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 20, 2019 at 03:41 UTC 3df28caefb2193fb7bbc87a427a620d96d508c8d
5 files changed +17 -16
builtin/pack-objects.c
+10 -9
@@ -606,12 +606,12 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
606 void *cb_data)
607 {
608 struct object_id peeled;
609 - struct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL);
609 + struct object_entry *entry = packlist_find(&to_pack, oid, NULL);
610
611 if (entry)
612 entry->tagged = 1;
613 if (!peel_ref(path, &peeled)) {
614 - entry = packlist_find(&to_pack, peeled.hash, NULL);
614 + entry = packlist_find(&to_pack, &peeled, NULL);
615 if (entry)
616 entry->tagged = 1;
617 }
@@ -996,7 +996,7 @@ static int have_duplicate_entry(const struct object_id *oid,
996 {
997 struct object_entry *entry;
998
999 - entry = packlist_find(&to_pack, oid->hash, index_pos);
999 + entry = packlist_find(&to_pack, oid, index_pos);
1000 if (!entry)
1001 return 0;
1002
@@ -1494,11 +1494,13 @@ static int can_reuse_delta(const unsigned char *base_sha1,
1494 if (!base_sha1)
1495 return 0;
1496
1497 + oidread(&base_oid, base_sha1);
1498 +
1499 /*
1500 * First see if we're already sending the base (or it's explicitly in
1501 * our "excluded" list).
1502 */
1501 - base = packlist_find(&to_pack, base_sha1, NULL);
1503 + base = packlist_find(&to_pack, &base_oid, NULL);
1504 if (base) {
1505 if (!in_same_island(&delta->idx.oid, &base->idx.oid))
1506 return 0;
@@ -1511,7 +1513,6 @@ static int can_reuse_delta(const unsigned char *base_sha1,
1513 * even if it was buried too deep in history to make it into the
1514 * packing list.
1515 */
1514 - oidread(&base_oid, base_sha1);
1516 if (thin && bitmap_has_oid_in_uninteresting(bitmap_git, &base_oid)) {
1517 if (use_delta_islands) {
1518 if (!in_same_island(&delta->idx.oid, &base_oid))
@@ -2571,7 +2572,7 @@ static void add_tag_chain(const struct object_id *oid)
2572 * it was included via bitmaps, we would not have parsed it
2573 * previously).
2574 */
2574 - if (packlist_find(&to_pack, oid->hash, NULL))
2575 + if (packlist_find(&to_pack, oid, NULL))
2576 return;
2577
2578 tag = lookup_tag(the_repository, oid);
@@ -2595,7 +2596,7 @@ static int add_ref_tag(const char *path, const struct object_id *oid, int flag,
2596
2597 if (starts_with(path, "refs/tags/") && /* is a tag? */
2598 !peel_ref(path, &peeled) && /* peelable? */
2598 - packlist_find(&to_pack, peeled.hash, NULL)) /* object packed? */
2599 + packlist_find(&to_pack, &peeled, NULL)) /* object packed? */
2600 add_tag_chain(oid);
2601 return 0;
2602 }
@@ -2795,7 +2796,7 @@ static void show_object(struct object *obj, const char *name, void *data)
2796 for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
2797 depth++;
2798
2798 - ent = packlist_find(&to_pack, obj->oid.hash, NULL);
2799 + ent = packlist_find(&to_pack, &obj->oid, NULL);
2800 if (ent && depth > oe_tree_depth(&to_pack, ent))
2801 oe_set_tree_depth(&to_pack, ent, depth);
2802 }
@@ -3026,7 +3027,7 @@ static void loosen_unused_packed_objects(void)
3027
3028 for (i = 0; i < p->num_objects; i++) {
3029 nth_packed_object_oid(&oid, p, i);
3029 - if (!packlist_find(&to_pack, oid.hash, NULL) &&
3030 + if (!packlist_find(&to_pack, &oid, NULL) &&
3031 !has_sha1_pack_kept_or_nonlocal(&oid) &&
3032 !loosened_object_can_be_discarded(&oid, p->mtime))
3033 if (force_object_loose(&oid, p->mtime))
pack-bitmap-write.c
+1 -1
@@ -144,7 +144,7 @@ static inline void reset_all_seen(void)
144
145 static uint32_t find_object_pos(const struct object_id *oid)
146 {
147 - struct object_entry *entry = packlist_find(writer.to_pack, oid->hash, NULL);
147 + struct object_entry *entry = packlist_find(writer.to_pack, oid, NULL);
148
149 if (!entry) {
150 die("Failed to write bitmap index. Packfile doesn't have full closure "
pack-bitmap.c
+3 -3
@@ -1057,13 +1057,13 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
1057 reposition = xcalloc(num_objects, sizeof(uint32_t));
1058
1059 for (i = 0; i < num_objects; ++i) {
1060 - const unsigned char *sha1;
1060 + struct object_id oid;
1061 struct revindex_entry *entry;
1062 struct object_entry *oe;
1063
1064 entry = &bitmap_git->pack->revindex[i];
1065 - sha1 = nth_packed_object_sha1(bitmap_git->pack, entry->nr);
1066 - oe = packlist_find(mapping, sha1, NULL);
1065 + nth_packed_object_oid(&oid, bitmap_git->pack, entry->nr);
1066 + oe = packlist_find(mapping, &oid, NULL);
1067
1068 if (oe)
1069 reposition[i] = oe_in_pack_pos(mapping, oe) + 1;
pack-objects.c
+2 -2
@@ -68,7 +68,7 @@ static void rehash_objects(struct packing_data *pdata)
68 }
69
70 struct object_entry *packlist_find(struct packing_data *pdata,
71 - const unsigned char *sha1,
71 + const struct object_id *oid,
72 uint32_t *index_pos)
73 {
74 uint32_t i;
@@ -77,7 +77,7 @@ struct object_entry *packlist_find(struct packing_data *pdata,
77 if (!pdata->index_size)
78 return NULL;
79
80 - i = locate_object_entry_hash(pdata, sha1, &found);
80 + i = locate_object_entry_hash(pdata, oid->hash, &found);
81
82 if (index_pos)
83 *index_pos = i;
pack-objects.h
+1 -1
@@ -187,7 +187,7 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
187 uint32_t index_pos);
188
189 struct object_entry *packlist_find(struct packing_data *pdata,
190 - const unsigned char *sha1,
190 + const struct object_id *oid,
191 uint32_t *index_pos);
192
193 static inline uint32_t pack_name_hash(const char *name)