Skip to content

Commit e3a69d7

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 58f6283 commit e3a69d7

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

builtin/gc.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ static const char * const builtin_gc_usage[] = {
5252
};
5353

5454
static timestamp_t gc_log_expire_time;
55-
5655
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-
6156
static struct tempfile *pidfile;
6257
static struct lock_file log_lock;
63-
6458
static struct string_list pack_garbage = STRING_LIST_INIT_DUP;
6559

6660
static void clean_pack_garbage(void)
@@ -779,9 +773,6 @@ int cmd_gc(int argc,
779773
builtin_gc_usage, builtin_gc_options);
780774

781775
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);
785776

786777
gc_config(&cfg);
787778

@@ -907,34 +898,36 @@ int cmd_gc(int argc,
907898
if (cfg.prune_expire) {
908899
struct child_process prune_cmd = CHILD_PROCESS_INIT;
909900

901+
strvec_pushl(&prune_cmd.args, "prune", "--expire", NULL);
910902
/* run `git prune` even if using cruft packs */
911-
strvec_push(&prune, cfg.prune_expire);
903+
strvec_push(&prune_cmd.args, cfg.prune_expire);
912904
if (quiet)
913-
strvec_push(&prune, "--no-progress");
905+
strvec_push(&prune_cmd.args, "--no-progress");
914906
if (repo_has_promisor_remote(the_repository))
915-
strvec_push(&prune,
907+
strvec_push(&prune_cmd.args,
916908
"--exclude-promisor-objects");
917909
prune_cmd.git_cmd = 1;
918-
strvec_pushv(&prune_cmd.args, prune.v);
910+
919911
if (run_command(&prune_cmd))
920-
die(FAILED_RUN, prune.v[0]);
912+
die(FAILED_RUN, prune_cmd.args.v[0]);
921913
}
922914
}
923915

924916
if (cfg.prune_worktrees_expire) {
925917
struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
926918

927-
strvec_push(&prune_worktrees, cfg.prune_worktrees_expire);
928919
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+
930923
if (run_command(&prune_worktrees_cmd))
931-
die(FAILED_RUN, prune_worktrees.v[0]);
924+
die(FAILED_RUN, prune_worktrees_cmd.args.v[0]);
932925
}
933926

934927
rerere_cmd.git_cmd = 1;
935-
strvec_pushv(&rerere_cmd.args, rerere.v);
928+
strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);
936929
if (run_command(&rerere_cmd))
937-
die(FAILED_RUN, rerere.v[0]);
930+
die(FAILED_RUN, rerere_cmd.args.v[0]);
938931

939932
report_garbage = report_pack_garbage;
940933
reprepare_packed_git(the_repository);

0 commit comments

Comments
 (0)