From 425426961814f915934017470b484f5eb6687d7f Mon Sep 17 00:00:00 2001 From: ZheNing Hu Date: Mon, 30 Dec 2024 19:51:05 +0800 Subject: [PATCH] fix(gc): make --prune=now compatible with --expire-to The original `git gc --prune=now` attempted to delete all unreachable objects. However, after the introduction of `--cruft` and `--expire-to=` in git gc, `--prune=now` can now compress unreachable objects into a cruft pack and store them in the specified instead of deleting them directly. This is beneficial for recovery in case of data corruption during repository GC. Therefore, update the handling logic of `--prune=now` in gc so that `-a` parameter is only passed to the repack command when neither `--cruft` nor `--expire-to` are used. Signed-off-by: ZheNing Hu --- builtin/gc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index 77904694c9f60d..8656e1caff0990 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -433,7 +433,8 @@ static int keep_one_pack(struct string_list_item *item, void *data UNUSED) static void add_repack_all_option(struct gc_config *cfg, struct string_list *keep_pack) { - if (cfg->prune_expire && !strcmp(cfg->prune_expire, "now")) + if (cfg->prune_expire && !strcmp(cfg->prune_expire, "now") + && !(cfg->cruft_packs && cfg->repack_expire_to)) strvec_push(&repack, "-a"); else if (cfg->cruft_packs) { strvec_push(&repack, "--cruft");