Skip to content

Commit 5c7ffaf

Browse files
committed
Merge branch 'ps/run-auto-maintenance-in-receive-pack'
The "receive-pack" program (which responds to "git push") was not converted to run "git maintenance --auto" when other codepaths that used to run "git gc --auto" were updated, which has been corrected. * ps/run-auto-maintenance-in-receive-pack: builtin/receive-pack: convert to use git-maintenance(1) run-command: introduce function to prepare auto-maintenance process
2 parents 5b78774 + 7bf3057 commit 5c7ffaf

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

Documentation/config/receive.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ receive.advertisePushOptions::
88
capability to its clients. False by default.
99

1010
receive.autogc::
11-
By default, git-receive-pack will run "git-gc --auto" after
11+
By default, git-receive-pack will run "git maintenance run --auto" after
1212
receiving data from git-push and updating refs. You can stop
1313
it by setting this variable to false.
1414

builtin/receive-pack.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,17 +2585,16 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
25852585
if (auto_gc) {
25862586
struct child_process proc = CHILD_PROCESS_INIT;
25872587

2588-
proc.no_stdin = 1;
2589-
proc.stdout_to_stderr = 1;
2590-
proc.err = use_sideband ? -1 : 0;
2591-
proc.git_cmd = proc.close_object_store = 1;
2592-
strvec_pushl(&proc.args, "gc", "--auto", "--quiet",
2593-
NULL);
2594-
2595-
if (!start_command(&proc)) {
2596-
if (use_sideband)
2597-
copy_to_sideband(proc.err, -1, NULL);
2598-
finish_command(&proc);
2588+
if (prepare_auto_maintenance(1, &proc)) {
2589+
proc.no_stdin = 1;
2590+
proc.stdout_to_stderr = 1;
2591+
proc.err = use_sideband ? -1 : 0;
2592+
2593+
if (!start_command(&proc)) {
2594+
if (use_sideband)
2595+
copy_to_sideband(proc.err, -1, NULL);
2596+
finish_command(&proc);
2597+
}
25992598
}
26002599
}
26012600
if (auto_update_server_info)

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)