Skip to content

Commit 99e4d08

Browse files
ttaylorrgitster
authored andcommitted
midx.c: avoid adding preferred objects twice
The last commit changes the behavior of midx.c's `get_sorted_objects()` function to handle the case of writing a MIDX bitmap while reusing an existing MIDX and changing the identity of the preferred pack separately. As part of this change, all objects from the (new) preferred pack are added to the fanout table in a separate pass. Since these copies of the objects all have their preferred bits set, any duplicates will be resolved in their favor. Importantly, this includes any copies of those same objects that come from the existing MIDX. We know at the time of adding them that they'll be redundant if their source pack is the (new) preferred one, so we can avoid adding them to the list in this case. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cdf517b commit 99e4d08

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

midx.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ static void midx_fanout_sort(struct midx_fanout *fanout)
595595

596596
static void midx_fanout_add_midx_fanout(struct midx_fanout *fanout,
597597
struct multi_pack_index *m,
598-
uint32_t cur_fanout)
598+
uint32_t cur_fanout,
599+
int preferred_pack)
599600
{
600601
uint32_t start = 0, end;
601602
uint32_t cur_object;
@@ -605,6 +606,15 @@ static void midx_fanout_add_midx_fanout(struct midx_fanout *fanout,
605606
end = ntohl(m->chunk_oid_fanout[cur_fanout]);
606607

607608
for (cur_object = start; cur_object < end; cur_object++) {
609+
if ((preferred_pack > -1) &&
610+
(preferred_pack == nth_midxed_pack_int_id(m, cur_object))) {
611+
/*
612+
* Objects from preferred packs are added
613+
* separately.
614+
*/
615+
continue;
616+
}
617+
608618
midx_fanout_grow(fanout, fanout->nr + 1);
609619
nth_midxed_pack_midx_entry(m,
610620
&fanout->entries[fanout->nr],
@@ -680,7 +690,8 @@ static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
680690
fanout.nr = 0;
681691

682692
if (m)
683-
midx_fanout_add_midx_fanout(&fanout, m, cur_fanout);
693+
midx_fanout_add_midx_fanout(&fanout, m, cur_fanout,
694+
preferred_pack);
684695

685696
for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++) {
686697
int preferred = cur_pack == preferred_pack;

0 commit comments

Comments
 (0)