]> git.ipfire.org Git - thirdparty/git.git/commitdiff
midx: teach `nth_midxed_object_oid()` about incremental MIDXs
authorTaylor Blau <me@ttaylorr.com>
Tue, 6 Aug 2024 15:37:24 +0000 (11:37 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Aug 2024 19:01:36 +0000 (12:01 -0700)
The function `nth_midxed_object_oid()` returns the object ID for a given
object position in the MIDX lexicographic order.

Teach this function to instead operate over the concatenated
lexicographic order defined in an earlier step so that it is able to be
used with incremental MIDXs.

To do this, we need to both (a) adjust the bounds check for the given
'n', as well as record the MIDX-local position after chasing the
`->base_midx` pointer to find the MIDX which contains that object.

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 07b3981a7a05845f93969af3d0021d80a9f32690..64a051cca1318b43e847c21a10aea57d72a161e0 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -338,9 +338,11 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
                                        struct multi_pack_index *m,
                                        uint32_t n)
 {
-       if (n >= m->num_objects)
+       if (n >= m->num_objects + m->num_objects_in_base)
                return NULL;
 
+       n = midx_for_object(&m, n);
+
        oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
                the_repository->hash_algo);
        return oid;