pack-bitmap.c: introduce 'nth_bitmap_object_oid()'

A subsequent patch to support reading MIDX bitmaps will be less noisy after extracting a generic function to fetch the nth OID contained in the bitmap. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Aug 31, 2021 at 16:52 UTC 6b4277e697a45db1fb266da1c9df6641aecc4902
1 file changed +10 -3
pack-bitmap.c
+10 -3
@@ -223,6 +223,13 @@ static inline uint8_t read_u8(const unsigned char *buffer, size_t *pos)
223
224 #define MAX_XOR_OFFSET 160
225
226 +static int nth_bitmap_object_oid(struct bitmap_index *index,
227 + struct object_id *oid,
228 + uint32_t n)
229 +{
230 + return nth_packed_object_id(oid, index->pack, n);
231 +}
232 +
233 static int load_bitmap_entries_v1(struct bitmap_index *index)
234 {
235 uint32_t i;
@@ -242,7 +249,7 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
249 xor_offset = read_u8(index->map, &index->map_pos);
250 flags = read_u8(index->map, &index->map_pos);
251
245 - if (nth_packed_object_id(&oid, index->pack, commit_idx_pos) < 0)
252 + if (nth_bitmap_object_oid(index, &oid, commit_idx_pos) < 0)
253 return error("corrupt ewah bitmap: commit index %u out of range",
254 (unsigned)commit_idx_pos);
255
@@ -868,8 +875,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
875 off_t ofs = pack_pos_to_offset(pack, pos);
876 if (packed_object_info(the_repository, pack, ofs, &oi) < 0) {
877 struct object_id oid;
871 - nth_packed_object_id(&oid, pack,
872 - pack_pos_to_index(pack, pos));
878 + nth_bitmap_object_oid(bitmap_git, &oid,
879 + pack_pos_to_index(pack, pos));
880 die(_("unable to get size of %s"), oid_to_hex(&oid));
881 }
882 } else {