Skip to content

Commit 5b9d01b

Browse files
committed
Merge branch 'zh/gc-expire-to'
"git gc" learned the "--expire-to" option and passes it down to underlying "git repack". * zh/gc-expire-to: gc: add `--expire-to` option
2 parents a4af0b6 + 08032fa commit 5b9d01b

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

Documentation/git-gc.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ 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+
This option only has an effect when used together with `--cruft`.
76+
See the `--expire-to` option of linkgit:git-repack[1] for
77+
more information.
78+
7279
--prune=<date>::
7380
Prune loose objects older than date (default is 2 weeks ago,
7481
overridable by the config variable `gc.pruneExpire`).

builtin/gc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct gc_config {
139139
char *prune_worktrees_expire;
140140
char *repack_filter;
141141
char *repack_filter_to;
142+
char *repack_expire_to;
142143
unsigned long big_pack_threshold;
143144
unsigned long max_delta_cache_size;
144145
/*
@@ -445,7 +446,8 @@ static int keep_one_pack(struct string_list_item *item, void *data UNUSED)
445446
static void add_repack_all_option(struct gc_config *cfg,
446447
struct string_list *keep_pack)
447448
{
448-
if (cfg->prune_expire && !strcmp(cfg->prune_expire, "now"))
449+
if (cfg->prune_expire && !strcmp(cfg->prune_expire, "now")
450+
&& !(cfg->cruft_packs && cfg->repack_expire_to))
449451
strvec_push(&repack, "-a");
450452
else if (cfg->cruft_packs) {
451453
strvec_push(&repack, "--cruft");
@@ -454,6 +456,8 @@ static void add_repack_all_option(struct gc_config *cfg,
454456
if (cfg->max_cruft_size)
455457
strvec_pushf(&repack, "--max-cruft-size=%lu",
456458
cfg->max_cruft_size);
459+
if (cfg->repack_expire_to)
460+
strvec_pushf(&repack, "--expire-to=%s", cfg->repack_expire_to);
457461
} else {
458462
strvec_push(&repack, "-A");
459463
if (cfg->prune_expire)
@@ -688,7 +692,6 @@ struct repository *repo UNUSED)
688692
const char *prune_expire_sentinel = "sentinel";
689693
const char *prune_expire_arg = prune_expire_sentinel;
690694
int ret;
691-
692695
struct option builtin_gc_options[] = {
693696
OPT__QUIET(&quiet, N_("suppress progress reporting")),
694697
{ OPTION_STRING, 0, "prune", &prune_expire_arg, N_("date"),
@@ -707,6 +710,8 @@ struct repository *repo UNUSED)
707710
PARSE_OPT_NOCOMPLETE),
708711
OPT_BOOL(0, "keep-largest-pack", &keep_largest_pack,
709712
N_("repack all other packs except the largest pack")),
713+
OPT_STRING(0, "expire-to", &cfg.repack_expire_to, N_("dir"),
714+
N_("pack prefix to store a pack containing pruned objects")),
710715
OPT_END()
711716
};
712717

t/t6500-gc.sh

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

341+
test_expect_success '--expire-to sets repack --expire-to' '
342+
rm -rf expired &&
343+
mkdir expired &&
344+
expire_to="$(pwd)/expired/pack" &&
345+
GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --cruft --expire-to="$expire_to" &&
346+
test_subcommand $cruft_max_size_opts --expire-to="$expire_to" <trace2.txt
347+
'
348+
349+
test_expect_success '--expire-to with --prune=now sets repack --expire-to' '
350+
rm -rf expired &&
351+
mkdir expired &&
352+
expire_to="$(pwd)/expired/pack" &&
353+
GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --cruft --prune=now --expire-to="$expire_to" &&
354+
test_subcommand git repack -d -l --cruft --cruft-expiration=now --expire-to="$expire_to" <trace2.txt
355+
'
356+
357+
358+
test_expect_success '--expire-to with --no-cruft sets repack -A' '
359+
rm -rf expired &&
360+
mkdir expired &&
361+
expire_to="$(pwd)/expired/pack" &&
362+
GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --no-cruft --expire-to="$expire_to" &&
363+
test_subcommand git repack -d -l -A --unpack-unreachable=2.weeks.ago <trace2.txt
364+
'
365+
366+
test_expect_success '--expire-to with --no-cruft sets repack -a' '
367+
rm -rf expired &&
368+
mkdir expired &&
369+
expire_to="$(pwd)/expired/pack" &&
370+
GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --no-cruft --prune=now --expire-to="$expire_to" &&
371+
test_subcommand git repack -d -l -a <trace2.txt
372+
'
373+
341374
run_and_wait_for_gc () {
342375
# We read stdout from gc for the side effect of waiting until the
343376
# background gc process exits, closing its fd 9. Furthermore, the

0 commit comments

Comments
 (0)