Skip to content

Commit 853165c

Browse files
ttaylorrgitster
authored andcommitted
midx: teach midx_contains_pack() about incremental MIDXs
Now that the `midx_contains_pack()` versus `midx_locate_pack()` debacle has been cleaned up, teach the former about how to operate in an incremental MIDX-aware world in a similar fashion as in previous commits. Instead of using either of the two `midx_for_object()` or `midx_for_pack()` helpers, this function is split into two: one that determines whether a pack is contained in a single MIDX, and another which calls the former in a loop over all MIDXs. This approach does not require that we change any of the implementation in what is now `midx_contains_pack_1()` as it still operates over a single MIDX. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d0ee3f commit 853165c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

midx.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name,
466466
return strcmp(idx_or_pack_name, idx_name);
467467
}
468468

469-
int midx_contains_pack(struct multi_pack_index *m, const char *idx_or_pack_name)
469+
static int midx_contains_pack_1(struct multi_pack_index *m,
470+
const char *idx_or_pack_name)
470471
{
471472
uint32_t first = 0, last = m->num_packs;
472473

@@ -489,6 +490,14 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_or_pack_name)
489490
return 0;
490491
}
491492

493+
int midx_contains_pack(struct multi_pack_index *m, const char *idx_or_pack_name)
494+
{
495+
for (; m; m = m->base_midx)
496+
if (midx_contains_pack_1(m, idx_or_pack_name))
497+
return 1;
498+
return 0;
499+
}
500+
492501
int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id)
493502
{
494503
if (m->preferred_pack_idx == -1) {

0 commit comments

Comments
 (0)