Skip to content

Commit 6aba9c6

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 2501a2f commit 6aba9c6

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎scalar.c‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,34 @@ static void setup_enlistment_directory(int argc, const char **argv,
7676
strbuf_release(&path);
7777
}
7878

79+
static int git_retries = 3;
80+
7981
LAST_ARG_MUST_BE_NULL
8082
static int run_git(const char *arg, ...)
8183
{
82-
struct child_process cmd = CHILD_PROCESS_INIT;
8384
va_list args;
8485
const char *p;
86+
struct strvec argv = STRVEC_INIT;
87+
int res = 0, attempts;
8588

8689
va_start(args, arg);
87-
strvec_push(&cmd.args, arg);
90+
strvec_push(&argv, arg);
8891
while ((p = va_arg(args, const char *)))
89-
strvec_push(&cmd.args, p);
92+
strvec_push(&argv, p);
9093
va_end(args);
9194

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

96109
struct scalar_config {
@@ -620,6 +633,8 @@ static int cmd_diagnose(int argc, const char **argv)
620633
setup_enlistment_directory(argc, argv, usage, options, &diagnostics_root);
621634
strbuf_addstr(&diagnostics_root, "/.scalarDiagnostics");
622635

636+
/* Here, a failure should not repeat itself. */
637+
git_retries = 1;
623638
res = run_git("diagnose", "--mode=all", "-s", "%Y%m%d_%H%M%S",
624639
"-o", diagnostics_root.buf, NULL);
625640

0 commit comments

Comments
 (0)