diff mbox series

[v3,05/19] midx: teach `nth_midxed_object_oid()` about incremental MIDXs

Message ID e68a3ceff9a3dc3d9c2504ed13217cac150c3640.1722958596.git.me@ttaylorr.com (mailing list archive)
State Accepted
Commit 26afb5afa16c9ea7825fdeae05e31d619849ad4b
Headers show
Series midx: incremental multi-pack indexes, part one | expand

Commit Message

Taylor Blau Aug. 6, 2024, 3:37 p.m. UTC
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>
---
 midx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/midx.c b/midx.c
index 07b3981a7a..64a051cca1 100644
--- 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;