From 517ff7f2a52bc9c96a7e5fdbce3cea04390f2c37 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 18 Feb 2025 11:32:27 +0100 Subject: GitApi: Use BackMap to get missing digests --- src/buildtool/execution_api/git/git_api.cpp | 39 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/buildtool/execution_api/git/git_api.cpp') diff --git a/src/buildtool/execution_api/git/git_api.cpp b/src/buildtool/execution_api/git/git_api.cpp index f8292558..a9373590 100644 --- a/src/buildtool/execution_api/git/git_api.cpp +++ b/src/buildtool/execution_api/git/git_api.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -32,6 +31,7 @@ #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" +#include "src/utils/cpp/back_map.hpp" #include "src/utils/cpp/expected.hpp" namespace { @@ -167,16 +167,20 @@ auto GitApi::RetrieveToFds( auto GitApi::RetrieveToCas( std::vector const& artifacts_info, IExecutionApi const& api) const noexcept -> bool { - // Determine missing artifacts in other CAS. - auto missing_artifacts_info = GetMissingArtifactsInfo( - api, - artifacts_info.begin(), - artifacts_info.end(), - [](Artifact::ObjectInfo const& info) { return info.digest; }); - if (not missing_artifacts_info) { - Logger::Log(LogLevel::Error, - "GitApi: Failed to retrieve the missing artifacts"); - return false; + // Determine missing artifacts in api. + std::unordered_set> missing; + missing.reserve(artifacts_info.size()); + { + auto back_map = BackMap::Make( + &artifacts_info, + [](Artifact::ObjectInfo const& info) { return info.digest; }); + if (back_map == nullptr) { + Logger::Log(LogLevel::Error, "GitApi: Failed to create BackMap"); + return false; + } + + auto missing_digests = api.GetMissingDigests(back_map->GetKeys()); + missing = back_map->GetReferences(missing_digests); } // GitApi works in the native mode only. @@ -185,12 +189,11 @@ auto GitApi::RetrieveToCas( // Collect blobs of missing artifacts from local CAS. Trees are // processed recursively before any blob is uploaded. std::unordered_set container; - for (auto const& dgst : missing_artifacts_info->digests) { - auto const& info = missing_artifacts_info->back_map[dgst]; + for (auto const& info : missing) { std::optional content; // Recursively process trees. - if (IsTreeObject(info.type)) { - auto tree = repo_config_.ReadTreeFromGitCAS(info.digest.hash()); + if (IsTreeObject(info->type)) { + auto tree = repo_config_.ReadTreeFromGitCAS(info->digest.hash()); if (not tree) { return false; } @@ -238,14 +241,14 @@ auto GitApi::RetrieveToCas( content = tree->RawData(); } else { - content = repo_config_.ReadBlobFromGitCAS(info.digest.hash()); + content = repo_config_.ReadBlobFromGitCAS(info->digest.hash()); } if (not content) { return false; } ArtifactDigest digest = - IsTreeObject(info.type) + IsTreeObject(info->type) ? ArtifactDigestFactory::HashDataAs( hash_function, *content) : ArtifactDigestFactory::HashDataAs( @@ -256,7 +259,7 @@ auto GitApi::RetrieveToCas( &container, ArtifactBlob{std::move(digest), std::move(*content), - IsExecutableObject(info.type)}, + IsExecutableObject(info->type)}, /*exception_is_fatal=*/true, [&api](std::unordered_set&& blobs) { return api.Upload(std::move(blobs), -- cgit v1.2.3