summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-12-04 14:47:50 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2025-01-13 16:22:13 +0100
commit150d84062bdfb21c9edd3b93c3595fea7107b15d (patch)
tree6e7c77a56d12dfab82beef3c91e3ca72f54f5615
parenta98612a9a06ae2d3c5f59b34f6632d4f88137f04 (diff)
downloadjustbuild-150d84062bdfb21c9edd3b93c3595fea7107b15d.tar.gz
GitCAS: remove mutex and locks
...since there are no unique_locks any more. (cherry-picked from 9a164558010af84d834dee86f1929bd6582a1ccb)
-rw-r--r--src/buildtool/file_system/git_cas.cpp32
-rw-r--r--src/buildtool/file_system/git_cas.hpp6
-rw-r--r--src/buildtool/file_system/git_repo.cpp71
3 files changed, 27 insertions, 82 deletions
diff --git a/src/buildtool/file_system/git_cas.cpp b/src/buildtool/file_system/git_cas.cpp
index 3d0b7063..67efb4b9 100644
--- a/src/buildtool/file_system/git_cas.cpp
+++ b/src/buildtool/file_system/git_cas.cpp
@@ -151,15 +151,12 @@ auto GitCAS::ReadObject(std::string const& id, bool is_hex_id) const noexcept
}
git_odb_object* obj = nullptr;
- {
- std::shared_lock lock{mutex_};
- if (git_odb_read(&obj, odb_.get(), &oid.value()) != 0) {
- Logger::Log(LogLevel::Error,
- "reading git object {} from database failed with:\n{}",
- is_hex_id ? id : ToHexString(id),
- GitLastError());
- return std::nullopt;
- }
+ if (git_odb_read(&obj, odb_.get(), &oid.value()) != 0) {
+ Logger::Log(LogLevel::Error,
+ "reading git object {} from database failed with:\n{}",
+ is_hex_id ? id : ToHexString(id),
+ GitLastError());
+ return std::nullopt;
}
std::string data(static_cast<char const*>(git_odb_object_data(obj)),
@@ -184,16 +181,13 @@ auto GitCAS::ReadHeader(std::string const& id, bool is_hex_id) const noexcept
std::size_t size{};
git_object_t type{};
- {
- std::shared_lock lock{mutex_};
- if (git_odb_read_header(&size, &type, odb_.get(), &oid.value()) != 0) {
- Logger::Log(LogLevel::Error,
- "reading git object header {} from database failed "
- "with:\n{}",
- is_hex_id ? id : ToHexString(id),
- GitLastError());
- return std::nullopt;
- }
+ if (git_odb_read_header(&size, &type, odb_.get(), &oid.value()) != 0) {
+ Logger::Log(LogLevel::Error,
+ "reading git object header {} from database failed "
+ "with:\n{}",
+ is_hex_id ? id : ToHexString(id),
+ GitLastError());
+ return std::nullopt;
}
if (auto obj_type = GitTypeToObjectType(type)) {
diff --git a/src/buildtool/file_system/git_cas.hpp b/src/buildtool/file_system/git_cas.hpp
index 78d03c99..8b2cdb1e 100644
--- a/src/buildtool/file_system/git_cas.hpp
+++ b/src/buildtool/file_system/git_cas.hpp
@@ -20,6 +20,7 @@
#include <memory>
#include <optional>
#include <shared_mutex>
+#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
@@ -81,11 +82,6 @@ class GitCAS {
// git folder path of repo
std::filesystem::path git_path_;
- // mutex to guard odb while setting up a "fake" repository; it needs to be
- // uniquely owned while wrapping the odb, but then git operations are free
- // to share it.
- mutable std::shared_mutex mutex_;
-
friend class GitRepo; // allow access to ODB
};
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp
index dd346b98..d57f7705 100644
--- a/src/buildtool/file_system/git_repo.cpp
+++ b/src/buildtool/file_system/git_repo.cpp
@@ -18,7 +18,6 @@
#include <cstddef>
#include <map>
#include <mutex>
-#include <shared_mutex>
#include <sstream>
#include <string_view>
#include <thread>
@@ -509,8 +508,6 @@ auto GitRepo::CommitDirectory(std::filesystem::path const& dir,
true /*fatal*/);
return std::nullopt;
}
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
// Due to limitations of Git in general, and libgit2 in particular, by
// which updating the index with entries that have Git-specific magic
@@ -619,8 +616,6 @@ auto GitRepo::KeepTag(std::string const& commit,
true /*fatal*/);
return std::nullopt;
}
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
// get commit spec
git_object* target_ptr{nullptr};
@@ -728,8 +723,6 @@ auto GitRepo::GetHeadCommit(anon_logger_ptr const& logger) noexcept
true /*fatal*/);
return std::nullopt;
}
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
// get root commit id
git_oid head_oid;
@@ -854,8 +847,6 @@ auto GitRepo::KeepTree(std::string const& tree_id,
true /*fatal*/);
return std::nullopt;
}
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
// get tree oid
git_oid tree_oid;
@@ -980,8 +971,6 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit,
LogLevel::Debug,
"Subtree id retrieval from commit called on a real repository");
}
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
// get commit object
git_oid commit_oid;
@@ -1080,8 +1069,6 @@ auto GitRepo::GetSubtreeFromTree(std::string const& tree_id,
"Subtree id retrieval from tree called on a real "
"repository");
}
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
// get tree object from tree id
git_oid tree_oid;
@@ -1223,13 +1210,8 @@ auto GitRepo::CheckCommitExists(std::string const& commit,
}
git_commit* commit_obj = nullptr;
- int lookup_res{};
- {
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
- lookup_res = git_commit_lookup(
- &commit_obj, &GetGitRepository(), &commit_oid);
- }
+ int const lookup_res =
+ git_commit_lookup(&commit_obj, &GetGitRepository(), &commit_oid);
if (lookup_res != 0) {
if (lookup_res == GIT_ENOTFOUND) {
// cleanup resources
@@ -1329,13 +1311,8 @@ auto GitRepo::CheckTreeExists(std::string const& tree_id,
}
// get tree object
git_tree* tree_ptr = nullptr;
- int lookup_res{};
- {
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
- lookup_res =
- git_tree_lookup(&tree_ptr, &GetGitRepository(), &tree_oid);
- }
+ int const lookup_res =
+ git_tree_lookup(&tree_ptr, &GetGitRepository(), &tree_oid);
git_tree_free(tree_ptr);
if (lookup_res != 0) {
if (lookup_res == GIT_ENOTFOUND) {
@@ -1381,13 +1358,8 @@ auto GitRepo::CheckBlobExists(std::string const& blob_id,
}
// get blob object
git_blob* blob_ptr = nullptr;
- int lookup_res{};
- {
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
- lookup_res =
- git_blob_lookup(&blob_ptr, &GetGitRepository(), &blob_oid);
- }
+ int const lookup_res =
+ git_blob_lookup(&blob_ptr, &GetGitRepository(), &blob_oid);
git_blob_free(blob_ptr);
if (lookup_res != 0) {
if (lookup_res == GIT_ENOTFOUND) {
@@ -1433,13 +1405,8 @@ auto GitRepo::TryReadBlob(std::string const& blob_id,
}
// get blob object
git_blob* blob_ptr = nullptr;
- int lookup_res{};
- {
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
- lookup_res =
- git_blob_lookup(&blob_ptr, &GetGitRepository(), &blob_oid);
- }
+ int const lookup_res =
+ git_blob_lookup(&blob_ptr, &GetGitRepository(), &blob_oid);
git_blob_free(blob_ptr);
if (lookup_res != 0) {
if (lookup_res == GIT_ENOTFOUND) {
@@ -1482,8 +1449,6 @@ auto GitRepo::WriteBlob(std::string const& content,
Logger::Log(LogLevel::Debug,
"Blob writer called on a real repository");
}
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
git_oid blob_oid;
if (git_blob_create_from_buffer(&blob_oid,
@@ -1521,9 +1486,6 @@ auto GitRepo::GetObjectByPathFromTree(std::string const& tree_id,
}
// check if path is not trivial
if (rel_path != ".") {
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
-
// get tree object from tree id
git_oid tree_oid;
if (git_oid_fromstr(&tree_oid, tree_id.c_str()) != 0) {
@@ -1720,15 +1682,11 @@ auto GitRepo::ReadTree(std::string const& id,
// lookup tree
git_tree* tree_ptr{nullptr};
- {
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
- if (git_tree_lookup(&tree_ptr, &GetGitRepository(), &(*oid)) != 0) {
- Logger::Log(LogLevel::Debug,
- "failed to lookup Git tree {}",
- is_hex_id ? std::string{id} : ToHexString(id));
- return std::nullopt;
- }
+ if (git_tree_lookup(&tree_ptr, &GetGitRepository(), &(*oid)) != 0) {
+ Logger::Log(LogLevel::Debug,
+ "failed to lookup Git tree {}",
+ is_hex_id ? std::string{id} : ToHexString(id));
+ return std::nullopt;
}
auto tree = std::unique_ptr<git_tree, decltype(&tree_closer)>{
tree_ptr, tree_closer};
@@ -1809,9 +1767,6 @@ auto GitRepo::CreateTree(tree_entries_t const& entries) const noexcept
// Check consistency of entries. Also check that entries exist.
ExpectsAudit(ValidateEntries(entries, GetGitCAS()));
#endif // NDEBUG
- // share the odb lock
- std::shared_lock lock{GetGitCAS()->mutex_};
-
try {
// As the libgit2 treebuilder checks for magic names and does not allow
// us to add any and all entries to a Git tree, we resort to