diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/root_maps/TARGETS | 6 | ||||
-rw-r--r-- | src/other_tools/root_maps/commit_git_map.cpp | 16 | ||||
-rw-r--r-- | src/other_tools/root_maps/distdir_git_map.cpp | 28 | ||||
-rw-r--r-- | src/other_tools/root_maps/root_utils.cpp | 14 |
4 files changed, 45 insertions, 19 deletions
diff --git a/src/other_tools/root_maps/TARGETS b/src/other_tools/root_maps/TARGETS index 84eef4a5..68d1ba5b 100644 --- a/src/other_tools/root_maps/TARGETS +++ b/src/other_tools/root_maps/TARGETS @@ -29,6 +29,8 @@ , ["src/other_tools/just_mr/progress_reporting", "progress"] , ["src/other_tools/just_mr/progress_reporting", "statistics"] , ["src/utils/cpp", "tmp_dir"] + , ["src/buildtool/common", "artifact_digest_factory"] + , ["src/buildtool/crypto", "hash_function"] ] } , "commit_git_map": @@ -61,6 +63,8 @@ , ["src/other_tools/git_operations", "git_repo_remote"] , ["src/other_tools/utils", "curl_url_handle"] , ["src/utils/cpp", "tmp_dir"] + , ["src/buildtool/common", "artifact_digest_factory"] + , ["src/buildtool/crypto", "hash_function"] ] } , "fpath_git_map": @@ -199,6 +203,8 @@ , ["src/buildtool/common", "config"] , ["src/buildtool/execution_api/git", "git"] , ["src/buildtool/file_system", "object_type"] + , ["src/buildtool/common", "artifact_digest_factory"] + , ["src/buildtool/crypto", "hash_function"] ] } } diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp index 2d64d599..e6463d57 100644 --- a/src/other_tools/root_maps/commit_git_map.cpp +++ b/src/other_tools/root_maps/commit_git_map.cpp @@ -19,6 +19,8 @@ #include <string> #include "fmt/core.h" +#include "src/buildtool/common/artifact_digest_factory.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/multithreading/task_system.hpp" @@ -851,12 +853,16 @@ void EnsureCommit(GitRepoInfo const& repo_info, } // try to get root tree from remote CAS - auto root_digest = ArtifactDigest{ - root_tree_id, 0, /*is_tree=*/true}; - if (remote_api != nullptr and + auto const root_digest = + ArtifactDigestFactory::Create( + storage_config->hash_function.GetType(), + root_tree_id, + 0, + /*is_tree=*/true); + if (remote_api != nullptr and root_digest and remote_api->RetrieveToCas( {Artifact::ObjectInfo{ - .digest = root_digest, + .digest = *root_digest, .type = ObjectType::Tree}}, *local_api)) { progress->TaskTracker().Stop(repo_info.origin); @@ -877,7 +883,7 @@ void EnsureCommit(GitRepoInfo const& repo_info, } if (not local_api->RetrieveToPaths( {Artifact::ObjectInfo{ - .digest = root_digest, + .digest = *root_digest, .type = ObjectType::Tree}}, {tmp_dir->GetPath()})) { (*logger)(fmt::format( diff --git a/src/other_tools/root_maps/distdir_git_map.cpp b/src/other_tools/root_maps/distdir_git_map.cpp index 4a7e9b51..455dd25b 100644 --- a/src/other_tools/root_maps/distdir_git_map.cpp +++ b/src/other_tools/root_maps/distdir_git_map.cpp @@ -19,6 +19,8 @@ #include "fmt/core.h" #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/execution_common.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/file_storage.hpp" @@ -46,9 +48,16 @@ namespace { content_list->begin(), content_list->end(), [&cas, tmp_dir](auto const& kv) { - auto content_path = - cas.BlobPath(ArtifactDigest(kv.second, 0, false), - /*is_executable=*/false); + auto const digest = + ArtifactDigestFactory::Create(cas.GetHashFunction().GetType(), + kv.second, + 0, + /*is_tree=*/false); + if (not digest) { + return false; + } + auto content_path = cas.BlobPath(*digest, + /*is_executable=*/false); if (content_path) { return FileSystemManager::CreateFileHardlink( *content_path, // from: cas_path/content_id @@ -329,9 +338,10 @@ auto CreateDistdirGitMap( return; } // get hash from raw_id - auto tree_id = ToHexString(tree->first); + auto const tree_id = ToHexString(tree->first); // get digest object - auto digest = ArtifactDigest{tree_id, 0, /*is_tree=*/true}; + auto const digest = ArtifactDigestFactory::Create( + HashFunction::Type::GitSHA1, tree_id, 0, /*is_tree=*/false); // use this knowledge of the resulting tree identifier to try to set // up the absent root without actually checking the local status of @@ -398,7 +408,7 @@ auto CreateDistdirGitMap( } // try to supply the serve endpoint with the tree via the // remote CAS - if (remote_api->IsAvailable({digest})) { + if (digest and remote_api->IsAvailable({*digest})) { // tell serve to set up the root from the remote CAS // tree; upload can be skipped if (EnsureAbsentRootOnServe( @@ -424,10 +434,10 @@ auto CreateDistdirGitMap( } // check if we have the tree in local CAS; if yes, upload it // to remote for the serve endpoint to find it - if (local_api->IsAvailable({digest})) { + if (digest and local_api->IsAvailable({*digest})) { if (not local_api->RetrieveToCas( {Artifact::ObjectInfo{ - .digest = digest, + .digest = *digest, .type = ObjectType::Tree}}, *remote_api)) { (*logger)(fmt::format("Failed to sync tree {} from " @@ -475,7 +485,7 @@ auto CreateDistdirGitMap( // if the root is not-absent, the order of checks is different; // first, look in the local CAS - if (local_api->IsAvailable({digest})) { + if (digest and local_api->IsAvailable({*digest})) { ImportFromCASAndSetRoot(key, *storage_config, *storage, diff --git a/src/other_tools/root_maps/root_utils.cpp b/src/other_tools/root_maps/root_utils.cpp index 6e77cae8..4173a00d 100644 --- a/src/other_tools/root_maps/root_utils.cpp +++ b/src/other_tools/root_maps/root_utils.cpp @@ -17,7 +17,9 @@ #include "fmt/core.h" #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/git/git_api.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -50,12 +52,14 @@ auto EnsureAbsentRootOnServe(ServeApi const& serve, /*fatal=*/true); return false; } + auto const digest = ArtifactDigestFactory::Create( + HashFunction::Type::GitSHA1, tree_id, 0, /*is_tree=*/true); + auto git_api = GitApi{&repo}; - if (not git_api.RetrieveToCas( - {Artifact::ObjectInfo{ - .digest = ArtifactDigest{tree_id, 0, /*is_tree=*/true}, - .type = ObjectType::Tree}}, - *remote_api)) { + if (not digest or not git_api.RetrieveToCas( + {Artifact::ObjectInfo{.digest = *digest, + .type = ObjectType::Tree}}, + *remote_api)) { (*logger)(fmt::format("Failed to sync tree {} from repository {}", tree_id, repo_path.string()), |