From 99860b78304817c4d5b27ec4c661b733e30a430a Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Wed, 4 Dec 2024 13:12:15 +0100 Subject: GitCAS: implement method for creation of an empty GitCAS ...and use it in GitRepo to set custom backends. --- src/buildtool/file_system/git_cas.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/buildtool/file_system/git_cas.cpp') 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(); + + 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(result); +#endif +} + auto GitCAS::ReadObject(std::string const& id, bool is_hex_id) const noexcept -> std::optional { #ifdef BOOTSTRAP_BUILD_TOOL -- cgit v1.2.3