diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-06-26 16:07:58 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-05 12:58:35 +0200 |
commit | 5bc6265b2ffe43370b4cddd0a9e4c09b059ef131 (patch) | |
tree | 63619c3d43f97c4ffa16feb9094fc8631620b164 /src | |
parent | 3440784e94de51c95d3dcca8509f8e46b4722ee6 (diff) | |
download | justbuild-5bc6265b2ffe43370b4cddd0a9e4c09b059ef131.tar.gz |
Pass StorageConfig to git_repo and git_repo_remote
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/file_system/TARGETS | 2 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 7 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 2 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/source_tree.cpp | 3 | ||||
-rw-r--r-- | src/other_tools/git_operations/TARGETS | 6 | ||||
-rw-r--r-- | src/other_tools/git_operations/git_repo_remote.cpp | 9 | ||||
-rw-r--r-- | src/other_tools/git_operations/git_repo_remote.hpp | 3 | ||||
-rw-r--r-- | src/other_tools/ops_maps/TARGETS | 1 | ||||
-rw-r--r-- | src/other_tools/ops_maps/git_tree_fetch_map.cpp | 1 | ||||
-rw-r--r-- | src/other_tools/ops_maps/git_update_map.cpp | 15 | ||||
-rw-r--r-- | src/other_tools/ops_maps/import_to_git_map.cpp | 1 | ||||
-rw-r--r-- | src/other_tools/root_maps/commit_git_map.cpp | 3 |
12 files changed, 34 insertions, 19 deletions
diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS index 51a8e077..82ddce24 100644 --- a/src/buildtool/file_system/TARGETS +++ b/src/buildtool/file_system/TARGETS @@ -118,6 +118,7 @@ , "git_types" , ["src/buildtool/common", "bazel_types"] , ["src/utils/cpp", "expected"] + , ["src/buildtool/storage", "config"] ] , "stage": ["src", "buildtool", "file_system"] , "private-deps": @@ -129,7 +130,6 @@ , ["src/utils/cpp", "gsl"] , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/common", "common"] - , ["src/buildtool/storage", "config"] ] , "cflags": ["-pthread"] } diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index 93c763ae..79708d2c 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -23,7 +23,6 @@ #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" -#include "src/buildtool/storage/config.hpp" #include "src/utils/cpp/gsl.hpp" #include "src/utils/cpp/hex_string.hpp" #include "src/utils/cpp/path.hpp" @@ -1701,7 +1700,8 @@ auto GitRepo::GetObjectByPathFromTree(std::string const& tree_id, #endif // BOOTSTRAP_BUILD_TOOL } -auto GitRepo::LocalFetchViaTmpRepo(std::string const& repo_path, +auto GitRepo::LocalFetchViaTmpRepo(StorageConfig const& storage_config, + std::string const& repo_path, std::optional<std::string> const& branch, anon_logger_ptr const& logger) noexcept -> bool { @@ -1714,8 +1714,7 @@ auto GitRepo::LocalFetchViaTmpRepo(std::string const& repo_path, Logger::Log(LogLevel::Debug, "Branch local fetch called on a real repository"); } - auto tmp_dir = - StorageConfig::Instance().CreateTypedTmpDir("local_fetch"); + auto tmp_dir = storage_config.CreateTypedTmpDir("local_fetch"); if (not tmp_dir) { (*logger)("Failed to create temp dir for Git repository", /*fatal=*/true); diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index d43a85ec..2a4a4238 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -26,6 +26,7 @@ #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/file_system/git_cas.hpp" #include "src/buildtool/file_system/git_types.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/utils/cpp/expected.hpp" extern "C" { @@ -293,6 +294,7 @@ class GitRepo { /// Returns a success flag. /// It guarantees the logger is called exactly once with fatal if failure. [[nodiscard]] auto LocalFetchViaTmpRepo( + StorageConfig const& storage_config, std::string const& repo_path, std::optional<std::string> const& branch, anon_logger_ptr const& logger) noexcept -> bool; diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp index 75dab8c2..0abfef83 100644 --- a/src/buildtool/serve_api/serve_service/source_tree.cpp +++ b/src/buildtool/serve_api/serve_service/source_tree.cpp @@ -546,7 +546,8 @@ auto SourceTreeService::CommonImportToGit( }); // fetch the new commit into the Git CAS via tmp directory; the call is // thread-safe, so it needs no guarding - if (not just_git_repo->LocalFetchViaTmpRepo(root_path.string(), + if (not just_git_repo->LocalFetchViaTmpRepo(StorageConfig::Instance(), + root_path.string(), /*branch=*/std::nullopt, wrapped_logger)) { return unexpected{err}; diff --git a/src/other_tools/git_operations/TARGETS b/src/other_tools/git_operations/TARGETS index 9d14f4bc..9a6aed5e 100644 --- a/src/other_tools/git_operations/TARGETS +++ b/src/other_tools/git_operations/TARGETS @@ -26,13 +26,15 @@ , "name": ["git_repo_remote"] , "hdrs": ["git_repo_remote.hpp"] , "srcs": ["git_repo_remote.cpp"] - , "deps": [["src/buildtool/file_system", "git_repo"]] + , "deps": + [ ["src/buildtool/file_system", "git_repo"] + , ["src/buildtool/storage", "config"] + ] , "stage": ["src", "other_tools", "git_operations"] , "private-deps": [ ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] , ["src/buildtool/file_system", "git_utils"] - , ["src/buildtool/storage", "config"] , ["@", "fmt", "", "fmt"] , ["", "libgit2"] , ["@", "json", "", "json"] diff --git a/src/other_tools/git_operations/git_repo_remote.cpp b/src/other_tools/git_operations/git_repo_remote.cpp index 80a2f956..00114b50 100644 --- a/src/other_tools/git_operations/git_repo_remote.cpp +++ b/src/other_tools/git_operations/git_repo_remote.cpp @@ -22,7 +22,6 @@ #include "src/buildtool/file_system/git_utils.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" -#include "src/buildtool/storage/config.hpp" #include "src/buildtool/system/system_command.hpp" #include "src/other_tools/git_operations/git_config_settings.hpp" @@ -397,6 +396,7 @@ auto GitRepoRemote::FetchFromRemote(std::shared_ptr<git_config> cfg, } auto GitRepoRemote::UpdateCommitViaTmpRepo( + StorageConfig const& storage_config, std::string const& repo_url, std::string const& branch, std::vector<std::string> const& inherit_env, @@ -405,7 +405,7 @@ auto GitRepoRemote::UpdateCommitViaTmpRepo( anon_logger_ptr const& logger) const noexcept -> std::optional<std::string> { try { - auto tmp_dir = StorageConfig::Instance().CreateTypedTmpDir("update"); + auto tmp_dir = storage_config.CreateTypedTmpDir("update"); if (not tmp_dir) { (*logger)("Failed to create temp dir for running 'git ls-remote'", /*fatal=*/true); @@ -532,7 +532,8 @@ auto GitRepoRemote::UpdateCommitViaTmpRepo( } } -auto GitRepoRemote::FetchViaTmpRepo(std::string const& repo_url, +auto GitRepoRemote::FetchViaTmpRepo(StorageConfig const& storage_config, + std::string const& repo_url, std::optional<std::string> const& branch, std::vector<std::string> const& inherit_env, std::string const& git_bin, @@ -540,7 +541,7 @@ auto GitRepoRemote::FetchViaTmpRepo(std::string const& repo_url, anon_logger_ptr const& logger) noexcept -> bool { try { - auto tmp_dir = StorageConfig::Instance().CreateTypedTmpDir("fetch"); + auto tmp_dir = storage_config.CreateTypedTmpDir("fetch"); if (not tmp_dir) { (*logger)("Failed to create temp dir for running 'git fetch'", /*fatal=*/true); diff --git a/src/other_tools/git_operations/git_repo_remote.hpp b/src/other_tools/git_operations/git_repo_remote.hpp index c59fb48e..53987e58 100644 --- a/src/other_tools/git_operations/git_repo_remote.hpp +++ b/src/other_tools/git_operations/git_repo_remote.hpp @@ -22,6 +22,7 @@ #include <vector> #include "src/buildtool/file_system/git_repo.hpp" +#include "src/buildtool/storage/config.hpp" extern "C" { struct git_config; @@ -87,6 +88,7 @@ class GitRepoRemote : public GitRepo { /// Returns the commit hash, as a string, or nullopt if failure. /// It guarantees the logger is called exactly once with fatal if failure. [[nodiscard]] auto UpdateCommitViaTmpRepo( + StorageConfig const& storage_config, std::string const& repo_url, std::string const& branch, std::vector<std::string> const& inherit_env, @@ -103,6 +105,7 @@ class GitRepoRemote : public GitRepo { /// Returns a success flag. /// It guarantees the logger is called exactly once with fatal if failure. [[nodiscard]] auto FetchViaTmpRepo( + StorageConfig const& storage_config, std::string const& repo_url, std::optional<std::string> const& branch, std::vector<std::string> const& inherit_env, diff --git a/src/other_tools/ops_maps/TARGETS b/src/other_tools/ops_maps/TARGETS index 01152ed9..ab8c6664 100644 --- a/src/other_tools/ops_maps/TARGETS +++ b/src/other_tools/ops_maps/TARGETS @@ -50,6 +50,7 @@ , ["src/buildtool/storage", "fs_utils"] , ["src/other_tools/just_mr/progress_reporting", "statistics"] , ["src/other_tools/just_mr/progress_reporting", "progress"] + , ["src/buildtool/storage", "config"] ] } , "content_cas_map": 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 0e84689a..60ea67da 100644 --- a/src/other_tools/ops_maps/git_tree_fetch_map.cpp +++ b/src/other_tools/ops_maps/git_tree_fetch_map.cpp @@ -423,6 +423,7 @@ auto CreateGitTreeFetchMap( fatal); }); if (not just_git_repo->FetchViaTmpRepo( + StorageConfig::Instance(), target_path.string(), std::nullopt, key.inherit_env, diff --git a/src/other_tools/ops_maps/git_update_map.cpp b/src/other_tools/ops_maps/git_update_map.cpp index 9886b84b..143000bc 100644 --- a/src/other_tools/ops_maps/git_update_map.cpp +++ b/src/other_tools/ops_maps/git_update_map.cpp @@ -16,6 +16,7 @@ #include "fmt/core.h" #include "src/buildtool/execution_api/local/config.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/fs_utils.hpp" #include "src/other_tools/just_mr/progress_reporting/progress.hpp" #include "src/other_tools/just_mr/progress_reporting/statistics.hpp" @@ -48,12 +49,14 @@ auto CreateGitUpdateMap(GitCASPtr const& git_cas, // update commit auto id = fmt::format("{}:{}", key.repo, key.branch); JustMRProgress::Instance().TaskTracker().Start(id); - auto new_commit = git_repo->UpdateCommitViaTmpRepo(key.repo, - key.branch, - key.inherit_env, - git_bin, - launcher, - wrapped_logger); + auto new_commit = + git_repo->UpdateCommitViaTmpRepo(StorageConfig::Instance(), + key.repo, + key.branch, + key.inherit_env, + git_bin, + launcher, + wrapped_logger); JustMRProgress::Instance().TaskTracker().Stop(id); if (not new_commit) { return; diff --git a/src/other_tools/ops_maps/import_to_git_map.cpp b/src/other_tools/ops_maps/import_to_git_map.cpp index 6a998f9d..7e75ab71 100644 --- a/src/other_tools/ops_maps/import_to_git_map.cpp +++ b/src/other_tools/ops_maps/import_to_git_map.cpp @@ -181,6 +181,7 @@ auto CreateImportToGitMap( fatal); }); if (not just_git_repo->FetchViaTmpRepo( + StorageConfig::Instance(), target_path.string(), std::nullopt, std::vector<std::string>{} /* inherit_env */, diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp index fac4d98d..4a33d240 100644 --- a/src/other_tools/root_maps/commit_git_map.cpp +++ b/src/other_tools/root_maps/commit_git_map.cpp @@ -254,7 +254,8 @@ void NetworkFetchAndSetPresentRoot( err_messages += fmt::format( "While attempting fetch from URL {}:\n{}\n", mirror, msg); }); - if (git_repo->FetchViaTmpRepo(mirror, + if (git_repo->FetchViaTmpRepo(StorageConfig::Instance(), + mirror, repo_info.branch, repo_info.inherit_env, git_bin, |