Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gc: add --expire-to option #1843

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Documentation/git-gc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ be performed as well.
the `--max-cruft-size` option of linkgit:git-repack[1] for
more.

--expire-to=<dir>::
When packing unreachable objects into a cruft pack, write a cruft
pack containing pruned objects (if any) to the directory `<dir>`.
See the `--expire-to` option of linkgit:git-repack[1] for
more.

--prune=<date>::
Prune loose objects older than date (default is 2 weeks ago,
overridable by the config variable `gc.pruneExpire`).
Expand Down
6 changes: 5 additions & 1 deletion builtin/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -441,6 +442,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)
Expand Down Expand Up @@ -675,7 +678,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"),
Expand All @@ -694,6 +696,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()
};

Expand Down
6 changes: 6 additions & 0 deletions t/t6500-gc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ test_expect_success 'gc.maxCruftSize sets appropriate repack options' '
test_subcommand $cruft_max_size_opts --max-cruft-size=3145728 <trace2.txt
'

test_expect_success '--expire-to sets appropriate repack options' '
mkdir expired &&
GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --cruft --expire-to=./expired/pack &&
test_subcommand $cruft_max_size_opts --expire-to=./expired/pack <trace2.txt
'

run_and_wait_for_gc () {
# We read stdout from gc for the side effect of waiting until the
# background gc process exits, closing its fd 9. Furthermore, the
Expand Down
Loading