summaryrefslogtreecommitdiff
path: root/src/other_tools/root_maps/commit_git_map.cpp
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/other_tools/root_maps/commit_git_map.cpp
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/other_tools/root_maps/commit_git_map.cpp')
-rw-r--r--src/other_tools/root_maps/commit_git_map.cpp54
1 files changed, 51 insertions, 3 deletions
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) {