builtin/gc: remove global variables where it is trivial to do

We use a couple of global variables to assemble command line arguments for subprocesses we execute in git-gc(1). All of these variables except the one for git-repack(1) are only used in a single place though, so they don't really add anything but confusion. Remove those variables. 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 e3a69d72b1e48b85f9dad8139797a6fe50d4059d
1 file changed +12 -19
builtin/gc.c
+12 -19
@@ -52,15 +52,9 @@ static const char * const builtin_gc_usage[] = {
52 };
53
54 static timestamp_t gc_log_expire_time;
55 -
55 static struct strvec repack = STRVEC_INIT;
57 -static struct strvec prune = STRVEC_INIT;
58 -static struct strvec prune_worktrees = STRVEC_INIT;
59 -static struct strvec rerere = STRVEC_INIT;
60 -
56 static struct tempfile *pidfile;
57 static struct lock_file log_lock;
63 -
58 static struct string_list pack_garbage = STRING_LIST_INIT_DUP;
59
60 static void clean_pack_garbage(void)
@@ -779,9 +773,6 @@ int cmd_gc(int argc,
773 builtin_gc_usage, builtin_gc_options);
774
775 strvec_pushl(&repack, "repack", "-d", "-l", NULL);
782 - strvec_pushl(&prune, "prune", "--expire", NULL);
783 - strvec_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL);
784 - strvec_pushl(&rerere, "rerere", "gc", NULL);
776
777 gc_config(&cfg);
778
@@ -907,34 +898,36 @@ int cmd_gc(int argc,
898 if (cfg.prune_expire) {
899 struct child_process prune_cmd = CHILD_PROCESS_INIT;
900
901 + strvec_pushl(&prune_cmd.args, "prune", "--expire", NULL);
902 /* run `git prune` even if using cruft packs */
911 - strvec_push(&prune, cfg.prune_expire);
903 + strvec_push(&prune_cmd.args, cfg.prune_expire);
904 if (quiet)
913 - strvec_push(&prune, "--no-progress");
905 + strvec_push(&prune_cmd.args, "--no-progress");
906 if (repo_has_promisor_remote(the_repository))
915 - strvec_push(&prune,
907 + strvec_push(&prune_cmd.args,
908 "--exclude-promisor-objects");
909 prune_cmd.git_cmd = 1;
918 - strvec_pushv(&prune_cmd.args, prune.v);
910 +
911 if (run_command(&prune_cmd))
920 - die(FAILED_RUN, prune.v[0]);
912 + die(FAILED_RUN, prune_cmd.args.v[0]);
913 }
914 }
915
916 if (cfg.prune_worktrees_expire) {
917 struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
918
927 - strvec_push(&prune_worktrees, cfg.prune_worktrees_expire);
919 prune_worktrees_cmd.git_cmd = 1;
929 - strvec_pushv(&prune_worktrees_cmd.args, prune_worktrees.v);
920 + strvec_pushl(&prune_worktrees_cmd.args, "worktree", "prune", "--expire", NULL);
921 + strvec_push(&prune_worktrees_cmd.args, cfg.prune_worktrees_expire);
922 +
923 if (run_command(&prune_worktrees_cmd))
931 - die(FAILED_RUN, prune_worktrees.v[0]);
924 + die(FAILED_RUN, prune_worktrees_cmd.args.v[0]);
925 }
926
927 rerere_cmd.git_cmd = 1;
935 - strvec_pushv(&rerere_cmd.args, rerere.v);
928 + strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);
929 if (run_command(&rerere_cmd))
937 - die(FAILED_RUN, rerere.v[0]);
930 + die(FAILED_RUN, rerere_cmd.args.v[0]);
931
932 report_garbage = report_pack_garbage;
933 reprepare_packed_git(the_repository);