Skip to content

Commit 255251c

Browse files
pks-tgitster
authored andcommitted
builtin/gc: move rerere garbage collection into separate function
In a subsequent commit we are going to introduce a new "rerere-gc" task for git-maintenance(1). To prepare for this, refactor the code that spawns `git rerere gc` into a separate function. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec31474 commit 255251c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

builtin/gc.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,15 @@ static int worktree_prune_condition(struct gc_config *cfg)
384384
return should_prune;
385385
}
386386

387+
static int maintenance_task_rerere_gc(struct maintenance_run_opts *opts UNUSED,
388+
struct gc_config *cfg UNUSED)
389+
{
390+
struct child_process rerere_cmd = CHILD_PROCESS_INIT;
391+
rerere_cmd.git_cmd = 1;
392+
strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);
393+
return run_command(&rerere_cmd);
394+
}
395+
387396
static int too_many_loose_objects(struct gc_config *cfg)
388397
{
389398
/*
@@ -785,7 +794,6 @@ int cmd_gc(int argc,
785794
int daemonized = 0;
786795
int keep_largest_pack = -1;
787796
timestamp_t dummy;
788-
struct child_process rerere_cmd = CHILD_PROCESS_INIT;
789797
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
790798
struct gc_config cfg = GC_CONFIG_INIT;
791799
const char *prune_expire_sentinel = "sentinel";
@@ -968,10 +976,8 @@ int cmd_gc(int argc,
968976
maintenance_task_worktree_prune(&opts, &cfg))
969977
die(FAILED_RUN, "worktree");
970978

971-
rerere_cmd.git_cmd = 1;
972-
strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);
973-
if (run_command(&rerere_cmd))
974-
die(FAILED_RUN, rerere_cmd.args.v[0]);
979+
if (maintenance_task_rerere_gc(&opts, &cfg))
980+
die(FAILED_RUN, "rerere");
975981

976982
report_garbage = report_pack_garbage;
977983
reprepare_packed_git(the_repository);

0 commit comments

Comments
 (0)