diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/fetch.cpp | 57 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup.cpp | 116 | ||||
-rw-r--r-- | src/other_tools/ops_maps/TARGETS | 3 | ||||
-rw-r--r-- | src/other_tools/ops_maps/archive_fetch_map.cpp | 32 | ||||
-rw-r--r-- | src/other_tools/ops_maps/archive_fetch_map.hpp | 5 | ||||
-rw-r--r-- | src/other_tools/ops_maps/content_cas_map.cpp | 37 | ||||
-rw-r--r-- | src/other_tools/ops_maps/content_cas_map.hpp | 5 | ||||
-rw-r--r-- | src/other_tools/ops_maps/git_tree_fetch_map.cpp | 65 | ||||
-rw-r--r-- | src/other_tools/ops_maps/git_tree_fetch_map.hpp | 5 | ||||
-rw-r--r-- | src/other_tools/root_maps/commit_git_map.cpp | 41 | ||||
-rw-r--r-- | src/other_tools/root_maps/commit_git_map.hpp | 5 | ||||
-rw-r--r-- | src/other_tools/root_maps/content_git_map.cpp | 9 | ||||
-rw-r--r-- | src/other_tools/root_maps/content_git_map.hpp | 5 | ||||
-rw-r--r-- | src/other_tools/root_maps/distdir_git_map.cpp | 8 | ||||
-rw-r--r-- | src/other_tools/root_maps/distdir_git_map.hpp | 5 |
15 files changed, 210 insertions, 188 deletions
diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp index a51307da..083284b9 100644 --- a/src/other_tools/just_mr/fetch.cpp +++ b/src/other_tools/just_mr/fetch.cpp @@ -456,8 +456,7 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, // setup the APIs for archive fetches auto remote_api = JustMR::Utils::GetRemoteApi( common_args.remote_execution_address, auth_args); - IExecutionApi::Ptr local_api{remote_api ? std::make_unique<LocalApi>() - : nullptr}; + IExecutionApi::Ptr local_api{std::make_unique<LocalApi>()}; // setup the API for serving trees of Git repos or archives auto serve_api_exists = JustMR::Utils::SetupServeApi( @@ -466,36 +465,42 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, // create async maps auto crit_git_op_ptr = std::make_shared<CriticalGitOpGuard>(); auto critical_git_op_map = CreateCriticalGitOpMap(crit_git_op_ptr); - auto content_cas_map = - CreateContentCASMap(common_args.just_mr_paths, - common_args.alternative_mirrors, - common_args.ca_info, - &critical_git_op_map, - serve_api_exists, - local_api ? &(*local_api) : nullptr, - remote_api ? &(*remote_api) : nullptr, - common_args.jobs); - auto archive_fetch_map = CreateArchiveFetchMap( - &content_cas_map, - *fetch_dir, - (fetch_args.backup_to_remote and local_api) ? &(*local_api) : nullptr, - (fetch_args.backup_to_remote and remote_api) ? &(*remote_api) : nullptr, + + auto content_cas_map = CreateContentCASMap( + common_args.just_mr_paths, + common_args.alternative_mirrors, + common_args.ca_info, + &critical_git_op_map, + serve_api_exists, + &(*local_api), + remote_api ? std::make_optional(&(*remote_api)) : std::nullopt, common_args.jobs); + + auto archive_fetch_map = + CreateArchiveFetchMap(&content_cas_map, + *fetch_dir, + &(*local_api), + (fetch_args.backup_to_remote and remote_api) + ? std::make_optional(&(*remote_api)) + : std::nullopt, + common_args.jobs); + auto import_to_git_map = CreateImportToGitMap(&critical_git_op_map, common_args.git_path->string(), *common_args.local_launcher, common_args.jobs); - auto git_tree_fetch_map = - CreateGitTreeFetchMap(&critical_git_op_map, - &import_to_git_map, - common_args.git_path->string(), - *common_args.local_launcher, - serve_api_exists, - local_api ? &(*local_api) : nullptr, - remote_api ? &(*remote_api) : nullptr, - fetch_args.backup_to_remote, - common_args.jobs); + + auto git_tree_fetch_map = CreateGitTreeFetchMap( + &critical_git_op_map, + &import_to_git_map, + common_args.git_path->string(), + *common_args.local_launcher, + serve_api_exists, + &(*local_api), + remote_api ? std::make_optional(&(*remote_api)) : std::nullopt, + fetch_args.backup_to_remote, + common_args.jobs); // set up progress observer JustMRProgress::Instance().SetTotal(static_cast<int>(nr_a + nr_gt)); diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp index e4d48086..22d4a04c 100644 --- a/src/other_tools/just_mr/setup.cpp +++ b/src/other_tools/just_mr/setup.cpp @@ -107,8 +107,7 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, // setup the APIs for archive fetches auto remote_api = JustMR::Utils::GetRemoteApi( common_args.remote_execution_address, auth_args); - IExecutionApi::Ptr local_api{remote_api ? std::make_unique<LocalApi>() - : nullptr}; + IExecutionApi::Ptr local_api{std::make_unique<LocalApi>()}; // setup the API for serving trees of Git repos or archives auto serve_api_exists = JustMR::Utils::SetupServeApi( @@ -117,57 +116,63 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, // setup the required async maps auto crit_git_op_ptr = std::make_shared<CriticalGitOpGuard>(); auto critical_git_op_map = CreateCriticalGitOpMap(crit_git_op_ptr); - auto content_cas_map = - CreateContentCASMap(common_args.just_mr_paths, - common_args.alternative_mirrors, - common_args.ca_info, - &critical_git_op_map, - serve_api_exists, - local_api ? &(*local_api) : nullptr, - remote_api ? &(*remote_api) : nullptr, - common_args.jobs); + + auto content_cas_map = CreateContentCASMap( + common_args.just_mr_paths, + common_args.alternative_mirrors, + common_args.ca_info, + &critical_git_op_map, + serve_api_exists, + &(*local_api), + remote_api ? std::make_optional(&(*remote_api)) : std::nullopt, + common_args.jobs); + auto import_to_git_map = CreateImportToGitMap(&critical_git_op_map, common_args.git_path->string(), *common_args.local_launcher, common_args.jobs); - auto git_tree_fetch_map = - CreateGitTreeFetchMap(&critical_git_op_map, - &import_to_git_map, - common_args.git_path->string(), - *common_args.local_launcher, - serve_api_exists, - local_api ? &(*local_api) : nullptr, - remote_api ? &(*remote_api) : nullptr, - false, /* backup_to_remote */ - common_args.jobs); + + auto git_tree_fetch_map = CreateGitTreeFetchMap( + &critical_git_op_map, + &import_to_git_map, + common_args.git_path->string(), + *common_args.local_launcher, + serve_api_exists, + &(*local_api), + remote_api ? std::make_optional(&(*remote_api)) : std::nullopt, + false, /* backup_to_remote */ + common_args.jobs); + auto resolve_symlinks_map = CreateResolveSymlinksMap(); - auto commit_git_map = - CreateCommitGitMap(&critical_git_op_map, - &import_to_git_map, - common_args.just_mr_paths, - common_args.alternative_mirrors, - common_args.git_path->string(), - *common_args.local_launcher, - serve_api_exists, - local_api ? &(*local_api) : nullptr, - remote_api ? &(*remote_api) : nullptr, - common_args.fetch_absent, - common_args.jobs); - auto content_git_map = - CreateContentGitMap(&content_cas_map, - &import_to_git_map, - common_args.just_mr_paths, - common_args.alternative_mirrors, - common_args.ca_info, - &resolve_symlinks_map, - &critical_git_op_map, - serve_api_exists, - local_api ? &(*local_api) : nullptr, - remote_api ? &(*remote_api) : nullptr, - common_args.fetch_absent, - common_args.jobs); + auto commit_git_map = CreateCommitGitMap( + &critical_git_op_map, + &import_to_git_map, + common_args.just_mr_paths, + common_args.alternative_mirrors, + common_args.git_path->string(), + *common_args.local_launcher, + serve_api_exists, + &(*local_api), + remote_api ? std::make_optional(&(*remote_api)) : std::nullopt, + common_args.fetch_absent, + common_args.jobs); + + auto content_git_map = CreateContentGitMap( + &content_cas_map, + &import_to_git_map, + common_args.just_mr_paths, + common_args.alternative_mirrors, + common_args.ca_info, + &resolve_symlinks_map, + &critical_git_op_map, + serve_api_exists, + &(*local_api), + remote_api ? std::make_optional(&(*remote_api)) : std::nullopt, + common_args.fetch_absent, + common_args.jobs); + auto fpath_git_map = CreateFilePathGitMap( just_cmd_args.subcmd_name, &critical_git_op_map, @@ -177,16 +182,19 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, multi_repo_tool_name, common_args.just_path ? common_args.just_path->string() : kDefaultJustPath); - auto distdir_git_map = - CreateDistdirGitMap(&content_cas_map, - &import_to_git_map, - &critical_git_op_map, - serve_api_exists, - local_api ? &(*local_api) : nullptr, - remote_api ? &(*remote_api) : nullptr, - common_args.jobs); + + auto distdir_git_map = CreateDistdirGitMap( + &content_cas_map, + &import_to_git_map, + &critical_git_op_map, + serve_api_exists, + &(*local_api), + remote_api ? std::make_optional(&(*remote_api)) : std::nullopt, + common_args.jobs); + auto tree_id_git_map = CreateTreeIdGitMap( &git_tree_fetch_map, common_args.fetch_absent, common_args.jobs); + auto repos_to_setup_map = CreateReposToSetupMap(config, main, interactive, diff --git a/src/other_tools/ops_maps/TARGETS b/src/other_tools/ops_maps/TARGETS index d20de15c..9c708f33 100644 --- a/src/other_tools/ops_maps/TARGETS +++ b/src/other_tools/ops_maps/TARGETS @@ -59,7 +59,8 @@ , "hdrs": ["content_cas_map.hpp"] , "srcs": ["content_cas_map.cpp"] , "deps": - [ ["src/buildtool/common", "user_structs"] + [ ["@", "gsl", "", "gsl"] + , ["src/buildtool/common", "user_structs"] , ["src/buildtool/file_system/symlinks_map", "pragma_special"] , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/multithreading", "async_map_consumer"] diff --git a/src/other_tools/ops_maps/archive_fetch_map.cpp b/src/other_tools/ops_maps/archive_fetch_map.cpp index c91cdcf9..f2b5842b 100644 --- a/src/other_tools/ops_maps/archive_fetch_map.cpp +++ b/src/other_tools/ops_maps/archive_fetch_map.cpp @@ -26,20 +26,21 @@ namespace { -void ProcessContent(std::filesystem::path const& content_path, - std::filesystem::path const& target_name, - IExecutionApi* local_api, - IExecutionApi* remote_api, - std::string const& content, - ArtifactDigest const& digest, - ArchiveFetchMap::SetterPtr const& setter, - ArchiveFetchMap::LoggerPtr const& logger) { +void ProcessContent( + std::filesystem::path const& content_path, + std::filesystem::path const& target_name, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, + std::string const& content, + ArtifactDigest const& digest, + ArchiveFetchMap::SetterPtr const& setter, + ArchiveFetchMap::LoggerPtr const& logger) { // try to back up to remote CAS - if (local_api != nullptr and remote_api != nullptr) { + if (remote_api) { if (not local_api->RetrieveToCas( {Artifact::ObjectInfo{.digest = digest, .type = ObjectType::File}}, - remote_api)) { + *remote_api)) { // give a warning (*logger)(fmt::format("Failed to back up content {} from local CAS " "to remote", @@ -67,11 +68,12 @@ void ProcessContent(std::filesystem::path const& content_path, } // namespace -auto CreateArchiveFetchMap(gsl::not_null<ContentCASMap*> const& content_cas_map, - std::filesystem::path const& fetch_dir, - IExecutionApi* local_api, - IExecutionApi* remote_api, - std::size_t jobs) -> ArchiveFetchMap { +auto CreateArchiveFetchMap( + gsl::not_null<ContentCASMap*> const& content_cas_map, + std::filesystem::path const& fetch_dir, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, + std::size_t jobs) -> ArchiveFetchMap { auto fetch_archive = [content_cas_map, fetch_dir, local_api, remote_api]( auto ts, auto setter, diff --git a/src/other_tools/ops_maps/archive_fetch_map.hpp b/src/other_tools/ops_maps/archive_fetch_map.hpp index 656f2100..89550996 100644 --- a/src/other_tools/ops_maps/archive_fetch_map.hpp +++ b/src/other_tools/ops_maps/archive_fetch_map.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_OTHER_TOOLS_OPS_MAPS_ARCHIVE_FETCH_MAP_HPP #include <filesystem> +#include <optional> #include "gsl/gsl" #include "src/buildtool/execution_api/common/execution_api.hpp" @@ -27,8 +28,8 @@ using ArchiveFetchMap = AsyncMapConsumer<ArchiveRepoInfo, bool>; [[nodiscard]] auto CreateArchiveFetchMap( gsl::not_null<ContentCASMap*> const& content_cas_map, std::filesystem::path const& fetch_dir, // should exist! - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, std::size_t jobs) -> ArchiveFetchMap; #endif // INCLUDED_SRC_OTHER_TOOLS_OPS_MAPS_ARCHIVE_FETCH_MAP_HPP
\ No newline at end of file diff --git a/src/other_tools/ops_maps/content_cas_map.cpp b/src/other_tools/ops_maps/content_cas_map.cpp index 65449d97..7fe4efef 100644 --- a/src/other_tools/ops_maps/content_cas_map.cpp +++ b/src/other_tools/ops_maps/content_cas_map.cpp @@ -28,18 +28,18 @@ namespace { -void CheckRemoteAndFetchFromNetwork(ArchiveContent const& key, - ArtifactDigest const& digest, - MirrorsPtr const& additional_mirrors, - CAInfoPtr const& ca_info, - IExecutionApi* local_api, - IExecutionApi* remote_api, - ContentCASMap::SetterPtr const& setter, - ContentCASMap::LoggerPtr const& logger) { +void CheckRemoteAndFetchFromNetwork( + ArchiveContent const& key, + ArtifactDigest const& digest, + MirrorsPtr const& additional_mirrors, + CAInfoPtr const& ca_info, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, + ContentCASMap::SetterPtr const& setter, + ContentCASMap::LoggerPtr const& logger) { // check if content is in remote CAS, if a remote is given - if (remote_api != nullptr and local_api != nullptr and - remote_api->IsAvailable(digest) and - remote_api->RetrieveToCas( + if (remote_api and + remote_api.value()->RetrieveToCas( {Artifact::ObjectInfo{.digest = digest, .type = ObjectType::File}}, local_api)) { JustMRProgress::Instance().TaskTracker().Stop(key.origin); @@ -123,8 +123,8 @@ auto CreateContentCASMap( CAInfoPtr const& ca_info, gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, std::size_t jobs) -> ContentCASMap { auto ensure_in_cas = [just_mr_paths, additional_mirrors, @@ -238,12 +238,11 @@ auto CreateContentCASMap( if (serve_api_exists and ServeApi::ContentInRemoteCAS(key.content)) { // try to get content from remote CAS - if (remote_api != nullptr and local_api != nullptr and - remote_api->RetrieveToCas( - {Artifact::ObjectInfo{ - .digest = digest, - .type = ObjectType::File}}, - local_api)) { + if (remote_api and remote_api.value()->RetrieveToCas( + {Artifact::ObjectInfo{ + .digest = digest, + .type = ObjectType::File}}, + local_api)) { JustMRProgress::Instance().TaskTracker().Stop( key.origin); (*setter)(nullptr); diff --git a/src/other_tools/ops_maps/content_cas_map.hpp b/src/other_tools/ops_maps/content_cas_map.hpp index 13c20387..206970fb 100644 --- a/src/other_tools/ops_maps/content_cas_map.hpp +++ b/src/other_tools/ops_maps/content_cas_map.hpp @@ -19,6 +19,7 @@ #include <string> #include <vector> +#include "gsl/gsl" #include "src/buildtool/common/user_structs.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" @@ -72,8 +73,8 @@ using ContentCASMap = AsyncMapConsumer<ArchiveContent, std::nullptr_t>; CAInfoPtr const& ca_info, gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, std::size_t jobs) -> ContentCASMap; namespace std { diff --git a/src/other_tools/ops_maps/git_tree_fetch_map.cpp b/src/other_tools/ops_maps/git_tree_fetch_map.cpp index 990f374b..00e0b1b4 100644 --- a/src/other_tools/ops_maps/git_tree_fetch_map.cpp +++ b/src/other_tools/ops_maps/git_tree_fetch_map.cpp @@ -33,7 +33,7 @@ namespace { void BackupToRemote(std::string const& tree_id, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& remote_api, GitTreeFetchMap::LoggerPtr const& logger) { // try to back up to remote CAS auto repo = RepositoryConfig{}; @@ -59,15 +59,18 @@ void BackupToRemote(std::string const& tree_id, } } -void MoveCASTreeToGit(std::string const& tree_id, - ArtifactDigest const& digest, - gsl::not_null<ImportToGitMap*> const& import_to_git_map, - IExecutionApi* local_api, - IExecutionApi* remote_api, - bool do_backup, - gsl::not_null<TaskSystem*> const& ts, - GitTreeFetchMap::SetterPtr const& setter, - GitTreeFetchMap::LoggerPtr const& logger) { +/// \brief Moves the root tree from local CAS to the Git cache and sets the +/// root. +void MoveCASTreeToGit( + std::string const& tree_id, + ArtifactDigest const& digest, + gsl::not_null<ImportToGitMap*> const& import_to_git_map, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, + bool backup_to_remote, + gsl::not_null<TaskSystem*> const& ts, + GitTreeFetchMap::SetterPtr const& setter, + GitTreeFetchMap::LoggerPtr const& logger) { // Move tree from CAS to local Git storage auto tmp_dir = StorageUtils::CreateTypedTmpDir("fetch-remote-git-tree"); if (not tmp_dir) { @@ -93,7 +96,7 @@ void MoveCASTreeToGit(std::string const& tree_id, [tmp_dir, // keep tmp_dir alive tree_id, remote_api, - do_backup, + backup_to_remote, setter, logger](auto const& values) { if (not values[0]->second) { @@ -101,8 +104,8 @@ void MoveCASTreeToGit(std::string const& tree_id, /*fatal=*/true); return; } - if (do_backup) { - BackupToRemote(tree_id, remote_api, logger); + if (backup_to_remote and remote_api != std::nullopt) { + BackupToRemote(tree_id, *remote_api, logger); } (*setter)(false /*no cache hit*/); }, @@ -124,8 +127,8 @@ auto CreateGitTreeFetchMap( std::string const& git_bin, std::vector<std::string> const& launcher, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, bool backup_to_remote, std::size_t jobs) -> GitTreeFetchMap { auto tree_to_cache = [critical_git_op_map, @@ -199,8 +202,8 @@ auto CreateGitTreeFetchMap( } if (*tree_found) { // backup to remote, if needed - if (backup_to_remote and remote_api != nullptr) { - BackupToRemote(key.hash, remote_api, logger); + if (backup_to_remote and remote_api != std::nullopt) { + BackupToRemote(key.hash, *remote_api, logger); } // success (*setter)(true /*cache hit*/); @@ -211,16 +214,15 @@ auto CreateGitTreeFetchMap( auto const& cas = Storage::Instance().CAS(); if (auto path = cas.TreePath(digest)) { // import tree to Git cache - MoveCASTreeToGit( - key.hash, - digest, - import_to_git_map, - local_api, - remote_api, - (backup_to_remote and remote_api != nullptr), - ts, - setter, - logger); + MoveCASTreeToGit(key.hash, + digest, + import_to_git_map, + local_api, + remote_api, + backup_to_remote, + ts, + setter, + logger); // done! return; } @@ -234,9 +236,8 @@ auto CreateGitTreeFetchMap( ServeApi::TreeInRemoteCAS(key.hash); } // check if tree is in remote CAS, if a remote is given - if (remote_api != nullptr and local_api != nullptr and - remote_api->IsAvailable(digest) and - remote_api->RetrieveToCas( + if (remote_api and + remote_api.value()->RetrieveToCas( {Artifact::ObjectInfo{.digest = digest, .type = ObjectType::Tree}}, local_api)) { @@ -462,9 +463,9 @@ auto CreateGitTreeFetchMap( key.origin); // backup to remote, if needed if (backup_to_remote and - remote_api != nullptr) { + remote_api != std::nullopt) { BackupToRemote( - key.hash, remote_api, logger); + key.hash, *remote_api, logger); } // success (*setter)(false /*no cache hit*/); diff --git a/src/other_tools/ops_maps/git_tree_fetch_map.hpp b/src/other_tools/ops_maps/git_tree_fetch_map.hpp index e5cab5fa..1b012a2a 100644 --- a/src/other_tools/ops_maps/git_tree_fetch_map.hpp +++ b/src/other_tools/ops_maps/git_tree_fetch_map.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_OTHER_TOOLS_OPS_MAPS_GIT_TREE_FETCH_MAP_HPP #include <map> +#include <optional> #include <string> #include <vector> @@ -58,8 +59,8 @@ using GitTreeFetchMap = AsyncMapConsumer<GitTreeInfo, bool>; std::string const& git_bin, std::vector<std::string> const& launcher, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, bool backup_to_remote, std::size_t jobs) -> GitTreeFetchMap; diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp index 0461f474..c17550f0 100644 --- a/src/other_tools/root_maps/commit_git_map.cpp +++ b/src/other_tools/root_maps/commit_git_map.cpp @@ -88,22 +88,23 @@ void WriteIdFileAndSetWSRoot(std::string const& root_tree_id, false)); } -void EnsureCommit(GitRepoInfo const& repo_info, - std::filesystem::path const& repo_root, - std::string const& fetch_repo, - MirrorsPtr const& additional_mirrors, - GitCASPtr const& git_cas, - gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, - gsl::not_null<ImportToGitMap*> const& import_to_git_map, - std::string const& git_bin, - std::vector<std::string> const& launcher, - bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, - bool fetch_absent, - gsl::not_null<TaskSystem*> const& ts, - CommitGitMap::SetterPtr const& ws_setter, - CommitGitMap::LoggerPtr const& logger) { +void EnsureCommit( + GitRepoInfo const& repo_info, + std::filesystem::path const& repo_root, + std::string const& fetch_repo, + MirrorsPtr const& additional_mirrors, + GitCASPtr const& git_cas, + gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, + gsl::not_null<ImportToGitMap*> const& import_to_git_map, + std::string const& git_bin, + std::vector<std::string> const& launcher, + bool serve_api_exists, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, + bool fetch_absent, + gsl::not_null<TaskSystem*> const& ts, + CommitGitMap::SetterPtr const& ws_setter, + CommitGitMap::LoggerPtr const& logger) { // ensure commit exists, and fetch if needed auto git_repo = GitRepoRemote::Open(git_cas); // link fake repo to odb if (not git_repo) { @@ -242,8 +243,8 @@ void EnsureCommit(GitRepoInfo const& repo_info, // try to get root tree from remote execution endpoint auto root_digest = ArtifactDigest{*root_tree_id, 0, /*is_tree=*/true}; - if (remote_api != nullptr and local_api != nullptr and - remote_api->RetrieveToCas( + if (remote_api and + remote_api.value()->RetrieveToCas( {Artifact::ObjectInfo{.digest = root_digest, .type = ObjectType::Tree}}, local_api)) { @@ -672,8 +673,8 @@ auto CreateCommitGitMap( std::string const& git_bin, std::vector<std::string> const& launcher, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, bool fetch_absent, std::size_t jobs) -> CommitGitMap { auto commit_to_git = [critical_git_op_map, diff --git a/src/other_tools/root_maps/commit_git_map.hpp b/src/other_tools/root_maps/commit_git_map.hpp index 348e5e11..949b0dd1 100644 --- a/src/other_tools/root_maps/commit_git_map.hpp +++ b/src/other_tools/root_maps/commit_git_map.hpp @@ -15,6 +15,7 @@ #ifndef INCLUDED_SRC_OTHER_TOOLS_ROOT_MAPS_COMMIT_GIT_MAP_HPP #define INCLUDED_SRC_OTHER_TOOLS_ROOT_MAPS_COMMIT_GIT_MAP_HPP +#include <optional> #include <string> #include <utility> #include <vector> @@ -77,8 +78,8 @@ using CommitGitMap = std::string const& git_bin, std::vector<std::string> const& launcher, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, bool fetch_absent, std::size_t jobs) -> CommitGitMap; diff --git a/src/other_tools/root_maps/content_git_map.cpp b/src/other_tools/root_maps/content_git_map.cpp index 6f4a08bc..e7361af4 100644 --- a/src/other_tools/root_maps/content_git_map.cpp +++ b/src/other_tools/root_maps/content_git_map.cpp @@ -310,8 +310,8 @@ auto CreateContentGitMap( gsl::not_null<ResolveSymlinksMap*> const& resolve_symlinks_map, gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, bool fetch_absent, std::size_t jobs) -> ContentGitMap { auto gitify_content = [content_cas_map, @@ -656,9 +656,8 @@ auto CreateContentGitMap( // endpoint auto root_digest = ArtifactDigest{ *root_tree_id, 0, /*is_tree=*/true}; - if (remote_api != nullptr and - local_api != nullptr and - remote_api->RetrieveToCas( + if (remote_api and + remote_api.value()->RetrieveToCas( {Artifact::ObjectInfo{ .digest = root_digest, .type = ObjectType::Tree}}, diff --git a/src/other_tools/root_maps/content_git_map.hpp b/src/other_tools/root_maps/content_git_map.hpp index 2b894d27..4fa4807b 100644 --- a/src/other_tools/root_maps/content_git_map.hpp +++ b/src/other_tools/root_maps/content_git_map.hpp @@ -15,6 +15,7 @@ #ifndef INCLUDED_SRC_OTHER_TOOLS_ROOT_MAPS_CONTENT_GIT_MAP_HPP #define INCLUDED_SRC_OTHER_TOOLS_ROOT_MAPS_CONTENT_GIT_MAP_HPP +#include <optional> #include <utility> #include "gsl/gsl" @@ -40,8 +41,8 @@ using ContentGitMap = gsl::not_null<ResolveSymlinksMap*> const& resolve_symlinks_map, gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, bool fetch_absent, std::size_t jobs) -> ContentGitMap; diff --git a/src/other_tools/root_maps/distdir_git_map.cpp b/src/other_tools/root_maps/distdir_git_map.cpp index 6fa9d2d2..1f6a1573 100644 --- a/src/other_tools/root_maps/distdir_git_map.cpp +++ b/src/other_tools/root_maps/distdir_git_map.cpp @@ -131,8 +131,8 @@ auto CreateDistdirGitMap( gsl::not_null<ImportToGitMap*> const& import_to_git_map, gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, std::size_t jobs) -> DistdirGitMap { auto distdir_to_git = [content_cas_map, import_to_git_map, @@ -258,8 +258,8 @@ auto CreateDistdirGitMap( ArtifactDigest{kv.second, 0, /*is_tree=*/false}, .type = ObjectType::File}); } - if (remote_api != nullptr and local_api != nullptr and - remote_api->RetrieveToCas(objects, local_api)) { + if (remote_api and + remote_api.value()->RetrieveToCas(objects, local_api)) { ImportFromCASAndSetRoot(key.content_list, key.content_id, distdir_tree_id_file, diff --git a/src/other_tools/root_maps/distdir_git_map.hpp b/src/other_tools/root_maps/distdir_git_map.hpp index df2b6064..bfdf02df 100644 --- a/src/other_tools/root_maps/distdir_git_map.hpp +++ b/src/other_tools/root_maps/distdir_git_map.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_OTHER_TOOLS_ROOT_MAPS_DISTDIR_GIT_MAP_HPP #include <memory> +#include <optional> #include <string> #include <unordered_map> #include <utility> @@ -52,8 +53,8 @@ using DistdirGitMap = gsl::not_null<ImportToGitMap*> const& import_to_git_map, gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, bool serve_api_exists, - IExecutionApi* local_api, - IExecutionApi* remote_api, + gsl::not_null<IExecutionApi*> const& local_api, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, std::size_t jobs) -> DistdirGitMap; namespace std { |