diff mbox series

[08/19] midx: teach `bsearch_midx()` about incremental MIDXs

Message ID f3c37c83696deb03ad06c59df393e9b66a72ddab.1717715060.git.me@ttaylorr.com (mailing list archive)
State Accepted
Commit 88f309e095d084d730f908fe1ec01a92c63612c2
Headers show
Series midx: incremental multi-pack indexes, part one | expand

Commit Message

Taylor Blau June 6, 2024, 11:04 p.m. UTC
Now that the special cases callers of `bsearch_midx()` have been dealt
with, teach `bsearch_midx()` to handle incremental MIDX chains.

The incremental MIDX-aware version of `bsearch_midx()` works by
repeatedly searching for a given OID in each layer along the
`->base_midx` pointer, stopping either when an exact match is found, or
the end of the chain is reached.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 midx.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/midx.c b/midx.c
index 1b4a9d5d00..7c4f58f7f1 100644
--- a/midx.c
+++ b/midx.c
@@ -341,7 +341,10 @@  int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,
 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m,
 		 uint32_t *result)
 {
-		return bsearch_one_midx(oid, m, result);
+	for (; m; m = m->base_midx)
+		if (bsearch_one_midx(oid, m, result))
+			return 1;
+	return 0;
 }
 
 struct object_id *nth_midxed_object_oid(struct object_id *oid,