Skip to content

Commit

Permalink
scalar: add retry logic to run_git()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
derrickstolee authored and dscho committed Sep 18, 2024
1 parent 4d7b52c commit 8f56aa9
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,34 @@ static void setup_enlistment_directory(int argc, const char **argv,
strbuf_release(&path);
}

static int git_retries = 3;

LAST_ARG_MUST_BE_NULL
static int run_git(const char *arg, ...)
{
struct child_process cmd = CHILD_PROCESS_INIT;
va_list args;
const char *p;
struct strvec argv = STRVEC_INIT;
int res = 0, attempts;

va_start(args, arg);
strvec_push(&cmd.args, arg);
strvec_push(&argv, arg);
while ((p = va_arg(args, const char *)))
strvec_push(&cmd.args, p);
strvec_push(&argv, p);
va_end(args);

cmd.git_cmd = 1;
return run_command(&cmd);
for (attempts = 0, res = 1;
res && attempts < git_retries;
attempts++) {
struct child_process cmd = CHILD_PROCESS_INIT;

cmd.git_cmd = 1;
strvec_pushv(&cmd.args, argv.v);
res = run_command(&cmd);
}

strvec_clear(&argv);
return res;
}

struct scalar_config {
Expand Down Expand Up @@ -579,6 +592,8 @@ static int cmd_diagnose(int argc, const char **argv)
setup_enlistment_directory(argc, argv, usage, options, &diagnostics_root);
strbuf_addstr(&diagnostics_root, "/.scalarDiagnostics");

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

Expand Down

0 comments on commit 8f56aa9

Please sign in to comment.