Skip to content

Commit

Permalink
run-command: introduce function to prepare auto-maintenance process
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pks-t authored and gitster committed Apr 17, 2024
1 parent 3c2a3fd commit b396ee6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
19 changes: 13 additions & 6 deletions run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 7 additions & 0 deletions run-command.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,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
*/
Expand Down

0 comments on commit b396ee6

Please sign in to comment.