mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
665d19ec7b
commit
b3bab9d272
39
midx-write.c
39
midx-write.c
@@ -1015,6 +1015,41 @@ static void clear_midx_files(struct odb_source *source,
|
||||
strbuf_release(&buf);
|
||||
}
|
||||
|
||||
static bool midx_needs_update(struct write_midx_context *ctx)
|
||||
{
|
||||
struct multi_pack_index *midx = ctx->m;
|
||||
bool needed = true;
|
||||
|
||||
/*
|
||||
* Ignore incremental updates for now. The assumption is that any
|
||||
* incremental update would be either empty (in which case we will bail
|
||||
* out later) or it would actually cover at least one new pack.
|
||||
*/
|
||||
if (ctx->incremental)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* If there is no MIDX then either it doesn't exist, or we're doing a
|
||||
* geometric repack. We cannot (yet) determine whether we need to
|
||||
* update the multi-pack index in the second case.
|
||||
*/
|
||||
if (!midx)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Otherwise, we need to verify that the packs covered by the existing
|
||||
* MIDX match the packs that we already have. This test is somewhat
|
||||
* lenient and will be fixed.
|
||||
*/
|
||||
if (ctx->nr != midx->num_packs + midx->num_packs_in_base)
|
||||
goto out;
|
||||
|
||||
needed = false;
|
||||
|
||||
out:
|
||||
return needed;
|
||||
}
|
||||
|
||||
static int write_midx_internal(struct odb_source *source,
|
||||
struct string_list *packs_to_include,
|
||||
struct string_list *packs_to_drop,
|
||||
@@ -1112,9 +1147,7 @@ static int write_midx_internal(struct odb_source *source,
|
||||
for_each_file_in_pack_dir(source->path, add_pack_to_midx, &ctx);
|
||||
stop_progress(&ctx.progress);
|
||||
|
||||
if ((ctx.m && ctx.nr == ctx.m->num_packs + ctx.m->num_packs_in_base) &&
|
||||
!ctx.incremental &&
|
||||
!(packs_to_include || packs_to_drop)) {
|
||||
if (!packs_to_include && !packs_to_drop && !midx_needs_update(&ctx)) {
|
||||
struct bitmap_index *bitmap_git;
|
||||
int bitmap_exists;
|
||||
int want_bitmap = flags & MIDX_WRITE_BITMAP;
|
||||
|
||||
Reference in New Issue
Block a user