Skip to content

Commit 8103717

Browse files
committed
Merge branch 'dt/disable-bitmap-in-auto-gc' into maint
It is natural that "git gc --auto" may not attempt to pack everything into a single pack, and there is no point in warning when the user has configured the system to use the pack bitmap, leading to disabling further "gc". * dt/disable-bitmap-in-auto-gc: repack: die on incremental + write-bitmap-index auto gc: don't write bitmaps for incremental repacks
2 parents bb7c47a + 1c409a7 commit 8103717

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

builtin/gc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ static void add_repack_all_option(void)
191191
}
192192
}
193193

194+
static void add_repack_incremental_option(void)
195+
{
196+
argv_array_push(&repack, "--no-write-bitmap-index");
197+
}
198+
194199
static int need_to_gc(void)
195200
{
196201
/*
@@ -208,7 +213,9 @@ static int need_to_gc(void)
208213
*/
209214
if (too_many_packs())
210215
add_repack_all_option();
211-
else if (!too_many_loose_objects())
216+
else if (too_many_loose_objects())
217+
add_repack_incremental_option();
218+
else
212219
return 0;
213220

214221
if (run_hook_le(NULL, "pre-auto-gc", NULL))

builtin/repack.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ static const char *const git_repack_usage[] = {
1818
NULL
1919
};
2020

21+
static const char incremental_bitmap_conflict_error[] = N_(
22+
"Incremental repacks are incompatible with bitmap indexes. Use\n"
23+
"--no-write-bitmap-index or disable the pack.writebitmaps configuration."
24+
);
25+
26+
2127
static int repack_config(const char *var, const char *value, void *cb)
2228
{
2329
if (!strcmp(var, "repack.usedeltabaseoffset")) {
@@ -206,6 +212,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
206212
if (pack_kept_objects < 0)
207213
pack_kept_objects = write_bitmaps;
208214

215+
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE))
216+
die(_(incremental_bitmap_conflict_error));
217+
209218
packdir = mkpathdup("%s/pack", get_object_directory());
210219
packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
211220

t/t5310-pack-bitmaps.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,10 @@ test_expect_success 'fetch (partial bitmap)' '
118118
test_cmp expect actual
119119
'
120120

121-
test_expect_success 'incremental repack cannot create bitmaps' '
121+
test_expect_success 'incremental repack fails when bitmaps are requested' '
122122
test_commit more-1 &&
123-
find .git/objects/pack -name "*.bitmap" >expect &&
124-
git repack -d &&
125-
find .git/objects/pack -name "*.bitmap" >actual &&
126-
test_cmp expect actual
123+
test_must_fail git repack -d 2>err &&
124+
test_i18ngrep "Incremental repacks are incompatible with bitmap" err
127125
'
128126

129127
test_expect_success 'incremental repack can disable bitmaps' '

t/t6500-gc.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,29 @@ test_expect_success 'gc is not aborted due to a stale symref' '
4343
)
4444
'
4545

46+
test_expect_success 'auto gc with too many loose objects does not attempt to create bitmaps' '
47+
test_config gc.auto 3 &&
48+
test_config gc.autodetach false &&
49+
test_config pack.writebitmaps true &&
50+
# We need to create two object whose sha1s start with 17
51+
# since this is what git gc counts. As it happens, these
52+
# two blobs will do so.
53+
test_commit 263 &&
54+
test_commit 410 &&
55+
# Our first gc will create a pack; our second will create a second pack
56+
git gc --auto &&
57+
ls .git/objects/pack | sort >existing_packs &&
58+
test_commit 523 &&
59+
test_commit 790 &&
60+
61+
git gc --auto 2>err &&
62+
test_i18ngrep ! "^warning:" err &&
63+
ls .git/objects/pack/ | sort >post_packs &&
64+
comm -1 -3 existing_packs post_packs >new &&
65+
comm -2 -3 existing_packs post_packs >del &&
66+
test_line_count = 0 del && # No packs are deleted
67+
test_line_count = 2 new # There is one new pack and its .idx
68+
'
69+
70+
4671
test_done

0 commit comments

Comments
 (0)