Skip to content

Commit 91321d4

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 <[email protected]>
1 parent 95acf54 commit 91321d4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

scalar.c

Lines changed: 20 additions & 5 deletions
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 {
@@ -610,6 +623,8 @@ static int cmd_diagnose(int argc, const char **argv)
610623
setup_enlistment_directory(argc, argv, usage, options, &diagnostics_root);
611624
strbuf_addstr(&diagnostics_root, "/.scalarDiagnostics");
612625

626+
/* Here, a failure should not repeat itself. */
627+
git_retries = 1;
613628
res = run_git("diagnose", "--mode=all", "-s", "%Y%m%d_%H%M%S",
614629
"-o", diagnostics_root.buf, NULL);
615630

0 commit comments

Comments
 (0)