]> git.ipfire.org Git - thirdparty/git.git/commitdiff
midx: teach `nth_bitmapped_pack()` about incremental MIDXs
authorTaylor Blau <me@ttaylorr.com>
Tue, 6 Aug 2024 15:37:27 +0000 (11:37 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Aug 2024 19:01:36 +0000 (12:01 -0700)
In a similar fashion as in previous commits, teach the function
`nth_bitmapped_pack()` about incremental MIDXs by translating the given
`pack_int_id` from the concatenated lexical order to a MIDX-local
lexical position.

When accessing the containing MIDX's array of packs, use the local pack
ID. Likewise, when reading the 'BTMP' chunk, use the MIDX-local offset
when accessing the data within that chunk.

(Note that the both the call to prepare_midx_pack() and the assignment
of bp->pack_int_id both care about the global pack_int_id, so avoid
shadowing the given 'pack_int_id' parameter).

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c

diff --git a/midx.c b/midx.c
index 64a051cca1318b43e847c21a10aea57d72a161e0..25350152f16c40b0f98fdbe636fc365d8f4d61d6 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -311,17 +311,19 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
 int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
                       struct bitmapped_pack *bp, uint32_t pack_int_id)
 {
+       uint32_t local_pack_int_id = midx_for_pack(&m, pack_int_id);
+
        if (!m->chunk_bitmapped_packs)
                return error(_("MIDX does not contain the BTMP chunk"));
 
        if (prepare_midx_pack(r, m, pack_int_id))
                return error(_("could not load bitmapped pack %"PRIu32), pack_int_id);
 
-       bp->p = m->packs[pack_int_id];
+       bp->p = m->packs[local_pack_int_id];
        bp->bitmap_pos = get_be32((char *)m->chunk_bitmapped_packs +
-                                 MIDX_CHUNK_BITMAPPED_PACKS_WIDTH * pack_int_id);
+                                 MIDX_CHUNK_BITMAPPED_PACKS_WIDTH * local_pack_int_id);
        bp->bitmap_nr = get_be32((char *)m->chunk_bitmapped_packs +
-                                MIDX_CHUNK_BITMAPPED_PACKS_WIDTH * pack_int_id +
+                                MIDX_CHUNK_BITMAPPED_PACKS_WIDTH * local_pack_int_id +
                                 sizeof(uint32_t));
        bp->pack_int_id = pack_int_id;