summaryrefslogtreecommitdiff
path: root/src/other_tools/root_maps/commit_git_map.cpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-06-28 12:02:14 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-07-05 13:32:39 +0200
commit849671f3d4ea482d208da4b5adf5c2c3556e25e4 (patch)
treec4464ebd7bd88a3785c6337c2788d6e8b449fa22 /src/other_tools/root_maps/commit_git_map.cpp
parent3c7f2481918289e8d47922df1c87a7ae77357749 (diff)
downloadjustbuild-849671f3d4ea482d208da4b5adf5c2c3556e25e4.tar.gz
Pass StorageConfig and Storage to just-mr maps
Diffstat (limited to 'src/other_tools/root_maps/commit_git_map.cpp')
-rw-r--r--src/other_tools/root_maps/commit_git_map.cpp137
1 files changed, 72 insertions, 65 deletions
diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp
index 4a33d240..d4e5c4e4 100644
--- a/src/other_tools/root_maps/commit_git_map.cpp
+++ b/src/other_tools/root_maps/commit_git_map.cpp
@@ -21,7 +21,6 @@
#include "fmt/core.h"
#include "src/buildtool/file_system/file_root.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
-#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/fs_utils.hpp"
#include "src/other_tools/git_operations/git_repo_remote.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress.hpp"
@@ -49,10 +48,10 @@ namespace {
}
[[nodiscard]] auto IsCacheGitRoot(
+ StorageConfig const& storage_config,
std::filesystem::path const& repo_root) noexcept -> bool {
return std::filesystem::absolute(ToNormalPath(repo_root)) ==
- std::filesystem::absolute(
- ToNormalPath(StorageConfig::Instance().GitRoot()));
+ std::filesystem::absolute(ToNormalPath(storage_config.GitRoot()));
}
/// \brief Helper function for ensuring the serve endpoint, if given, has the
@@ -146,6 +145,7 @@ void EnsureRootAsAbsent(std::string const& tree_id,
void WriteIdFileAndSetWSRoot(std::string const& root_tree_id,
std::string const& subdir,
bool ignore_special,
+ StorageConfig const& storage_config,
GitCASPtr const& git_cas,
std::filesystem::path const& tree_id_file,
CommitGitMap::SetterPtr const& ws_setter,
@@ -162,7 +162,7 @@ void WriteIdFileAndSetWSRoot(std::string const& root_tree_id,
auto git_repo = GitRepoRemote::Open(git_cas); // link fake repo to odb
if (not git_repo) {
(*logger)(fmt::format("Could not open cache object database {}",
- StorageConfig::Instance().GitRoot().string()),
+ storage_config.GitRoot().string()),
/*fatal=*/true);
return;
}
@@ -185,7 +185,7 @@ void WriteIdFileAndSetWSRoot(std::string const& root_tree_id,
? FileRoot::kGitTreeIgnoreSpecialMarker
: FileRoot::kGitTreeMarker,
*tree_id,
- StorageConfig::Instance().GitRoot().string()}),
+ storage_config.GitRoot().string()}),
false));
}
@@ -195,6 +195,7 @@ void NetworkFetchAndSetPresentRoot(
std::string const& fetch_repo,
MirrorsPtr const& additional_mirrors,
GitCASPtr const& git_cas,
+ StorageConfig const& storage_config,
gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map,
std::string const& git_bin,
std::vector<std::string> const& launcher,
@@ -254,7 +255,7 @@ void NetworkFetchAndSetPresentRoot(
err_messages += fmt::format(
"While attempting fetch from URL {}:\n{}\n", mirror, msg);
});
- if (git_repo->FetchViaTmpRepo(StorageConfig::Instance(),
+ if (git_repo->FetchViaTmpRepo(storage_config,
mirror,
repo_info.branch,
repo_info.inherit_env,
@@ -300,7 +301,7 @@ void NetworkFetchAndSetPresentRoot(
return;
}
// if witnessing repository is the Git cache, then also tag the commit
- if (IsCacheGitRoot(repo_root)) {
+ if (IsCacheGitRoot(storage_config, repo_root)) {
GitOpKey op_key = {.params =
{
repo_root, // target_path
@@ -410,6 +411,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
std::string const& git_bin,
std::vector<std::string> const& launcher,
ServeApi const* serve,
+ gsl::not_null<StorageConfig const*> const& storage_config,
gsl::not_null<IExecutionApi const*> const& local_api,
IExecutionApi const* remote_api,
bool fetch_absent,
@@ -436,8 +438,8 @@ void EnsureCommit(GitRepoInfo const& repo_info,
return;
}
if (not is_commit_present.value()) {
- auto tree_id_file = StorageUtils::GetCommitTreeIDFile(
- StorageConfig::Instance(), repo_info.hash);
+ auto tree_id_file =
+ StorageUtils::GetCommitTreeIDFile(*storage_config, repo_info.hash);
// Check if we have stored a file association between commit and tree;
// if an association file exists, the respective tree MUST be in the
// Git cache
@@ -450,21 +452,18 @@ void EnsureCommit(GitRepoInfo const& repo_info,
/*fatal=*/true);
return;
}
- auto just_git_cas =
- GitCAS::Open(StorageConfig::Instance().GitRoot());
+ auto just_git_cas = GitCAS::Open(storage_config->GitRoot());
if (not just_git_cas) {
- (*logger)(
- fmt::format("Could not open Git cache database {}",
- StorageConfig::Instance().GitRoot().string()),
- /*fatal=*/true);
+ (*logger)(fmt::format("Could not open Git cache database {}",
+ storage_config->GitRoot().string()),
+ /*fatal=*/true);
return;
}
auto just_git_repo = GitRepo::Open(just_git_cas);
if (not just_git_repo) {
- (*logger)(
- fmt::format("Could not open Git cache repository {}",
- StorageConfig::Instance().GitRoot().string()),
- /*fatal=*/true);
+ (*logger)(fmt::format("Could not open Git cache repository {}",
+ storage_config->GitRoot().string()),
+ /*fatal=*/true);
return;
}
// extract the subdir tree
@@ -487,7 +486,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
if (repo_info.absent and not fetch_absent) {
// try by all available means to generate & set the absent root
EnsureRootAsAbsent(*tree_id,
- StorageConfig::Instance().GitRoot(),
+ storage_config->GitRoot(),
repo_info,
serve,
remote_api,
@@ -496,14 +495,14 @@ void EnsureCommit(GitRepoInfo const& repo_info,
}
else {
// this root is present
- (*ws_setter)(std::pair(
- nlohmann::json::array(
- {repo_info.ignore_special
- ? FileRoot::kGitTreeIgnoreSpecialMarker
- : FileRoot::kGitTreeMarker,
- *tree_id,
- StorageConfig::Instance().GitRoot().string()}),
- /*is_cache_hit=*/false));
+ (*ws_setter)(
+ std::pair(nlohmann::json::array(
+ {repo_info.ignore_special
+ ? FileRoot::kGitTreeIgnoreSpecialMarker
+ : FileRoot::kGitTreeMarker,
+ *tree_id,
+ storage_config->GitRoot().string()}),
+ /*is_cache_hit=*/false));
}
// done!
return;
@@ -552,16 +551,16 @@ void EnsureCommit(GitRepoInfo const& repo_info,
if (serve_result) {
auto const& root_tree_id = *serve_result;
// verify if we know the tree already in the local Git cache
- GitOpKey op_key = {.params =
- {
- StorageConfig::Instance()
- .GitRoot(), // target_path
- "", // git_hash
- "", // branch
- std::nullopt, // message
- true // init_bare
- },
- .op_type = GitOpType::ENSURE_INIT};
+ GitOpKey op_key = {
+ .params =
+ {
+ storage_config->GitRoot(), // target_path
+ "", // git_hash
+ "", // branch
+ std::nullopt, // message
+ true // init_bare
+ },
+ .op_type = GitOpType::ENSURE_INIT};
critical_git_op_map->ConsumeAfterKeysReady(
ts,
{std::move(op_key)},
@@ -571,6 +570,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
repo_root,
fetch_repo,
additional_mirrors,
+ storage_config,
git_cas,
critical_git_op_map,
import_to_git_map,
@@ -592,31 +592,29 @@ void EnsureCommit(GitRepoInfo const& repo_info,
auto just_git_repo =
GitRepoRemote::Open(op_result.git_cas);
if (not just_git_repo) {
- (*logger)(fmt::format("Could not open Git "
- "cache repository "
- "{}",
- StorageConfig::Instance()
- .GitRoot()
- .string()),
- /*fatal=*/true);
+ (*logger)(
+ fmt::format(
+ "Could not open Git "
+ "cache repository "
+ "{}",
+ storage_config->GitRoot().string()),
+ /*fatal=*/true);
return;
}
// check tree existence
- auto wrapped_logger =
- std::make_shared<AsyncMapConsumerLogger>(
- [logger, tree = root_tree_id](
- auto const& msg, bool fatal) {
- (*logger)(
- fmt::format(
- "While verifying presence of "
- "tree {} in repository {}:\n{}",
- tree,
- StorageConfig::Instance()
- .GitRoot()
- .string(),
- msg),
- fatal);
- });
+ auto wrapped_logger = std::make_shared<
+ AsyncMapConsumerLogger>(
+ [logger, storage_config, tree = root_tree_id](
+ auto const& msg, bool fatal) {
+ (*logger)(
+ fmt::format(
+ "While verifying presence of "
+ "tree {} in repository {}:\n{}",
+ tree,
+ storage_config->GitRoot().string(),
+ msg),
+ fatal);
+ });
auto tree_present = just_git_repo->CheckTreeExists(
root_tree_id, wrapped_logger);
if (not tree_present) {
@@ -631,6 +629,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
root_tree_id,
repo_info.subdir,
repo_info.ignore_special,
+ *storage_config,
op_result.git_cas,
tree_id_file,
ws_setter,
@@ -641,7 +640,8 @@ void EnsureCommit(GitRepoInfo const& repo_info,
// now check if the tree is in the local checkout,
// if this checkout is not our Git cache; this can
// save an unnecessary remote CAS call
- if (not IsCacheGitRoot(repo_root)) {
+ if (not IsCacheGitRoot(*storage_config,
+ repo_root)) {
auto git_repo = GitRepoRemote::Open(git_cas);
if (not git_repo) {
(*logger)(fmt::format("Could not open Git "
@@ -730,7 +730,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
repo_info.origin);
// Move tree from local CAS to local Git storage
auto tmp_dir =
- StorageConfig::Instance().CreateTypedTmpDir(
+ storage_config->CreateTypedTmpDir(
"fetch-absent-root");
if (not tmp_dir) {
(*logger)(
@@ -763,6 +763,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
{std::move(c_info)},
[tmp_dir, // keep tmp_dir alive
root_tree_id,
+ storage_config,
subdir = repo_info.subdir,
ignore_special = repo_info.ignore_special,
just_git_cas = op_result.git_cas,
@@ -794,6 +795,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
WriteIdFileAndSetWSRoot(root_tree_id,
subdir,
ignore_special,
+ *storage_config,
just_git_cas,
tree_id_file,
ws_setter,
@@ -826,6 +828,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
fetch_repo,
additional_mirrors,
git_cas,
+ *storage_config,
critical_git_op_map,
git_bin,
launcher,
@@ -834,8 +837,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
ws_setter,
logger);
},
- [logger,
- target_path = StorageConfig::Instance().GitRoot()](
+ [logger, target_path = storage_config->GitRoot()](
auto const& msg, bool fatal) {
(*logger)(fmt::format("While running critical Git "
"op ENSURE_INIT bare for "
@@ -866,6 +868,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
fetch_repo,
additional_mirrors,
git_cas,
+ *storage_config,
critical_git_op_map,
git_bin,
launcher,
@@ -927,6 +930,7 @@ auto CreateCommitGitMap(
std::string const& git_bin,
std::vector<std::string> const& launcher,
ServeApi const* serve,
+ gsl::not_null<StorageConfig const*> const& storage_config,
gsl::not_null<IExecutionApi const*> const& local_api,
IExecutionApi const* remote_api,
bool fetch_absent,
@@ -938,6 +942,7 @@ auto CreateCommitGitMap(
git_bin,
launcher,
serve,
+ storage_config,
local_api,
remote_api,
fetch_absent](auto ts,
@@ -953,7 +958,7 @@ auto CreateCommitGitMap(
fetch_repo = std::filesystem::absolute(*fetch_repo_path).string();
}
std::filesystem::path repo_root = StorageUtils::GetGitRoot(
- StorageConfig::Instance(), just_mr_paths, fetch_repo);
+ *storage_config, just_mr_paths, fetch_repo);
// ensure git repo
// define Git operation to be done
GitOpKey op_key = {
@@ -979,6 +984,7 @@ auto CreateCommitGitMap(
git_bin,
launcher,
serve,
+ storage_config,
local_api,
remote_api,
fetch_absent,
@@ -1012,6 +1018,7 @@ auto CreateCommitGitMap(
git_bin,
launcher,
serve,
+ storage_config,
local_api,
remote_api,
fetch_absent,