diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-12-04 13:12:15 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-12-05 11:07:10 +0100 |
commit | 99860b78304817c4d5b27ec4c661b733e30a430a (patch) | |
tree | dc4ae56e2046e43ee9ea11590e9ba5c8d42300a0 /src/buildtool/file_system/git_repo.cpp | |
parent | f40780393d68e2ebb866d8b941b5a30f0ea5f0de (diff) | |
download | justbuild-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_repo.cpp')
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index ccb888c7..f43a1f5f 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -1975,7 +1975,6 @@ auto GitRepo::ReadTreeData( #ifndef BOOTSTRAP_BUILD_TOOL try { InMemoryODBBackend b{.parent = kInMemoryODBParent}; - auto cas = std::make_shared<GitCAS>(); if (auto raw_id = is_hex_id ? FromHexString(id) : std::make_optional(id)) { try { @@ -1983,17 +1982,16 @@ auto GitRepo::ReadTreeData( } catch (...) { return std::nullopt; } - // create a GitCAS from a special-purpose in-memory object database. - git_odb* odb_ptr{nullptr}; - if (git_odb_new(&odb_ptr) == 0 and + // create a GitCAS from a special-purpose in-memory object + // database. + auto cas = GitCAS::CreateEmpty(); + if (cas != nullptr and git_odb_add_backend( - odb_ptr, + cas->GetODB(), reinterpret_cast<git_odb_backend*>(&b), // NOLINT 0) == 0) { - cas->odb_.reset(odb_ptr); // take ownership of odb // wrap odb in "fake" repo - auto repo = - GitRepo(std::static_pointer_cast<GitCAS const>(cas)); + auto repo = GitRepo(cas); return repo.ReadTree( *raw_id, check_symlinks, /*is_hex_id=*/false); } @@ -2011,17 +2009,14 @@ auto GitRepo::CreateShallowTree(tree_entries_t const& entries) noexcept #ifndef BOOTSTRAP_BUILD_TOOL try { InMemoryODBBackend b{.parent = kInMemoryODBParent, .entries = &entries}; - auto cas = std::make_shared<GitCAS>(); - // create a GitCAS from a special-purpose in-memory object database. - git_odb* odb_ptr{nullptr}; - if (git_odb_new(&odb_ptr) == 0 and + auto cas = GitCAS::CreateEmpty(); + if (cas != nullptr and git_odb_add_backend( - odb_ptr, + cas->GetODB(), reinterpret_cast<git_odb_backend*>(&b), // NOLINT 0) == 0) { - cas->odb_.reset(odb_ptr); // take ownership of odb // wrap odb in "fake" repo - auto repo = GitRepo(std::static_pointer_cast<GitCAS const>(cas)); + auto repo = GitRepo(cas); if (auto raw_id = repo.CreateTree(entries)) { // read result from in-memory trees if (auto it = b.trees.find(*raw_id); it != b.trees.end()) { |