Skip to content

Commit 14e94bf

Browse files
committed
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 `git repack` (see 91badeb), 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. Signed-off-by: ZheNing Hu <adlternative@gmail.com>
1 parent 92999a4 commit 14e94bf

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Documentation/git-gc.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ be performed as well.
6969
the `--max-cruft-size` option of linkgit:git-repack[1] for
7070
more.
7171

72+
--expire-to=<dir>::
73+
When packing unreachable objects into a cruft pack, write a cruft
74+
pack containing pruned objects (if any) to the directory `<dir>`.
75+
See the `--expire-to` option of linkgit:git-repack[1] for
76+
more.
77+
7278
--prune=<date>::
7379
Prune loose objects older than date (default is 2 weeks ago,
7480
overridable by the config variable `gc.pruneExpire`).

builtin/gc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct gc_config {
136136
char *prune_worktrees_expire;
137137
char *repack_filter;
138138
char *repack_filter_to;
139+
char *repack_expire_to;
139140
unsigned long big_pack_threshold;
140141
unsigned long max_delta_cache_size;
141142
};
@@ -441,6 +442,8 @@ static void add_repack_all_option(struct gc_config *cfg,
441442
if (cfg->max_cruft_size)
442443
strvec_pushf(&repack, "--max-cruft-size=%lu",
443444
cfg->max_cruft_size);
445+
if (cfg->repack_expire_to)
446+
strvec_pushf(&repack, "--expire-to=%s", cfg->repack_expire_to);
444447
} else {
445448
strvec_push(&repack, "-A");
446449
if (cfg->prune_expire)
@@ -675,7 +678,6 @@ struct repository *repo UNUSED)
675678
const char *prune_expire_sentinel = "sentinel";
676679
const char *prune_expire_arg = prune_expire_sentinel;
677680
int ret;
678-
679681
struct option builtin_gc_options[] = {
680682
OPT__QUIET(&quiet, N_("suppress progress reporting")),
681683
{ OPTION_STRING, 0, "prune", &prune_expire_arg, N_("date"),
@@ -694,6 +696,8 @@ struct repository *repo UNUSED)
694696
PARSE_OPT_NOCOMPLETE),
695697
OPT_BOOL(0, "keep-largest-pack", &keep_largest_pack,
696698
N_("repack all other packs except the largest pack")),
699+
OPT_STRING(0, "expire-to", &cfg.repack_expire_to, N_("dir"),
700+
N_("pack prefix to store a pack containing pruned objects")),
697701
OPT_END()
698702
};
699703

t/t6500-gc.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ test_expect_success 'gc.maxCruftSize sets appropriate repack options' '
339339
test_subcommand $cruft_max_size_opts --max-cruft-size=3145728 <trace2.txt
340340
'
341341

342+
test_expect_success '--expire-to sets appropriate repack options' '
343+
mkdir expired &&
344+
GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --cruft --expire-to=./expired/pack &&
345+
test_subcommand $cruft_max_size_opts --expire-to=./expired/pack <trace2.txt
346+
'
347+
342348
run_and_wait_for_gc () {
343349
# We read stdout from gc for the side effect of waiting until the
344350
# background gc process exits, closing its fd 9. Furthermore, the

0 commit comments

Comments
 (0)