From b0d1da1fd7c82a5b636337e562d8ba36ce7ffa16 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 13 Mar 2023 17:36:59 +0100 Subject: 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. --- src/buildtool/file_system/git_repo.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/buildtool/file_system/git_repo.cpp') 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 -- cgit v1.2.3