Skip to content

Commit b396ee6

Browse files
pks-tgitster
authored andcommitted
run-command: introduce function to prepare auto-maintenance process
The `run_auto_maintenance()` function is responsible for spawning a new `git maintenance run --auto` process. To do so, it sets up the `sturct child_process` and then runs it by executing `run_command()` directly. This is rather inflexible in case callers want to modify the child process somewhat, e.g. to redirect stderr or stdout. Introduce a new `prepare_auto_maintenance()` function to plug this gap. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit b396ee6

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

run-command.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,20 +1793,27 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
17931793
trace2_region_leave(tr2_category, tr2_label, NULL);
17941794
}
17951795

1796-
int run_auto_maintenance(int quiet)
1796+
int prepare_auto_maintenance(int quiet, struct child_process *maint)
17971797
{
17981798
int enabled;
1799-
struct child_process maint = CHILD_PROCESS_INIT;
18001799

18011800
if (!git_config_get_bool("maintenance.auto", &enabled) &&
18021801
!enabled)
18031802
return 0;
18041803

1805-
maint.git_cmd = 1;
1806-
maint.close_object_store = 1;
1807-
strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
1808-
strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
1804+
maint->git_cmd = 1;
1805+
maint->close_object_store = 1;
1806+
strvec_pushl(&maint->args, "maintenance", "run", "--auto", NULL);
1807+
strvec_push(&maint->args, quiet ? "--quiet" : "--no-quiet");
1808+
1809+
return 1;
1810+
}
18091811

1812+
int run_auto_maintenance(int quiet)
1813+
{
1814+
struct child_process maint = CHILD_PROCESS_INIT;
1815+
if (!prepare_auto_maintenance(quiet, &maint))
1816+
return 0;
18101817
return run_command(&maint);
18111818
}
18121819

run-command.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ int finish_command_in_signal(struct child_process *);
217217
*/
218218
int run_command(struct child_process *);
219219

220+
/*
221+
* Prepare a `struct child_process` to run auto-maintenance. Returns 1 if the
222+
* process has been prepared and is ready to run, or 0 in case auto-maintenance
223+
* should be skipped.
224+
*/
225+
int prepare_auto_maintenance(int quiet, struct child_process *maint);
226+
220227
/*
221228
* Trigger an auto-gc
222229
*/

0 commit comments

Comments
 (0)