aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-04-17 08:16:31 +0200
committerJunio C Hamano <gitster@pobox.com>2024-04-17 08:42:26 -0700
commitb396ee6bed7882af3333eb52333f8a34b648437d (patch)
tree800f4cb7cb9b676d7c6a1d9b65de17d3cce292d1
parent3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0 (diff)
downloadgit-b396ee6bed7882af3333eb52333f8a34b648437d.tar.gz
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>
-rw-r--r--run-command.c19
-rw-r--r--run-command.h7
2 files changed, 20 insertions, 6 deletions
diff --git a/run-command.c b/run-command.c
index 0e7435718a..1b821042b4 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1793,20 +1793,27 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
trace2_region_leave(tr2_category, tr2_label, NULL);
}
-int run_auto_maintenance(int quiet)
+int prepare_auto_maintenance(int quiet, struct child_process *maint)
{
int enabled;
- struct child_process maint = CHILD_PROCESS_INIT;
if (!git_config_get_bool("maintenance.auto", &enabled) &&
!enabled)
return 0;
- maint.git_cmd = 1;
- maint.close_object_store = 1;
- strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
- strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
+ maint->git_cmd = 1;
+ maint->close_object_store = 1;
+ strvec_pushl(&maint->args, "maintenance", "run", "--auto", NULL);
+ strvec_push(&maint->args, quiet ? "--quiet" : "--no-quiet");
+
+ return 1;
+}
+int run_auto_maintenance(int quiet)
+{
+ struct child_process maint = CHILD_PROCESS_INIT;
+ if (!prepare_auto_maintenance(quiet, &maint))
+ return 0;
return run_command(&maint);
}
diff --git a/run-command.h b/run-command.h
index 1f22cc3827..55f6631a2a 100644
--- a/run-command.h
+++ b/run-command.h
@@ -218,6 +218,13 @@ int finish_command_in_signal(struct child_process *);
int run_command(struct child_process *);
/*
+ * Prepare a `struct child_process` to run auto-maintenance. Returns 1 if the
+ * process has been prepared and is ready to run, or 0 in case auto-maintenance
+ * should be skipped.
+ */
+int prepare_auto_maintenance(int quiet, struct child_process *maint);
+
+/*
* Trigger an auto-gc
*/
int run_auto_maintenance(int quiet);