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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Apr 17, 2024 at 08:16 UTC
b396ee6bed7882af3333eb52333f8a34b648437d
2 files changed
+20
-6
run-command.c
+13
-6
@@ -1793,20 +1793,27 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
1793
trace2_region_leave(tr2_category, tr2_label, NULL);
1794
}
1795
1796
-int run_auto_maintenance(int quiet)
1796
+int prepare_auto_maintenance(int quiet, struct child_process *maint)
1797
{
1798
int enabled;
1799
- struct child_process maint = CHILD_PROCESS_INIT;
1799
1800
if (!git_config_get_bool("maintenance.auto", &enabled) &&
1801
!enabled)
1802
return 0;
1803
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
+}
1811
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;
1817
return run_command(&maint);
1818
}
1819
run-command.h
+7
@@ -217,6 +217,13 @@ int finish_command_in_signal(struct child_process *);
217
*/
218
int run_command(struct child_process *);
219
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
+
227
/*
228
* Trigger an auto-gc
229
*/