Skip to content

Commit c5dd777

Browse files
committed
Merge branch 'tb/remove-unused-pack-bitmap'
When creating a multi-pack bitmap, remove per-pack bitmap files unconditionally as they will never be consulted. * tb/remove-unused-pack-bitmap: builtin/repack.c: remove redundant pack-based bitmaps
2 parents 7b9b634 + 55d902c commit c5dd777

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

builtin/repack.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,35 @@ static int write_midx_included_packs(struct string_list *include,
661661
return finish_command(&cmd);
662662
}
663663

664+
static void remove_redundant_bitmaps(struct string_list *include,
665+
const char *packdir)
666+
{
667+
struct strbuf path = STRBUF_INIT;
668+
struct string_list_item *item;
669+
size_t packdir_len;
670+
671+
strbuf_addstr(&path, packdir);
672+
strbuf_addch(&path, '/');
673+
packdir_len = path.len;
674+
675+
/*
676+
* Remove any pack bitmaps corresponding to packs which are now
677+
* included in the MIDX.
678+
*/
679+
for_each_string_list_item(item, include) {
680+
strbuf_addstr(&path, item->string);
681+
strbuf_strip_suffix(&path, ".idx");
682+
strbuf_addstr(&path, ".bitmap");
683+
684+
if (unlink(path.buf) && errno != ENOENT)
685+
warning_errno(_("could not remove stale bitmap: %s"),
686+
path.buf);
687+
688+
strbuf_setlen(&path, packdir_len);
689+
}
690+
strbuf_release(&path);
691+
}
692+
664693
static int write_cruft_pack(const struct pack_objects_args *args,
665694
const char *pack_prefix,
666695
struct string_list *names,
@@ -1059,6 +1088,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
10591088
refs_snapshot ? get_tempfile_path(refs_snapshot) : NULL,
10601089
show_progress, write_bitmaps > 0);
10611090

1091+
if (!ret && write_bitmaps)
1092+
remove_redundant_bitmaps(&include, packdir);
1093+
10621094
string_list_clear(&include, 0);
10631095

10641096
if (ret)

t/t7700-repack.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,27 @@ test_expect_success '--write-midx -b packs non-kept objects' '
426426
)
427427
'
428428

429+
test_expect_success '--write-midx removes stale pack-based bitmaps' '
430+
rm -fr repo &&
431+
git init repo &&
432+
test_when_finished "rm -fr repo" &&
433+
(
434+
cd repo &&
435+
test_commit base &&
436+
GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ab &&
437+
438+
pack_bitmap=$(ls $objdir/pack/pack-*.bitmap) &&
439+
test_path_is_file "$pack_bitmap" &&
440+
441+
test_commit tip &&
442+
GIT_TEST_MULTI_PACK_INDEX=0 git repack -bm &&
443+
444+
test_path_is_file $midx &&
445+
test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
446+
test_path_is_missing $pack_bitmap
447+
)
448+
'
449+
429450
test_expect_success '--write-midx with --pack-kept-objects' '
430451
git init repo &&
431452
test_when_finished "rm -fr repo" &&

0 commit comments

Comments
 (0)