summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-09-15 15:40:36 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-09-15 16:39:35 +0200
commitc71bfe939b8eee864f45004e9daad19d01b3f38e (patch)
treeb39235cbecc5e122995313f8185210ef5d17a4de /src
parenta3824693e15fd7076f27ee17bf7fda2313d9d7ae (diff)
downloadjustbuild-c71bfe939b8eee864f45004e9daad19d01b3f38e.tar.gz
just-mr: ensure that after --fetch-absent a local build is possible
... by also keeping the map of commit to tree locally.
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/just_mr/utils.cpp5
-rw-r--r--src/other_tools/just_mr/utils.hpp5
-rw-r--r--src/other_tools/root_maps/commit_git_map.cpp54
3 files changed, 61 insertions, 3 deletions
diff --git a/src/other_tools/just_mr/utils.cpp b/src/other_tools/just_mr/utils.cpp
index 57ef6830..be0e841e 100644
--- a/src/other_tools/just_mr/utils.cpp
+++ b/src/other_tools/just_mr/utils.cpp
@@ -44,6 +44,11 @@ auto CreateTypedTmpDir(std::string const& type) noexcept -> TmpDirPtr {
return TmpDir::Create(parent_path);
}
+auto GetCommitTreeIDFile(std::string const& commit) noexcept
+ -> std::filesystem::path {
+ return StorageConfig::BuildRoot() / "commit-tree-map" / commit;
+}
+
auto GetArchiveTreeIDFile(std::string const& repo_type,
std::string const& content) noexcept
-> std::filesystem::path {
diff --git a/src/other_tools/just_mr/utils.hpp b/src/other_tools/just_mr/utils.hpp
index 65e6eda5..304cc839 100644
--- a/src/other_tools/just_mr/utils.hpp
+++ b/src/other_tools/just_mr/utils.hpp
@@ -211,6 +211,11 @@ namespace Utils {
[[nodiscard]] auto CreateTypedTmpDir(std::string const& type) noexcept
-> TmpDirPtr;
+/// \brief Get the path to the file storing the tree id associated with
+/// a given commit.
+[[nodiscard]] auto GetCommitTreeIDFile(std::string const& commit) noexcept
+ -> std::filesystem::path;
+
/// \brief Get the path to the file storing the tree id of an archive
/// content.
[[nodiscard]] auto GetArchiveTreeIDFile(std::string const& repo_type,
diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp
index 883fe697..a70406d1 100644
--- a/src/other_tools/root_maps/commit_git_map.cpp
+++ b/src/other_tools/root_maps/commit_git_map.cpp
@@ -67,10 +67,43 @@ void EnsureCommit(GitRepoInfo const& repo_info,
return;
}
if (not is_commit_present.value()) {
- JustMRProgress::Instance().TaskTracker().Start(repo_info.origin);
- // check if commit is known to remote serve service, if asked for an
- // absent root
if (repo_info.absent) {
+ auto tree_id_file =
+ JustMR::Utils::GetCommitTreeIDFile(repo_info.hash);
+ if (FileSystemManager::Exists(tree_id_file)) {
+ // read resolved tree id
+ auto resolved_tree_id =
+ FileSystemManager::ReadFile(tree_id_file);
+ if (not resolved_tree_id) {
+ (*logger)(fmt::format("Failed to read tree id from file {}",
+ tree_id_file.string()),
+ /*fatal=*/true);
+ return;
+ }
+ if (fetch_absent) {
+ (*ws_setter)(std::pair(
+ nlohmann::json::array(
+ {repo_info.ignore_special
+ ? FileRoot::kGitTreeIgnoreSpecialMarker
+ : FileRoot::kGitTreeMarker,
+ *resolved_tree_id,
+ StorageConfig::GitRoot().string()}),
+ false));
+ }
+ else {
+ (*ws_setter)(std::pair(
+ nlohmann::json::array(
+ {repo_info.ignore_special
+ ? FileRoot::kGitTreeIgnoreSpecialMarker
+ : FileRoot::kGitTreeMarker,
+ *resolved_tree_id}),
+ false));
+ }
+ return;
+ }
+ JustMRProgress::Instance().TaskTracker().Start(repo_info.origin);
+ // check if commit is known to remote serve service, if asked for an
+ // absent root
if (serve_api != nullptr) {
if (auto tree_id = serve_api->RetrieveTreeFromCommit(
repo_info.hash, repo_info.subdir, fetch_absent)) {
@@ -158,6 +191,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
[tmp_dir, // keep tmp_dir alive
repo_info,
tree_id,
+ tree_id_file,
logger,
ws_setter](auto const& values) {
if (not values[0]->second) {
@@ -165,6 +199,19 @@ void EnsureCommit(GitRepoInfo const& repo_info,
/*fatal=*/true);
return;
}
+ // Now that we also have the tree, write the
+ // association.
+ if (not JustMR::Utils::WriteTreeIDFile(
+ tree_id_file, *tree_id)) {
+ (*logger)(
+ fmt::format("Failed to write tree id "
+ "{} to file {}",
+ *tree_id,
+ tree_id_file.string()),
+ /*fatal=*/true);
+ return;
+ }
+
// set the workspace root as present
(*ws_setter)(std::pair(
nlohmann::json::array(
@@ -323,6 +370,7 @@ void EnsureCommit(GitRepoInfo const& repo_info,
});
}
else {
+ JustMRProgress::Instance().TaskTracker().Start(repo_info.origin);
// setup wrapped logger
auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>(
[logger](auto const& msg, bool fatal) {