Skip to content

Commit 384c80e

Browse files
committed
maintenance: add custom config to background jobs
At the moment, some background jobs are getting blocked on credentials during the 'prefetch' task. This leads to other tasks, such as incremental repacks, getting blocked. Further, if a user manages to fix their credentials, then they still need to cancel the background process before their background maintenance can continue working. Update the background schedules for our four scheduler integrations to include these config options via '-c' options: * 'credential.interactive=false' will stop Git and some credential helpers from prompting in the UI (assuming the '-c' parameters are carried through and respected by GCM). * 'core.askPass=true' will replace the text fallback for a username and password into the 'true' command, which will return a success in its exit code, but Git will treat the empty string returned as an invalid password and move on. We can do some testing that the credentials are passed, at least in the systemd case due to writing the service files. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 22acd55 commit 384c80e

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

builtin/gc.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,42 @@ static const char *get_frequency(enum schedule_priority schedule)
16571657
}
16581658
}
16591659

1660+
static const char *extraconfig[] = {
1661+
"credential.interactive=false",
1662+
"core.askPass=true", /* 'true' returns success, but no output. */
1663+
NULL
1664+
};
1665+
1666+
static const char *get_extra_config_parameters(void) {
1667+
static const char *result = NULL;
1668+
struct strbuf builder = STRBUF_INIT;
1669+
1670+
if (result)
1671+
return result;
1672+
1673+
for (const char **s = extraconfig; s && *s; s++)
1674+
strbuf_addf(&builder, "-c %s ", *s);
1675+
1676+
result = strbuf_detach(&builder, NULL);
1677+
return result;
1678+
}
1679+
1680+
static const char *get_extra_launchctl_strings(void) {
1681+
static const char *result = NULL;
1682+
struct strbuf builder = STRBUF_INIT;
1683+
1684+
if (result)
1685+
return result;
1686+
1687+
for (const char **s = extraconfig; s && *s; s++) {
1688+
strbuf_addstr(&builder, "<string>-c</string>\n");
1689+
strbuf_addf(&builder, "<string>%s</string>\n", *s);
1690+
}
1691+
1692+
result = strbuf_detach(&builder, NULL);
1693+
return result;
1694+
}
1695+
16601696
/*
16611697
* get_schedule_cmd` reads the GIT_TEST_MAINT_SCHEDULER environment variable
16621698
* to mock the schedulers that `git maintenance start` rely on.
@@ -1863,6 +1899,7 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
18631899
"<array>\n"
18641900
"<string>%s/git</string>\n"
18651901
"<string>--exec-path=%s</string>\n"
1902+
"%s" /* For extra config parameters. */
18661903
"<string>for-each-repo</string>\n"
18671904
"<string>--config=maintenance.repo</string>\n"
18681905
"<string>maintenance</string>\n"
@@ -1871,7 +1908,8 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
18711908
"</array>\n"
18721909
"<key>StartCalendarInterval</key>\n"
18731910
"<array>\n";
1874-
strbuf_addf(&plist, preamble, name, exec_path, exec_path, frequency);
1911+
strbuf_addf(&plist, preamble, name, exec_path, exec_path,
1912+
get_extra_launchctl_strings(), frequency);
18751913

18761914
switch (schedule) {
18771915
case SCHEDULE_HOURLY:
@@ -2106,11 +2144,12 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
21062144
"<Actions Context=\"Author\">\n"
21072145
"<Exec>\n"
21082146
"<Command>\"%s\\headless-git.exe\"</Command>\n"
2109-
"<Arguments>--exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%s</Arguments>\n"
2147+
"<Arguments>--exec-path=\"%s\" %s for-each-repo --config=maintenance.repo maintenance run --schedule=%s</Arguments>\n"
21102148
"</Exec>\n"
21112149
"</Actions>\n"
21122150
"</Task>\n";
2113-
fprintf(tfile->fp, xml, exec_path, exec_path, frequency);
2151+
fprintf(tfile->fp, xml, exec_path, exec_path,
2152+
get_extra_config_parameters(), frequency);
21142153
strvec_split(&child.args, cmd);
21152154
strvec_pushl(&child.args, "/create", "/tn", name, "/f", "/xml",
21162155
get_tempfile_path(tfile), NULL);
@@ -2251,8 +2290,8 @@ static int crontab_update_schedule(int run_maintenance, int fd)
22512290
"# replaced in the future by a Git command.\n\n");
22522291

22532292
strbuf_addf(&line_format,
2254-
"%%d %%s * * %%s \"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n",
2255-
exec_path, exec_path);
2293+
"%%d %%s * * %%s \"%s/git\" --exec-path=\"%s\" %s for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n",
2294+
exec_path, exec_path, get_extra_config_parameters());
22562295
fprintf(cron_in, line_format.buf, minute, "1-23", "*", "hourly");
22572296
fprintf(cron_in, line_format.buf, minute, "0", "1-6", "daily");
22582297
fprintf(cron_in, line_format.buf, minute, "0", "0", "weekly");
@@ -2452,7 +2491,7 @@ static int systemd_timer_write_service_template(const char *exec_path)
24522491
"\n"
24532492
"[Service]\n"
24542493
"Type=oneshot\n"
2455-
"ExecStart=\"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%i\n"
2494+
"ExecStart=\"%s/git\" --exec-path=\"%s\" %s for-each-repo --config=maintenance.repo maintenance run --schedule=%%i\n"
24562495
"LockPersonality=yes\n"
24572496
"MemoryDenyWriteExecute=yes\n"
24582497
"NoNewPrivileges=yes\n"
@@ -2462,7 +2501,7 @@ static int systemd_timer_write_service_template(const char *exec_path)
24622501
"RestrictSUIDSGID=yes\n"
24632502
"SystemCallArchitectures=native\n"
24642503
"SystemCallFilter=@system-service\n";
2465-
if (fprintf(file, unit, exec_path, exec_path) < 0) {
2504+
if (fprintf(file, unit, exec_path, exec_path, get_extra_config_parameters()) < 0) {
24662505
error(_("failed to write to '%s'"), filename);
24672506
fclose(file);
24682507
goto error;

t/t7900-maintenance.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ test_expect_success 'start and stop Linux/systemd maintenance' '
754754
test_systemd_analyze_verify "systemd/user/[email protected]" &&
755755
test_systemd_analyze_verify "systemd/user/[email protected]" &&
756756
757+
grep "core.askPass=true" "systemd/user/[email protected]" &&
758+
grep "credential.interactive=false" "systemd/user/[email protected]" &&
759+
757760
printf -- "--user enable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
758761
test_cmp expect args &&
759762

0 commit comments

Comments
 (0)