Skip to content

Commit 3fef24a

Browse files
pks-tgitster
authored andcommitted
builtin/gc: split out function to expire reflog entries
We're about to introduce a new task for git-maintenance(1) that knows to expire reflog entries. The logic will be shared with git-gc(1), which already knows how to do this. Pull out the common logic into a separate function so that we can share the implementation between both builtins. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d20fc19 commit 3fef24a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

builtin/gc.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static const char * const builtin_gc_usage[] = {
5353

5454
static timestamp_t gc_log_expire_time;
5555

56-
static struct strvec reflog = STRVEC_INIT;
5756
static struct strvec repack = STRVEC_INIT;
5857
static struct strvec prune = STRVEC_INIT;
5958
static struct strvec prune_worktrees = STRVEC_INIT;
@@ -286,6 +285,15 @@ static int maintenance_task_pack_refs(struct maintenance_run_opts *opts,
286285
return run_command(&cmd);
287286
}
288287

288+
static int maintenance_task_reflog_expire(struct maintenance_run_opts *opts UNUSED,
289+
struct gc_config *cfg UNUSED)
290+
{
291+
struct child_process cmd = CHILD_PROCESS_INIT;
292+
cmd.git_cmd = 1;
293+
strvec_pushl(&cmd.args, "reflog", "expire", "--all", NULL);
294+
return run_command(&cmd);
295+
}
296+
289297
static int too_many_loose_objects(struct gc_config *cfg)
290298
{
291299
/*
@@ -662,15 +670,8 @@ static void gc_before_repack(struct maintenance_run_opts *opts,
662670

663671
if (cfg->pack_refs && maintenance_task_pack_refs(opts, cfg))
664672
die(FAILED_RUN, "pack-refs");
665-
666-
if (cfg->prune_reflogs) {
667-
struct child_process cmd = CHILD_PROCESS_INIT;
668-
669-
cmd.git_cmd = 1;
670-
strvec_pushv(&cmd.args, reflog.v);
671-
if (run_command(&cmd))
672-
die(FAILED_RUN, reflog.v[0]);
673-
}
673+
if (cfg->prune_reflogs && maintenance_task_reflog_expire(opts, cfg))
674+
die(FAILED_RUN, "reflog");
674675
}
675676

676677
int cmd_gc(int argc,
@@ -718,7 +719,6 @@ struct repository *repo UNUSED)
718719
show_usage_with_options_if_asked(argc, argv,
719720
builtin_gc_usage, builtin_gc_options);
720721

721-
strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
722722
strvec_pushl(&repack, "repack", "-d", "-l", NULL);
723723
strvec_pushl(&prune, "prune", "--expire", NULL);
724724
strvec_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL);

0 commit comments

Comments
 (0)