Skip to content

Commit ae76c1c

Browse files
pks-tgitster
authored andcommitted
builtin/gc: move pruning of worktrees into a separate function
In a subsequent commit we will introduce a new "worktree-prune" task for git-maintenance(1). To prepare for this, refactor the code that spawns `git worktree prune` into a separate function. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3a69d7 commit ae76c1c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

builtin/gc.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,18 @@ static int maintenance_task_reflog_expire(struct maintenance_run_opts *opts UNUS
333333
return run_command(&cmd);
334334
}
335335

336+
static int maintenance_task_worktree_prune(struct maintenance_run_opts *opts UNUSED,
337+
struct gc_config *cfg)
338+
{
339+
struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
340+
341+
prune_worktrees_cmd.git_cmd = 1;
342+
strvec_pushl(&prune_worktrees_cmd.args, "worktree", "prune", "--expire", NULL);
343+
strvec_push(&prune_worktrees_cmd.args, cfg->prune_worktrees_expire);
344+
345+
return run_command(&prune_worktrees_cmd);
346+
}
347+
336348
static int too_many_loose_objects(struct gc_config *cfg)
337349
{
338350
/*
@@ -913,16 +925,9 @@ int cmd_gc(int argc,
913925
}
914926
}
915927

916-
if (cfg.prune_worktrees_expire) {
917-
struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
918-
919-
prune_worktrees_cmd.git_cmd = 1;
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))
924-
die(FAILED_RUN, prune_worktrees_cmd.args.v[0]);
925-
}
928+
if (cfg.prune_worktrees_expire &&
929+
maintenance_task_worktree_prune(&opts, &cfg))
930+
die(FAILED_RUN, "worktree");
926931

927932
rerere_cmd.git_cmd = 1;
928933
strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);

0 commit comments

Comments
 (0)