summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_cas.cpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-12-04 13:12:15 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2024-12-05 11:07:10 +0100
commit99860b78304817c4d5b27ec4c661b733e30a430a (patch)
treedc4ae56e2046e43ee9ea11590e9ba5c8d42300a0 /src/buildtool/file_system/git_cas.cpp
parentf40780393d68e2ebb866d8b941b5a30f0ea5f0de (diff)
downloadjustbuild-99860b78304817c4d5b27ec4c661b733e30a430a.tar.gz
GitCAS: implement method for creation of an empty GitCAS
...and use it in GitRepo to set custom backends.
Diffstat (limited to 'src/buildtool/file_system/git_cas.cpp')
-rw-r--r--src/buildtool/file_system/git_cas.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/buildtool/file_system/git_cas.cpp b/src/buildtool/file_system/git_cas.cpp
index 2d1c4c33..69fc8922 100644
--- a/src/buildtool/file_system/git_cas.cpp
+++ b/src/buildtool/file_system/git_cas.cpp
@@ -108,6 +108,24 @@ auto GitCAS::Open(std::filesystem::path const& repo_path) noexcept
#endif
}
+auto GitCAS::CreateEmpty() noexcept -> GitCASPtr {
+#ifdef BOOTSTRAP_BUILD_TOOL
+ return nullptr;
+#else
+ auto result = std::make_shared<GitCAS>();
+
+ git_odb* odb_ptr{nullptr};
+ if (git_odb_new(&odb_ptr) != 0 or odb_ptr == nullptr) {
+ Logger::Log(LogLevel::Error,
+ "creating an empty database failed with:\n{}",
+ GitLastError());
+ return nullptr;
+ }
+ result->odb_.reset(odb_ptr); // retain odb pointer
+ return std::const_pointer_cast<GitCAS const>(result);
+#endif
+}
+
auto GitCAS::ReadObject(std::string const& id, bool is_hex_id) const noexcept
-> std::optional<std::string> {
#ifdef BOOTSTRAP_BUILD_TOOL