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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed May 7, 2025 at 09:21 UTC 255251cce179efffe6dd17bc26f2729f6fcfd3bd
1 file changed +11 -5
builtin/gc.c
+11 -5
@@ -384,6 +384,15 @@ out:
384 return should_prune;
385 }
386
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 +
396 static int too_many_loose_objects(struct gc_config *cfg)
397 {
398 /*
@@ -785,7 +794,6 @@ int cmd_gc(int argc,
794 int daemonized = 0;
795 int keep_largest_pack = -1;
796 timestamp_t dummy;
788 - struct child_process rerere_cmd = CHILD_PROCESS_INIT;
797 struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
798 struct gc_config cfg = GC_CONFIG_INIT;
799 const char *prune_expire_sentinel = "sentinel";
@@ -968,10 +976,8 @@ int cmd_gc(int argc,
976 maintenance_task_worktree_prune(&opts, &cfg))
977 die(FAILED_RUN, "worktree");
978
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");
981
982 report_garbage = report_pack_garbage;
983 reprepare_packed_git(the_repository);