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
committerKlaus Aehlig <klaus.aehlig@huawei.com>2025-01-13 16:21:08 +0100
commit98f1e8224753e7d7bfaf697012302887d85bff6c (patch)
tree5430fa4e9f8d971d8e8043e62e3aa57aef231217 /src/buildtool/file_system/git_cas.cpp
parent0c50b8a6a181795697be882bd62c0d37efab078c (diff)
downloadjustbuild-98f1e8224753e7d7bfaf697012302887d85bff6c.tar.gz
GitCAS: implement method for creation of an empty GitCAS
...and use it in GitRepo to set custom backends. (cherry-picked 99860b78304817c4d5b27ec4c661b733e30a430a)
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 13177cea..f40c83cf 100644
--- a/src/buildtool/file_system/git_cas.cpp
+++ b/src/buildtool/file_system/git_cas.cpp
@@ -109,6 +109,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