Skip to content

Commit bdf56de

Browse files
novalisgitster
authored andcommitted
auto gc: don't write bitmaps for incremental repacks
When git gc --auto does an incremental repack of loose objects, we do not expect to be able to write a bitmap; it is very likely that objects in the new pack will have references to objects outside of the pack. So we shouldn't try to write a bitmap, because doing so will likely issue a warning. This warning was making its way into gc.log. When the gc.log was present, future auto gc runs would refuse to run. Patch by Jeff King. Bug report, test, and commit message by David Turner. Signed-off-by: David Turner <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c3808ca commit bdf56de

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
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))

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)