summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-02-28 15:22:53 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-03-06 10:39:58 +0100
commit8f15cfaab8e6913a23dd31bcaf7399b539a9aac9 (patch)
tree56e8713e852a6dc01bf384dbf012b3bc70fc6bd8 /src
parent1143de5bab2e90f8f42874e67ed62244960dd880 (diff)
downloadjustbuild-8f15cfaab8e6913a23dd31bcaf7399b539a9aac9.tar.gz
CommitGitMap: Move helper function out of header file
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/root_maps/commit_git_map.cpp146
-rw-r--r--src/other_tools/root_maps/commit_git_map.hpp8
2 files changed, 73 insertions, 81 deletions
diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp
index 18adc4fa..a4759cc1 100644
--- a/src/other_tools/root_maps/commit_git_map.cpp
+++ b/src/other_tools/root_maps/commit_git_map.cpp
@@ -32,79 +32,6 @@ namespace {
});
}
-} // namespace
-
-/// \brief Create a CommitGitMap object
-auto CreateCommitGitMap(
- gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map,
- JustMR::PathsPtr const& just_mr_paths,
- std::size_t jobs) -> CommitGitMap {
- auto commit_to_git = [critical_git_op_map, just_mr_paths](auto ts,
- auto setter,
- auto logger,
- auto /* unused */,
- auto const& key) {
- // get root for repo (making sure that if repo is a path, it is
- // absolute)
- std::string fetch_repo = key.repo_url;
- if (GitURLIsPath(fetch_repo)) {
- fetch_repo = std::filesystem::absolute(fetch_repo).string();
- }
- std::filesystem::path repo_root =
- JustMR::Utils::GetGitRoot(just_mr_paths, fetch_repo);
- // ensure git repo
- // define Git operation to be done
- GitOpKey op_key = {
- {
- repo_root, // target_path
- "", // git_hash
- "", // branch
- std::nullopt, // message
- not just_mr_paths->git_checkout_locations.contains(
- fetch_repo) // init_bare
- },
- GitOpType::ENSURE_INIT};
- critical_git_op_map->ConsumeAfterKeysReady(
- ts,
- {std::move(op_key)},
- [key, repo_root, critical_git_op_map, ts, setter, logger](
- auto const& values) {
- GitOpValue op_result = *values[0];
- // check flag
- if (not op_result.result) {
- (*logger)("Git init failed",
- /*fatal=*/true);
- return;
- }
- // setup a wrapped_logger
- auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>(
- [logger, target_path = repo_root](auto const& msg,
- bool fatal) {
- (*logger)(fmt::format("While ensuring commit for "
- "repository {}:\n{}",
- target_path.string(),
- msg),
- fatal);
- });
- EnsureCommit(key,
- repo_root,
- op_result.git_cas,
- critical_git_op_map,
- ts,
- setter,
- wrapped_logger);
- },
- [logger, target_path = repo_root](auto const& msg, bool fatal) {
- (*logger)(fmt::format("While running critical Git op "
- "ENSURE_INIT for target {}:\n{}",
- target_path.string(),
- msg),
- fatal);
- });
- };
- return AsyncMapConsumer<GitRepoInfo, nlohmann::json>(commit_to_git, jobs);
-}
-
void EnsureCommit(GitRepoInfo const& repo_info,
std::filesystem::path const& repo_root,
GitCASPtr const& git_cas,
@@ -255,3 +182,76 @@ void EnsureCommit(GitRepoInfo const& repo_info,
JustMRStatistics::Instance().IncrementCacheHitsCounter();
}
}
+
+} // namespace
+
+/// \brief Create a CommitGitMap object
+auto CreateCommitGitMap(
+ gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map,
+ JustMR::PathsPtr const& just_mr_paths,
+ std::size_t jobs) -> CommitGitMap {
+ auto commit_to_git = [critical_git_op_map, just_mr_paths](auto ts,
+ auto setter,
+ auto logger,
+ auto /* unused */,
+ auto const& key) {
+ // get root for repo (making sure that if repo is a path, it is
+ // absolute)
+ std::string fetch_repo = key.repo_url;
+ if (GitURLIsPath(fetch_repo)) {
+ fetch_repo = std::filesystem::absolute(fetch_repo).string();
+ }
+ std::filesystem::path repo_root =
+ JustMR::Utils::GetGitRoot(just_mr_paths, fetch_repo);
+ // ensure git repo
+ // define Git operation to be done
+ GitOpKey op_key = {
+ {
+ repo_root, // target_path
+ "", // git_hash
+ "", // branch
+ std::nullopt, // message
+ not just_mr_paths->git_checkout_locations.contains(
+ fetch_repo) // init_bare
+ },
+ GitOpType::ENSURE_INIT};
+ critical_git_op_map->ConsumeAfterKeysReady(
+ ts,
+ {std::move(op_key)},
+ [key, repo_root, critical_git_op_map, ts, setter, logger](
+ auto const& values) {
+ GitOpValue op_result = *values[0];
+ // check flag
+ if (not op_result.result) {
+ (*logger)("Git init failed",
+ /*fatal=*/true);
+ return;
+ }
+ // setup a wrapped_logger
+ auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>(
+ [logger, target_path = repo_root](auto const& msg,
+ bool fatal) {
+ (*logger)(fmt::format("While ensuring commit for "
+ "repository {}:\n{}",
+ target_path.string(),
+ msg),
+ fatal);
+ });
+ EnsureCommit(key,
+ repo_root,
+ op_result.git_cas,
+ critical_git_op_map,
+ ts,
+ setter,
+ wrapped_logger);
+ },
+ [logger, target_path = repo_root](auto const& msg, bool fatal) {
+ (*logger)(fmt::format("While running critical Git op "
+ "ENSURE_INIT for target {}:\n{}",
+ target_path.string(),
+ msg),
+ fatal);
+ });
+ };
+ return AsyncMapConsumer<GitRepoInfo, nlohmann::json>(commit_to_git, jobs);
+}
diff --git a/src/other_tools/root_maps/commit_git_map.hpp b/src/other_tools/root_maps/commit_git_map.hpp
index 163163d2..992f876c 100644
--- a/src/other_tools/root_maps/commit_git_map.hpp
+++ b/src/other_tools/root_maps/commit_git_map.hpp
@@ -57,12 +57,4 @@ using CommitGitMap = AsyncMapConsumer<GitRepoInfo, nlohmann::json>;
JustMR::PathsPtr const& just_mr_paths,
std::size_t jobs) -> CommitGitMap;
-void EnsureCommit(GitRepoInfo const& repo_info,
- std::filesystem::path const& repo_root,
- GitCASPtr const& git_cas,
- gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map,
- gsl::not_null<TaskSystem*> const& ts,
- CommitGitMap::SetterPtr const& ws_setter,
- CommitGitMap::LoggerPtr const& logger);
-
#endif // INCLUDED_SRC_OTHER_TOOLS_ROOT_MAPS_COMMIT_GIT_MAP_HPP