diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-03-13 17:36:59 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-03-23 14:18:52 +0100 |
commit | b0d1da1fd7c82a5b636337e562d8ba36ce7ffa16 (patch) | |
tree | e7ffe85e4d1f267d48e4b35906018081eb9d41f9 /src | |
parent | 020555821575f8717b3aa36aebdb9012a86b9016 (diff) | |
download | justbuild-b0d1da1fd7c82a5b636337e562d8ba36ce7ffa16.tar.gz |
GitRepo: Make tag creation operation more robust
Use a similar logic as for repository initialisation: first check
if tag has not already been created in another process, and only
then try creation; make more tries with more wait in between; only
retry if failure was due to internal locking.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index 7e7a4d18..31bfed38 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -594,10 +594,18 @@ auto GitRepo::KeepTag(std::string const& commit, // create tag git_oid oid; auto name = fmt::format("keep-{}", commit); + git_strarray tag_names{}; + + // check if tag hasn't already been added by another process + if (git_tag_list_match(&tag_names, name.c_str(), repo_.get()) == 0 and + tag_names.count > 0) { + git_strarray_dispose(&tag_names); + return true; // success! + } + git_strarray_dispose(&tag_names); // free any allocated unused space size_t max_attempts = kGitLockNumTries; // number of tries int err = 0; - git_strarray tag_names{}; std::string err_mess{}; while (max_attempts > 0) { --max_attempts; @@ -612,6 +620,10 @@ auto GitRepo::KeepTag(std::string const& commit, return true; // success! } err_mess = GitLastError(); // store last error message + // only retry if failure is due to locking + if (err != GIT_ELOCKED) { + break; + } // check if tag hasn't already been added by another process if (git_tag_list_match(&tag_names, name.c_str(), repo_.get()) == 0 and |