Skip to content

Commit d2ed421

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 b73a701 commit d2ed421

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
@@ -73,20 +73,33 @@ static void setup_enlistment_directory(int argc, const char **argv,
7373
strbuf_release(&path);
7474
}
7575

76+
static int git_retries = 3;
77+
7678
static int run_git(const char *arg, ...)
7779
{
78-
struct child_process cmd = CHILD_PROCESS_INIT;
7980
va_list args;
8081
const char *p;
82+
struct strvec argv = STRVEC_INIT;
83+
int res = 0, attempts;
8184

8285
va_start(args, arg);
83-
strvec_push(&cmd.args, arg);
86+
strvec_push(&argv, arg);
8487
while ((p = va_arg(args, const char *)))
85-
strvec_push(&cmd.args, p);
88+
strvec_push(&argv, p);
8689
va_end(args);
8790

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

92105
struct scalar_config {
@@ -572,6 +585,8 @@ static int cmd_diagnose(int argc, const char **argv)
572585
setup_enlistment_directory(argc, argv, usage, options, &diagnostics_root);
573586
strbuf_addstr(&diagnostics_root, "/.scalarDiagnostics");
574587

588+
/* Here, a failure should not repeat itself. */
589+
git_retries = 1;
575590
res = run_git("diagnose", "--mode=all", "-s", "%Y%m%d_%H%M%S",
576591
"-o", diagnostics_root.buf, NULL);
577592

0 commit comments

Comments
 (0)