repack: turn on "ref paranoia" when doing a destructive repack

If we are repacking with "-ad", we will drop any unreachable objects. Likewise, using "-Ad --unpack-unreachable=<time>" will drop any old, unreachable objects. In these cases, we want to make sure the reachability we compute with "--all" is complete. We can do this by passing GIT_REF_PARANOIA=1 in the environment to pack-objects. Note that "-Ad" is safe already, because it only loosens unreachable objects. It is up to "git prune" to avoid deleting them. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 20, 2015 at 14:43 UTC 8d422993617be42a48a54fd7325d5ba5350c1082
2 files changed +7 -3
builtin/repack.c
+6 -2
@@ -228,13 +228,17 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
228 get_non_kept_pack_filenames(&existing_packs);
229
230 if (existing_packs.nr && delete_redundant) {
231 - if (unpack_unreachable)
231 + if (unpack_unreachable) {
232 argv_array_pushf(&cmd.args,
233 "--unpack-unreachable=%s",
234 unpack_unreachable);
235 - else if (pack_everything & LOOSEN_UNREACHABLE)
235 + argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
236 + } else if (pack_everything & LOOSEN_UNREACHABLE) {
237 argv_array_push(&cmd.args,
238 "--unpack-unreachable");
239 + } else {
240 + argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
241 + }
242 }
243 } else {
244 argv_array_push(&cmd.args, "--unpacked");
t/t5312-prune-corruption.sh
+1 -1
@@ -38,7 +38,7 @@ test_expect_success 'put bogus object into pack' '
38 verbose git cat-file -e $bogus
39 '
40
41 -test_expect_failure 'destructive repack keeps packed object' '
41 +test_expect_success 'destructive repack keeps packed object' '
42 test_might_fail git repack -Ad --unpack-unreachable=now &&
43 verbose git cat-file -e $bogus &&
44 test_might_fail git repack -ad &&