summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-06-26 16:07:58 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-07-05 12:58:35 +0200
commit5bc6265b2ffe43370b4cddd0a9e4c09b059ef131 (patch)
tree63619c3d43f97c4ffa16feb9094fc8631620b164
parent3440784e94de51c95d3dcca8509f8e46b4722ee6 (diff)
downloadjustbuild-5bc6265b2ffe43370b4cddd0a9e4c09b059ef131.tar.gz
Pass StorageConfig to git_repo and git_repo_remote
-rw-r--r--src/buildtool/file_system/TARGETS2
-rw-r--r--src/buildtool/file_system/git_repo.cpp7
-rw-r--r--src/buildtool/file_system/git_repo.hpp2
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.cpp3
-rw-r--r--src/other_tools/git_operations/TARGETS6
-rw-r--r--src/other_tools/git_operations/git_repo_remote.cpp9
-rw-r--r--src/other_tools/git_operations/git_repo_remote.hpp3
-rw-r--r--src/other_tools/ops_maps/TARGETS1
-rw-r--r--src/other_tools/ops_maps/git_tree_fetch_map.cpp1
-rw-r--r--src/other_tools/ops_maps/git_update_map.cpp15
-rw-r--r--src/other_tools/ops_maps/import_to_git_map.cpp1
-rw-r--r--src/other_tools/root_maps/commit_git_map.cpp3
-rw-r--r--test/buildtool/file_system/TARGETS1
-rw-r--r--test/buildtool/file_system/git_repo.test.cpp10
-rw-r--r--test/other_tools/git_operations/TARGETS1
-rw-r--r--test/other_tools/git_operations/git_repo_remote.test.cpp61
16 files changed, 84 insertions, 42 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,
diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS
index 880cc368..c202fa32 100644
--- a/test/buildtool/file_system/TARGETS
+++ b/test/buildtool/file_system/TARGETS
@@ -125,6 +125,7 @@
, ["@", "src", "src/buildtool/logging", "logging"]
, ["@", "src", "src/utils/cpp", "atomic"]
, ["@", "src", "src/utils/cpp", "hex_string"]
+ , ["@", "src", "src/buildtool/storage", "config"]
, ["utils", "shell_quoting"]
]
, "stage": ["test", "buildtool", "file_system"]
diff --git a/test/buildtool/file_system/git_repo.test.cpp b/test/buildtool/file_system/git_repo.test.cpp
index c5265aaf..94801dfe 100644
--- a/test/buildtool/file_system/git_repo.test.cpp
+++ b/test/buildtool/file_system/git_repo.test.cpp
@@ -29,6 +29,7 @@
#include "src/buildtool/file_system/git_repo.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/utils/cpp/atomic.hpp"
#include "src/utils/cpp/hex_string.hpp"
#include "test/utils/shell_quoting.hpp"
@@ -418,7 +419,7 @@ TEST_CASE("Single-threaded fake repository operations -- batch 1",
// fetch all with base refspecs
REQUIRE(repo_fetch_all->LocalFetchViaTmpRepo(
- *repo_path, std::nullopt, logger));
+ StorageConfig::Instance(), *repo_path, std::nullopt, logger));
// check commit is there after fetch
CHECK(*repo_fetch_all->CheckCommitExists(kRootCommit, logger));
@@ -437,7 +438,7 @@ TEST_CASE("Single-threaded fake repository operations -- batch 1",
// fetch branch
REQUIRE(repo_fetch_branch->LocalFetchViaTmpRepo(
- *repo_path, "master", logger));
+ StorageConfig::Instance(), *repo_path, "master", logger));
// check commit is there after fetch
CHECK(*repo_fetch_branch->CheckCommitExists(kRootCommit, logger));
@@ -728,7 +729,10 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo]") {
REQUIRE(remote_repo->IsRepoFake());
// fetch all
REQUIRE(remote_repo->LocalFetchViaTmpRepo(
- *remote_repo_path, std::nullopt, logger));
+ StorageConfig::Instance(),
+ *remote_repo_path,
+ std::nullopt,
+ logger));
} break;
}
},
diff --git a/test/other_tools/git_operations/TARGETS b/test/other_tools/git_operations/TARGETS
index 9fa94906..57603ecc 100644
--- a/test/other_tools/git_operations/TARGETS
+++ b/test/other_tools/git_operations/TARGETS
@@ -36,6 +36,7 @@
, ["@", "src", "src/buildtool/logging", "log_level"]
, ["@", "src", "src/buildtool/logging", "logging"]
, ["@", "src", "src/other_tools/git_operations", "git_repo_remote"]
+ , ["@", "src", "src/buildtool/storage", "config"]
, ["@", "src", "src/utils/cpp", "atomic"]
, ["utils", "shell_quoting"]
]
diff --git a/test/other_tools/git_operations/git_repo_remote.test.cpp b/test/other_tools/git_operations/git_repo_remote.test.cpp
index 0a970db8..89bfad23 100644
--- a/test/other_tools/git_operations/git_repo_remote.test.cpp
+++ b/test/other_tools/git_operations/git_repo_remote.test.cpp
@@ -26,6 +26,7 @@
#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/other_tools/git_operations/git_repo_remote.hpp"
#include "src/utils/cpp/atomic.hpp"
#include "test/utils/shell_quoting.hpp"
@@ -250,8 +251,13 @@ TEST_CASE("Single-threaded fake repository operations", "[git_repo_remote]") {
*repo_fetch_all->CheckCommitExists(kRootCommit, logger));
// fetch all with base refspecs
- REQUIRE(repo_fetch_all->FetchViaTmpRepo(
- *repo_path, std::nullopt, {}, "git", {}, logger));
+ REQUIRE(repo_fetch_all->FetchViaTmpRepo(StorageConfig::Instance(),
+ *repo_path,
+ std::nullopt,
+ {},
+ "git",
+ {},
+ logger));
// check commit is there after fetch
CHECK(*repo_fetch_all->CheckCommitExists(kRootCommit, logger));
@@ -269,8 +275,14 @@ TEST_CASE("Single-threaded fake repository operations", "[git_repo_remote]") {
*repo_fetch_wRefspec->CheckCommitExists(kRootCommit, logger));
// fetch all
- REQUIRE(repo_fetch_wRefspec->FetchViaTmpRepo(
- *repo_path, "master", {}, "git", {}, logger));
+ REQUIRE(
+ repo_fetch_wRefspec->FetchViaTmpRepo(StorageConfig::Instance(),
+ *repo_path,
+ "master",
+ {},
+ "git",
+ {},
+ logger));
// check commit is there after fetch
CHECK(*repo_fetch_wRefspec->CheckCommitExists(kRootCommit, logger));
@@ -284,8 +296,14 @@ TEST_CASE("Single-threaded fake repository operations", "[git_repo_remote]") {
REQUIRE(repo_commit_upd);
// do remote ls
- auto fetched_commit = repo_commit_upd->UpdateCommitViaTmpRepo(
- *repo_path, "master", {}, "git", {}, logger);
+ auto fetched_commit =
+ repo_commit_upd->UpdateCommitViaTmpRepo(StorageConfig::Instance(),
+ *repo_path,
+ "master",
+ {},
+ "git",
+ {},
+ logger);
REQUIRE(fetched_commit);
CHECK(*fetched_commit == kRootCommit);
@@ -345,28 +363,31 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo_remote]") {
} break;
case 1: {
// fetch with base refspecs
- CHECK(
- target_repo->FetchViaTmpRepo(*remote_repo_path,
- std::nullopt,
- {},
- "git",
- {},
- logger));
+ CHECK(target_repo->FetchViaTmpRepo(
+ StorageConfig::Instance(),
+ *remote_repo_path,
+ std::nullopt,
+ {},
+ "git",
+ {},
+ logger));
} break;
case 2: {
// fetch specific branch
- CHECK(
- target_repo->FetchViaTmpRepo(*remote_repo_path,
- "master",
- {},
- "git",
- {},
- logger));
+ CHECK(target_repo->FetchViaTmpRepo(
+ StorageConfig::Instance(),
+ *remote_repo_path,
+ "master",
+ {},
+ "git",
+ {},
+ logger));
} break;
case 3: {
// do remote ls
auto fetched_commit =
target_repo->UpdateCommitViaTmpRepo(
+ StorageConfig::Instance(),
*remote_repo_path,
"master",
{},