diff options
author | Taylor Blau <me@ttaylorr.com> | 2022-10-17 22:45:12 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-10-17 21:26:16 -0700 |
commit | 55d902cd61a8fd2e9b9aa4bf49b47e4dbf10ea67 (patch) | |
tree | 00cf2b80e37119273c4c75e4e76eba1d10147287 /builtin/repack.c | |
parent | 3dcec76d9df911ed8321007b1d197c1a206dc164 (diff) | |
download | git-55d902cd61a8fd2e9b9aa4bf49b47e4dbf10ea67.tar.gz |
builtin/repack.c: remove redundant pack-based bitmaps
When we write a MIDX bitmap after repacking, it is possible that the
repository would be left in a state with both pack- and multi-pack
reachability bitmaps.
This can occur, for instance, if a pack that was kept (either by having
a .keep file, or during a geometric repack in which it is not rolled up)
has a bitmap file, and the repack wrote a multi-pack index and bitmap.
When loading a reachability bitmap for the repository, the multi-pack
one is always preferred, so the pack-based one is redundant. Let's
remove it unconditionally, even if '-d' isn't passed, since there is no
practical reason to keep both around. The patch below does just that.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/repack.c')
-rw-r--r-- | builtin/repack.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/builtin/repack.c b/builtin/repack.c index a5bacc7797..c2d2e52bd4 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -661,6 +661,35 @@ static int write_midx_included_packs(struct string_list *include, return finish_command(&cmd); } +static void remove_redundant_bitmaps(struct string_list *include, + const char *packdir) +{ + struct strbuf path = STRBUF_INIT; + struct string_list_item *item; + size_t packdir_len; + + strbuf_addstr(&path, packdir); + strbuf_addch(&path, '/'); + packdir_len = path.len; + + /* + * Remove any pack bitmaps corresponding to packs which are now + * included in the MIDX. + */ + for_each_string_list_item(item, include) { + strbuf_addstr(&path, item->string); + strbuf_strip_suffix(&path, ".idx"); + strbuf_addstr(&path, ".bitmap"); + + if (unlink(path.buf) && errno != ENOENT) + warning_errno(_("could not remove stale bitmap: %s"), + path.buf); + + strbuf_setlen(&path, packdir_len); + } + strbuf_release(&path); +} + static int write_cruft_pack(const struct pack_objects_args *args, const char *pack_prefix, struct string_list *names, @@ -1059,6 +1088,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix) refs_snapshot ? get_tempfile_path(refs_snapshot) : NULL, show_progress, write_bitmaps > 0); + if (!ret && write_bitmaps) + remove_redundant_bitmaps(&include, packdir); + string_list_clear(&include, 0); if (ret) |