git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] fix(gc): make --prune=now compatible with --expire-to

From
ZheNing Hu via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 31, 2024, 02:18 UTC
Message-ID
<579757957d21faaa8dd9228a191d82f663e93c03.1735611513.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1843.v2.git.1735611513.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>

The original `git gc --prune=now` attempted to delete all unreachable objects. However, after the introduction of `--cruft` and `--expire-to=<dir>` in git gc, `--prune=now` can now compress unreachable objects into a cruft pack and store them in the specified <dir> 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 <adlternative@gmail.com>
---
 builtin/gc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/gc.c b/builtin/gc.c
index 77904694c9f..8656e1caff0 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");
-- 
gitgitgadget
Previous: ZheNing HuNext: Jeff King
Message 6 of 13 in “gc: add `--expire-to` option”
  1. gc: add `--expire-to` optionZheNing Hu via GitGitGadget, Dec 24, 2024
  2. 0/2 gc: add --expire-to optionZheNing Hu via GitGitGadget, Dec 31, 2024
  3. 1/2 gc: add `--expire-to` optionZheNing Hu via GitGitGadget, Dec 31, 2024
  4. ZheNing HuJan 3, 2025
  5. ZheNing HuJan 13, 2025
  6. 2/2 fix(gc): make --prune=now compatible with --expire-toZheNing Hu via GitGitGadget, Dec 31, 2024
  7. Jeff KingJan 13, 2025
  8. ZheNing HuJan 15, 2025
  9. gc: add `--expire-to` optionZheNing Hu via GitGitGadget, Jan 16, 2025
  10. Junio C HamanoJan 16, 2025
  11. ZheNing HuJan 23, 2025
  12. gc: add `--expire-to` optionZheNing Hu via GitGitGadget, Jan 24, 2025
  13. Junio C HamanoFeb 4, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.