diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-05-16 15:02:05 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-05-17 10:36:13 +0200 |
commit | 06336198a38ffaec6c35df34580391579a7a7b22 (patch) | |
tree | 275b66f24ea2433d9672f64b0303e5ecd1afbfda /src/buildtool/file_system/file_root.hpp | |
parent | 580539ab08a098e7f348fee3c46fbf5d44cd4d54 (diff) | |
download | justbuild-06336198a38ffaec6c35df34580391579a7a7b22.tar.gz |
FileRoot: Fix parsing of ignore-special Git tree roots
When populating the GitTree instance stored in a Git tree-type
FileRoot with the ignore-special flag set, the GitTree instance
would be created with an empty raw_id_ field, signaling that some
of the entries might have been skipped and thus the root tree id
is not anymore in a one-to-one correspondence with the stored list
of entries.
This however caused FileRoot instances with missing tree id
information. This commit fixes the issue by always storing the
raw_id_ field as the root id of the Git tree, as well as clarifying
the relationship between this field and the ignore_special_ flag,
including refactoring the tree id getters.
Diffstat (limited to 'src/buildtool/file_system/file_root.hpp')
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index 08779e8e..eff4d450 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -225,17 +225,15 @@ class FileRoot { if (std::holds_alternative<tree_t>(data_)) { try { auto const& data = std::get<tree_t>(data_); - // check if tree is ignore_special - if (data->RawHash().empty()) { - return std::nullopt; - } - auto const& id = data->Hash(); - auto const& size = data->Size(); - if (size) { - return ArtifactDescription{ - ArtifactDigest{id, *size, /*is_tree=*/true}, - ObjectType::Tree, - repository}; + // only consider tree if we have it unmodified + if (auto id = data->Hash()) { + auto const& size = data->Size(); + if (size) { + return ArtifactDescription{ + ArtifactDigest{*id, *size, /*is_tree=*/true}, + ObjectType::Tree, + repository}; + } } } catch (...) { return std::nullopt; @@ -351,7 +349,8 @@ class FileRoot { nlohmann::json j; j.push_back(ignore_special_ ? kGitTreeIgnoreSpecialMarker : kGitTreeMarker); - j.push_back(std::get<git_root_t>(root_).tree->Hash()); + // we need the root tree id, irrespective of ignore_special flag + j.push_back(std::get<git_root_t>(root_).tree->FileRootHash()); return j; } if (std::holds_alternative<absent_root_t>(root_)) { |