Skip to content

Commit cdf3ce6

Browse files
derrickstoleedscho
authored andcommitted
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 ab34496 commit cdf3ce6

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
@@ -1674,6 +1674,42 @@ static const char *get_frequency(enum schedule_priority schedule)
16741674
}
16751675
}
16761676

1677+
static const char *extraconfig[] = {
1678+
"credential.interactive=false",
1679+
"core.askPass=true", /* 'true' returns success, but no output. */
1680+
NULL
1681+
};
1682+
1683+
static const char *get_extra_config_parameters(void) {
1684+
static const char *result = NULL;
1685+
struct strbuf builder = STRBUF_INIT;
1686+
1687+
if (result)
1688+
return result;
1689+
1690+
for (const char **s = extraconfig; s && *s; s++)
1691+
strbuf_addf(&builder, "-c %s ", *s);
1692+
1693+
result = strbuf_detach(&builder, NULL);
1694+
return result;
1695+
}
1696+
1697+
static const char *get_extra_launchctl_strings(void) {
1698+
static const char *result = NULL;
1699+
struct strbuf builder = STRBUF_INIT;
1700+
1701+
if (result)
1702+
return result;
1703+
1704+
for (const char **s = extraconfig; s && *s; s++) {
1705+
strbuf_addstr(&builder, "<string>-c</string>\n");
1706+
strbuf_addf(&builder, "<string>%s</string>\n", *s);
1707+
}
1708+
1709+
result = strbuf_detach(&builder, NULL);
1710+
return result;
1711+
}
1712+
16771713
/*
16781714
* get_schedule_cmd` reads the GIT_TEST_MAINT_SCHEDULER environment variable
16791715
* to mock the schedulers that `git maintenance start` rely on.
@@ -1880,6 +1916,7 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
18801916
"<array>\n"
18811917
"<string>%s/git</string>\n"
18821918
"<string>--exec-path=%s</string>\n"
1919+
"%s" /* For extra config parameters. */
18831920
"<string>for-each-repo</string>\n"
18841921
"<string>--config=maintenance.repo</string>\n"
18851922
"<string>maintenance</string>\n"
@@ -1888,7 +1925,8 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
18881925
"</array>\n"
18891926
"<key>StartCalendarInterval</key>\n"
18901927
"<array>\n";
1891-
strbuf_addf(&plist, preamble, name, exec_path, exec_path, frequency);
1928+
strbuf_addf(&plist, preamble, name, exec_path, exec_path,
1929+
get_extra_launchctl_strings(), frequency);
18921930

18931931
switch (schedule) {
18941932
case SCHEDULE_HOURLY:
@@ -2123,11 +2161,12 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
21232161
"<Actions Context=\"Author\">\n"
21242162
"<Exec>\n"
21252163
"<Command>\"%s\\headless-git.exe\"</Command>\n"
2126-
"<Arguments>--exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%s</Arguments>\n"
2164+
"<Arguments>--exec-path=\"%s\" %s for-each-repo --config=maintenance.repo maintenance run --schedule=%s</Arguments>\n"
21272165
"</Exec>\n"
21282166
"</Actions>\n"
21292167
"</Task>\n";
2130-
fprintf(tfile->fp, xml, exec_path, exec_path, frequency);
2168+
fprintf(tfile->fp, xml, exec_path, exec_path,
2169+
get_extra_config_parameters(), frequency);
21312170
strvec_split(&child.args, cmd);
21322171
strvec_pushl(&child.args, "/create", "/tn", name, "/f", "/xml",
21332172
get_tempfile_path(tfile), NULL);
@@ -2268,8 +2307,8 @@ static int crontab_update_schedule(int run_maintenance, int fd)
22682307
"# replaced in the future by a Git command.\n\n");
22692308

22702309
strbuf_addf(&line_format,
2271-
"%%d %%s * * %%s \"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n",
2272-
exec_path, exec_path);
2310+
"%%d %%s * * %%s \"%s/git\" --exec-path=\"%s\" %s for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n",
2311+
exec_path, exec_path, get_extra_config_parameters());
22732312
fprintf(cron_in, line_format.buf, minute, "1-23", "*", "hourly");
22742313
fprintf(cron_in, line_format.buf, minute, "0", "1-6", "daily");
22752314
fprintf(cron_in, line_format.buf, minute, "0", "0", "weekly");
@@ -2469,7 +2508,7 @@ static int systemd_timer_write_service_template(const char *exec_path)
24692508
"\n"
24702509
"[Service]\n"
24712510
"Type=oneshot\n"
2472-
"ExecStart=\"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%i\n"
2511+
"ExecStart=\"%s/git\" --exec-path=\"%s\" %s for-each-repo --config=maintenance.repo maintenance run --schedule=%%i\n"
24732512
"LockPersonality=yes\n"
24742513
"MemoryDenyWriteExecute=yes\n"
24752514
"NoNewPrivileges=yes\n"
@@ -2479,7 +2518,7 @@ static int systemd_timer_write_service_template(const char *exec_path)
24792518
"RestrictSUIDSGID=yes\n"
24802519
"SystemCallArchitectures=native\n"
24812520
"SystemCallFilter=@system-service\n";
2482-
if (fprintf(file, unit, exec_path, exec_path) < 0) {
2521+
if (fprintf(file, unit, exec_path, exec_path, get_extra_config_parameters()) < 0) {
24832522
error(_("failed to write to '%s'"), filename);
24842523
fclose(file);
24852524
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)