aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/gc.c
diff options
context:
space:
mode:
authorZheNing Hu <adlternative@gmail.com>2025-01-24 07:49:14 +0000
committerJunio C Hamano <gitster@pobox.com>2025-01-24 14:32:28 -0800
commit08032fa30fefa3101bec4b774e79f4d091b516a6 (patch)
tree6f65295cbde9d938e56d8ad94568dcb3becf18be /builtin/gc.c
parent92999a42db1c5f43f330e4f2bca4026b5b81576f (diff)
downloadgit-08032fa30fefa3101bec4b774e79f4d091b516a6.tar.gz
gc: add `--expire-to` option
This commit extends the functionality of `git gc` by adding a new option, `--expire-to=<dir>`. Previously, this feature was implemented in 91badeba32 (builtin/repack.c: implement `--expire-to` for storing pruned objects, 2022-10-24), which allowing users to specify a directory where unreachable and expired cruft packs are stored during garbage collection. However, users had to run `git repack --cruft --expire-to=<dir>` followed by `git prune` to achieve similar results within `git gc`. By introducing `--expire-to=<dir>` directly into `git gc`, we simplify the process for users who wish to manage their repository's cleanup more efficiently. This change involves passing the `--expire-to=<dir>` parameter through to `git repack`, making it easier for users to set up a backup location for cruft packs that will be pruned. Due to the original `git gc --prune=now` deleting all unreachable objects by passing the `-a` parameter to git repack. With the addition of the `--cruft` and `--expire-to` options, it is necessary to modify this default behavior: instead of deleting these unreachable objects, they should be merged into a cruft pack and collected in a specified directory. Therefore, we do not pass `-a` to the repack command but instead pass `--cruft`, `--expire-to`, and `--cruft-expiration=now` to repack. Signed-off-by: ZheNing Hu <adlternative@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/gc.c')
-rw-r--r--builtin/gc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index d52735354c..8656e1caff 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -136,6 +136,7 @@ struct gc_config {
char *prune_worktrees_expire;
char *repack_filter;
char *repack_filter_to;
+ char *repack_expire_to;
unsigned long big_pack_threshold;
unsigned long max_delta_cache_size;
};
@@ -432,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");
@@ -441,6 +443,8 @@ static void add_repack_all_option(struct gc_config *cfg,
if (cfg->max_cruft_size)
strvec_pushf(&repack, "--max-cruft-size=%lu",
cfg->max_cruft_size);
+ if (cfg->repack_expire_to)
+ strvec_pushf(&repack, "--expire-to=%s", cfg->repack_expire_to);
} else {
strvec_push(&repack, "-A");
if (cfg->prune_expire)
@@ -675,7 +679,6 @@ struct repository *repo UNUSED)
const char *prune_expire_sentinel = "sentinel";
const char *prune_expire_arg = prune_expire_sentinel;
int ret;
-
struct option builtin_gc_options[] = {
OPT__QUIET(&quiet, N_("suppress progress reporting")),
{ OPTION_STRING, 0, "prune", &prune_expire_arg, N_("date"),
@@ -694,6 +697,8 @@ struct repository *repo UNUSED)
PARSE_OPT_NOCOMPLETE),
OPT_BOOL(0, "keep-largest-pack", &keep_largest_pack,
N_("repack all other packs except the largest pack")),
+ OPT_STRING(0, "expire-to", &cfg.repack_expire_to, N_("dir"),
+ N_("pack prefix to store a pack containing pruned objects")),
OPT_END()
};