diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-10-31 15:50:59 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-11-14 13:35:01 +0100 |
commit | 17f88a4752243f09ede9571014b8d723aca6ca44 (patch) | |
tree | b50c76f7d9aff20dd95726dde337e005a71bb5c6 /src/other_tools/root_maps/commit_git_map.cpp | |
parent | 4c12fa12f7ad54174cce97ee511b9a897c992fc1 (diff) | |
download | justbuild-17f88a4752243f09ede9571014b8d723aca6ca44.tar.gz |
just-mr: Add 'mirrors' field to 'git' repositories
Diffstat (limited to 'src/other_tools/root_maps/commit_git_map.cpp')
-rw-r--r-- | src/other_tools/root_maps/commit_git_map.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp index 40399811..6959dfe6 100644 --- a/src/other_tools/root_maps/commit_git_map.cpp +++ b/src/other_tools/root_maps/commit_git_map.cpp @@ -355,18 +355,52 @@ void EnsureCommit(GitRepoInfo const& repo_info, /*fatal=*/true); return; } - // setup wrapped logger + // store failed attempts for subsequent logging + std::string err_messages{}; auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>( - [logger](auto const& msg, bool fatal) { - (*logger)(fmt::format("While fetching via tmp repo:\n{}", msg), - fatal); + [fetch_repo, &err_messages](auto const& msg, bool /*fatal*/) { + err_messages += + fmt::format("\nWhile attempting fetch from remote {}:\n{}", + fetch_repo, + msg); }); + // try the main fetch URL + bool fetched{false}; if (not git_repo->FetchViaTmpRepo(tmp_dir->GetPath(), fetch_repo, repo_info.branch, git_bin, launcher, wrapped_logger)) { + // try to fetch from mirrors, in order, if given + for (auto mirror : repo_info.mirrors) { + if (GitURLIsPath(mirror)) { + mirror = std::filesystem::absolute(mirror).string(); + } + wrapped_logger = std::make_shared<AsyncMapConsumerLogger>( + [mirror, &err_messages](auto const& msg, bool /*fatal*/) { + err_messages += fmt::format( + "\nWhile attempting fetch from mirror {}:\n{}", + mirror, + msg); + }); + if (git_repo->FetchViaTmpRepo(tmp_dir->GetPath(), + mirror, + repo_info.branch, + git_bin, + launcher, + wrapped_logger)) { + fetched = true; + break; + } + } + } + if (not fetched) { + // log fetch failure details separately to reduce verbosity + (*logger)( + fmt::format("While fetching via tmp repo:{}", err_messages), + /*fatal=*/false); + (*logger)("Failed to fetch from provided remotes", /*fatal=*/true); return; } // setup wrapped logger |