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 <dturner@twosigma.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed Dec 28, 2016 at 17:45 UTC bdf56de896b48d6fe3ad90e92138b5fd6579748d
2 files changed +33 -1
builtin/gc.c
+8 -1
@@ -191,6 +191,11 @@ static void add_repack_all_option(void)
191 }
192 }
193
194 +static void add_repack_incremental_option(void)
195 +{
196 + argv_array_push(&repack, "--no-write-bitmap-index");
197 +}
198 +
199 static int need_to_gc(void)
200 {
201 /*
@@ -208,7 +213,9 @@ static int need_to_gc(void)
213 */
214 if (too_many_packs())
215 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
219 return 0;
220
221 if (run_hook_le(NULL, "pre-auto-gc", NULL))
t/t6500-gc.sh
+25
@@ -43,4 +43,29 @@ test_expect_success 'gc is not aborted due to a stale symref' '
43 )
44 '
45
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 +
71 test_done