diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-27 11:56:07 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-28 13:44:06 +0100 |
commit | 44fd3fdabe70aa0961b7b0114248a5d9ac633f71 (patch) | |
tree | 22555764af5dc9166754952b17c95b0a505be1c4 | |
parent | 73736390a01d792580e9f9081676b7f2dae20ff4 (diff) | |
download | justbuild-44fd3fdabe70aa0961b7b0114248a5d9ac633f71.tar.gz |
TreeIdGitMap: Use ServeApi::UploadTree
-rw-r--r-- | src/other_tools/root_maps/TARGETS | 3 | ||||
-rw-r--r-- | src/other_tools/root_maps/tree_id_git_map.cpp | 46 |
2 files changed, 10 insertions, 39 deletions
diff --git a/src/other_tools/root_maps/TARGETS b/src/other_tools/root_maps/TARGETS index dcbd8b2b..b49d662d 100644 --- a/src/other_tools/root_maps/TARGETS +++ b/src/other_tools/root_maps/TARGETS @@ -202,13 +202,12 @@ , "private-deps": [ ["@", "fmt", "", "fmt"] , ["src/buildtool/common", "common"] - , ["src/buildtool/common", "config"] - , ["src/buildtool/execution_api/serve", "mr_git_api"] , ["src/buildtool/file_system", "file_root"] , ["src/buildtool/file_system", "object_type"] , ["src/buildtool/multithreading", "task_system"] , ["src/other_tools/git_operations", "git_ops_types"] , ["src/other_tools/git_operations", "git_repo_remote"] + , ["src/utils/cpp", "expected"] , ["src/utils/cpp", "tmp_dir"] ] } diff --git a/src/other_tools/root_maps/tree_id_git_map.cpp b/src/other_tools/root_maps/tree_id_git_map.cpp index f6fac1d0..e99bf8d9 100644 --- a/src/other_tools/root_maps/tree_id_git_map.cpp +++ b/src/other_tools/root_maps/tree_id_git_map.cpp @@ -23,13 +23,12 @@ #include "fmt/core.h" #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/common/artifact_digest.hpp" -#include "src/buildtool/common/repository_config.hpp" -#include "src/buildtool/execution_api/serve/mr_git_api.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/multithreading/task_system.hpp" #include "src/other_tools/git_operations/git_ops_types.hpp" #include "src/other_tools/git_operations/git_repo_remote.hpp" +#include "src/utils/cpp/expected.hpp" #include "src/utils/cpp/tmp_dir.hpp" namespace { @@ -39,51 +38,24 @@ namespace { void UploadToServeAndSetRoot( ServeApi const& serve, gsl::not_null<StorageConfig const*> const& native_storage_config, - StorageConfig const* compat_storage_config, - std::string const& tree_id, + StorageConfig const* /*compat_storage_config*/, + std::string const& /*tree_id*/, ArtifactDigest const& digest, - gsl::not_null<IExecutionApi const*> const& local_api, - IExecutionApi const& remote_api, + gsl::not_null<IExecutionApi const*> const& /*local_api*/, + IExecutionApi const& /*remote_api*/, bool ignore_special, TreeIdGitMap::SetterPtr const& setter, TreeIdGitMap::LoggerPtr const& logger) { - // upload to remote CAS - auto repo_config = RepositoryConfig{}; - if (repo_config.SetGitCAS(native_storage_config->GitRoot())) { - auto git_api = - MRGitApi{&repo_config, - native_storage_config, - compat_storage_config, - compat_storage_config != nullptr ? &*local_api : nullptr}; - if (not git_api.RetrieveToCas( - {Artifact::ObjectInfo{.digest = digest, - .type = ObjectType::Tree}}, - remote_api)) { - (*logger)(fmt::format("Failed to sync tree {} from local Git cache " - "to remote CAS", - tree_id), - /*fatal=*/true); - return; - } - } - else { - (*logger)(fmt::format("Failed to SetGitCAS at {}", - native_storage_config->GitRoot().string()), - /*fatal=*/true); - return; - } - // tell serve to set up the root from the remote CAS tree; - if (not serve.GetTreeFromRemote(digest)) { - (*logger)( - fmt::format("Serve endpoint failed to sync root tree {}.", tree_id), - /*fatal=*/true); + auto uploaded = serve.UploadTree(digest, native_storage_config->GitRoot()); + if (not uploaded.has_value()) { + (*logger)(uploaded.error().Message(), /*fatal=*/true); return; } // set workspace root as absent auto root = nlohmann::json::array( {ignore_special ? FileRoot::kGitTreeIgnoreSpecialMarker : FileRoot::kGitTreeMarker, - tree_id}); + digest.hash()}); (*setter)(std::pair(std::move(root), /*is_cache_hit=*/false)); } |