Skip to content

Commit 1f2506f

Browse files
derrickstoleedscho
authored andcommitted
scalar: add retry logic to run_git()
Use a fixed 3 tries total to see how that increases our chances of success for subcommands such as 'git fetch'. We special-case the `diagnose` command here: When 672196a (scalar-diagnose: use 'git diagnose --mode=all', 2022-08-12) updated 'scalar diagnose' to run 'git diagnose' as a subprocess, it was passed through the run_git() caller. We need to avoid repeating the call when the underlying 'git diagnose' command fails. Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
1 parent d28ad03 commit 1f2506f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Diff for: scalar.c

+20-5
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,34 @@ static void setup_enlistment_directory(int argc, const char **argv,
7575
strbuf_release(&path);
7676
}
7777

78+
static int git_retries = 3;
79+
7880
LAST_ARG_MUST_BE_NULL
7981
static int run_git(const char *arg, ...)
8082
{
81-
struct child_process cmd = CHILD_PROCESS_INIT;
8283
va_list args;
8384
const char *p;
85+
struct strvec argv = STRVEC_INIT;
86+
int res = 0, attempts;
8487

8588
va_start(args, arg);
86-
strvec_push(&cmd.args, arg);
89+
strvec_push(&argv, arg);
8790
while ((p = va_arg(args, const char *)))
88-
strvec_push(&cmd.args, p);
91+
strvec_push(&argv, p);
8992
va_end(args);
9093

91-
cmd.git_cmd = 1;
92-
return run_command(&cmd);
94+
for (attempts = 0, res = 1;
95+
res && attempts < git_retries;
96+
attempts++) {
97+
struct child_process cmd = CHILD_PROCESS_INIT;
98+
99+
cmd.git_cmd = 1;
100+
strvec_pushv(&cmd.args, argv.v);
101+
res = run_command(&cmd);
102+
}
103+
104+
strvec_clear(&argv);
105+
return res;
93106
}
94107

95108
struct scalar_config {
@@ -590,6 +603,8 @@ static int cmd_diagnose(int argc, const char **argv)
590603
setup_enlistment_directory(argc, argv, usage, options, &diagnostics_root);
591604
strbuf_addstr(&diagnostics_root, "/.scalarDiagnostics");
592605

606+
/* Here, a failure should not repeat itself. */
607+
git_retries = 1;
593608
res = run_git("diagnose", "--mode=all", "-s", "%Y%m%d_%H%M%S",
594609
"-o", diagnostics_root.buf, NULL);
595610

0 commit comments

Comments
 (0)