Skip to content

Commit b3bab9d

Browse files
pks-tgitster
authored andcommitted
midx-write: extract function to test whether MIDX needs updating
In `write_midx_internal()` we know to skip writing the new multi-pack index in case it would be the same as the existing one. This logic does not handle the `--stdin-packs` option yet though, so we end up always rewriting the MIDX if that option is passed to us. Extract the logic to decide whether or not to rewrite the MIDX into a separate function. This will allow us to extend that feature in the next commit to address the above issue. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 665d19e commit b3bab9d

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

midx-write.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,41 @@ static void clear_midx_files(struct odb_source *source,
10151015
strbuf_release(&buf);
10161016
}
10171017

1018+
static bool midx_needs_update(struct write_midx_context *ctx)
1019+
{
1020+
struct multi_pack_index *midx = ctx->m;
1021+
bool needed = true;
1022+
1023+
/*
1024+
* Ignore incremental updates for now. The assumption is that any
1025+
* incremental update would be either empty (in which case we will bail
1026+
* out later) or it would actually cover at least one new pack.
1027+
*/
1028+
if (ctx->incremental)
1029+
goto out;
1030+
1031+
/*
1032+
* If there is no MIDX then either it doesn't exist, or we're doing a
1033+
* geometric repack. We cannot (yet) determine whether we need to
1034+
* update the multi-pack index in the second case.
1035+
*/
1036+
if (!midx)
1037+
goto out;
1038+
1039+
/*
1040+
* Otherwise, we need to verify that the packs covered by the existing
1041+
* MIDX match the packs that we already have. This test is somewhat
1042+
* lenient and will be fixed.
1043+
*/
1044+
if (ctx->nr != midx->num_packs + midx->num_packs_in_base)
1045+
goto out;
1046+
1047+
needed = false;
1048+
1049+
out:
1050+
return needed;
1051+
}
1052+
10181053
static int write_midx_internal(struct odb_source *source,
10191054
struct string_list *packs_to_include,
10201055
struct string_list *packs_to_drop,
@@ -1112,9 +1147,7 @@ static int write_midx_internal(struct odb_source *source,
11121147
for_each_file_in_pack_dir(source->path, add_pack_to_midx, &ctx);
11131148
stop_progress(&ctx.progress);
11141149

1115-
if ((ctx.m && ctx.nr == ctx.m->num_packs + ctx.m->num_packs_in_base) &&
1116-
!ctx.incremental &&
1117-
!(packs_to_include || packs_to_drop)) {
1150+
if (!packs_to_include && !packs_to_drop && !midx_needs_update(&ctx)) {
11181151
struct bitmap_index *bitmap_git;
11191152
int bitmap_exists;
11201153
int want_bitmap = flags & MIDX_WRITE_BITMAP;

0 commit comments

Comments
 (0)