Skip to content

Commit 8d42299

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff4056b commit 8d42299

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

builtin/repack.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,17 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
228228
get_non_kept_pack_filenames(&existing_packs);
229229

230230
if (existing_packs.nr && delete_redundant) {
231-
if (unpack_unreachable)
231+
if (unpack_unreachable) {
232232
argv_array_pushf(&cmd.args,
233233
"--unpack-unreachable=%s",
234234
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) {
236237
argv_array_push(&cmd.args,
237238
"--unpack-unreachable");
239+
} else {
240+
argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
241+
}
238242
}
239243
} else {
240244
argv_array_push(&cmd.args, "--unpacked");

t/t5312-prune-corruption.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test_expect_success 'put bogus object into pack' '
3838
verbose git cat-file -e $bogus
3939
'
4040

41-
test_expect_failure 'destructive repack keeps packed object' '
41+
test_expect_success 'destructive repack keeps packed object' '
4242
test_might_fail git repack -Ad --unpack-unreachable=now &&
4343
verbose git cat-file -e $bogus &&
4444
test_might_fail git repack -ad &&

0 commit comments

Comments
 (0)