diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-02-25 13:32:48 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-02-28 14:57:48 +0100 |
commit | 1622d6426989b28b6b8a5105f29ec89b4340710b (patch) | |
tree | f9ea666b5a2f947c1a8a36950306d15a1824ea22 | |
parent | 7843f3a4a81ab735f16ea37aaf220a5e46c03cc9 (diff) | |
download | justbuild-1622d6426989b28b6b8a5105f29ec89b4340710b.tar.gz |
just-lock: Improve thread safety in Git operations
Similarly to how it is done in just-mr:
- lock against concurrent git-tag calls;
- extend git-fetch call with arguments that ensure thread-safe
operation.
-rwxr-xr-x | bin/just-lock.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/bin/just-lock.py b/bin/just-lock.py index 0c1abcd2..41ca2f7e 100755 --- a/bin/just-lock.py +++ b/bin/just-lock.py @@ -291,15 +291,21 @@ def git_keep(commit: str, *, upstream: Optional[str], fail_context: str) -> None: """Keep commit by tagging it. It is a user error if the referenced Git repository does not exist.""" + root: str = git_root(upstream=upstream) + # acquire exclusive lock + lockfile = lock_acquire(os.path.join(Path(root).parent, "init_open.lock")) + # tag commit git_env = {**os.environ.copy(), **GIT_NOBODY_ENV} run_cmd(g_LAUNCHER + [ g_GIT, "tag", "-f", "-m", "Keep referenced tree alive", "keep-%s" % (commit, ), commit ], - cwd=git_root(upstream=upstream), + cwd=root, env=git_env, attempts=3, fail_context=fail_context) + # release exclusive lock + lock_release(lockfile) def ensure_git_init(*, @@ -358,7 +364,10 @@ def git_fetch(*, from_repo: Optional[str], to_repo: Optional[str], path_url = git_url_is_path(from_repo) if path_url is not None: from_repo = os.path.abspath(path_url) - return run_cmd(g_LAUNCHER + [g_GIT, "fetch", from_repo, fetchable], + return run_cmd(g_LAUNCHER + [ + g_GIT, "fetch", "--no-auto-gc", "--no-write-fetch-head", from_repo, + fetchable + ], cwd=git_root(upstream=to_repo), fail_context=fail_context)[1] == 0 |