From 4d5dac7ae48762a6750bbff5a8af9b7512d1e361 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 25 Jul 2022 16:14:40 +0200 Subject: just-mr: retry `git tag -f` if needed just-mr uses git tags to ensure that git roots used in the repository configuration handed out do not get garbage collected. Here, the tag encodes the commit to be kept; hence we can safely do this operation forcefully: we would only reset the tag to its old value. However, this tagging still is not free of races: git seems to first check for the existence of the tag and if not present tries creation under the assumption that no other process does so (and fails if this is the case). As our tagging is idempotent, we can safely retry it to work around this git race. --- bin/just-mr.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'bin/just-mr.py') diff --git a/bin/just-mr.py b/bin/just-mr.py index 4773e1aa..28c9249e 100755 --- a/bin/just-mr.py +++ b/bin/just-mr.py @@ -75,8 +75,14 @@ def move_to_place(src, dst): if not os.path.exists(dst): fail("%s not present after move" % (dst,)) -def run_cmd(cmd, *, env=None, stdout=subprocess.DEVNULL, stdin=None, cwd): - result = subprocess.run(cmd, cwd=cwd, env=env, stdout=stdout, stdin=stdin) +def run_cmd(cmd, *, env=None, stdout=subprocess.DEVNULL, stdin=None, cwd, + attempts=1): + for _ in range(attempts): + result = subprocess.run(cmd, cwd=cwd, env=env, stdout=stdout, + stdin=stdin) + if result.returncode == 0: + return + time.sleep(1.0) if result.returncode != 0: fail("Command %s in %s failed" % (cmd, cwd)) @@ -120,6 +126,7 @@ def git_keep(commit, *, upstream): ], cwd=git_root(upstream=upstream), env=dict(os.environ, **GIT_NOBODY_ENV), + attempts=3 ) -- cgit v1.2.3