diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-06-13 13:30:13 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-13 13:30:13 +0200 |
commit | 454cfcf66efc6ff5f42253431c6033e1e21044cf (patch) | |
tree | dd19c080220547807b3c3c916ca1a12cc6eabcd6 /src | |
parent | f5c12e59e34107f1fc16349d843a8f64d7dd5459 (diff) | |
download | justbuild-454cfcf66efc6ff5f42253431c6033e1e21044cf.tar.gz |
Include raw identifier to GitTree
In this way, we have it available when needed, e.g., to get identifers
for file roots or to get whole trees as source artifacts.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/file_system/git_tree.cpp | 11 | ||||
-rw-r--r-- | src/buildtool/file_system/git_tree.hpp | 11 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/buildtool/file_system/git_tree.cpp b/src/buildtool/file_system/git_tree.cpp index 1805961c..98281707 100644 --- a/src/buildtool/file_system/git_tree.cpp +++ b/src/buildtool/file_system/git_tree.cpp @@ -3,6 +3,7 @@ #include <sstream> #include "src/buildtool/logging/logger.hpp" +#include "src/utils/cpp/hex_string.hpp" extern "C" { #include <git2.h> @@ -113,7 +114,11 @@ auto GitTree::Read(std::filesystem::path const& repo_path, auto GitTree::Read(gsl::not_null<GitCASPtr> const& cas, std::string const& tree_id) noexcept -> std::optional<GitTree> { - auto obj = cas->ReadObject(tree_id, /*is_hex_id=*/true); + auto raw_id = FromHexString(tree_id); + if (not raw_id) { + return std::nullopt; + } + auto obj = cas->ReadObject(*raw_id); if (not obj) { return std::nullopt; } @@ -121,7 +126,7 @@ auto GitTree::Read(gsl::not_null<GitCASPtr> const& cas, if (not entries) { return std::nullopt; } - return GitTree{cas, std::move(*entries)}; + return GitTree{cas, std::move(*entries), std::move(*raw_id)}; } auto GitTree::LookupEntryByName(std::string const& name) const noexcept @@ -157,7 +162,7 @@ auto GitTreeEntry::Tree() const& noexcept -> std::optional<GitTree> const& { if (IsTree() and (obj = cas_->ReadObject(raw_id_))) { if (auto entries = ParseRawTreeObject(cas_, *obj)) { ptr = std::make_shared<std::optional<GitTree>>( - GitTree{cas_, std::move(*entries)}); + GitTree{cas_, std::move(*entries), raw_id_}); } } tree_cached_.store(ptr); diff --git a/src/buildtool/file_system/git_tree.hpp b/src/buildtool/file_system/git_tree.hpp index 57cb3b52..8371d785 100644 --- a/src/buildtool/file_system/git_tree.hpp +++ b/src/buildtool/file_system/git_tree.hpp @@ -45,13 +45,20 @@ class GitTree { [[nodiscard]] auto begin() const noexcept { return entries_.begin(); } [[nodiscard]] auto end() const noexcept { return entries_.end(); } + [[nodiscard]] auto Hash() const noexcept { return ToHexString(raw_id_); } + [[nodiscard]] auto RawHash() const noexcept { return raw_id_; } private: gsl::not_null<GitCASPtr> cas_; entries_t entries_; + std::string raw_id_; - GitTree(gsl::not_null<GitCASPtr> cas, entries_t&& entries) noexcept - : cas_{std::move(cas)}, entries_{std::move(entries)} {} + GitTree(gsl::not_null<GitCASPtr> cas, + entries_t&& entries, + std::string raw_id) noexcept + : cas_{std::move(cas)}, + entries_{std::move(entries)}, + raw_id_{std::move(raw_id)} {} }; class GitTreeEntry { |