diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-08-01 14:30:37 +0200 |
---|---|---|
committer | Sascha Roloff <sascha.roloff@huawei.com> | 2022-08-05 14:41:31 +0200 |
commit | c974b1eb4df53dc23bd80dd13ad514d8828dc986 (patch) | |
tree | ad6bd0a5e35e2f4e89a43e7a3d10a3895598f71d /src/buildtool/file_system/git_tree.hpp | |
parent | 8594b00243aa95f6bea9a45bfcfa55d2d71d4b48 (diff) | |
download | justbuild-c974b1eb4df53dc23bd80dd13ad514d8828dc986.tar.gz |
GitCAS: Implement reading git tree via libgit2
Diffstat (limited to 'src/buildtool/file_system/git_tree.hpp')
-rw-r--r-- | src/buildtool/file_system/git_tree.hpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/buildtool/file_system/git_tree.hpp b/src/buildtool/file_system/git_tree.hpp index ff7dc828..eb1c2147 100644 --- a/src/buildtool/file_system/git_tree.hpp +++ b/src/buildtool/file_system/git_tree.hpp @@ -59,6 +59,26 @@ class GitTree { : cas_{std::move(cas)}, entries_{std::move(entries)}, raw_id_{std::move(raw_id)} {} + + [[nodiscard]] static auto FromEntries(gsl::not_null<GitCASPtr> cas, + GitCAS::tree_entries_t&& entries, + std::string raw_id) noexcept + -> std::optional<GitTree> { + entries_t e{}; + e.reserve(entries.size()); + for (auto& [id, es] : entries) { + for (auto& entry : es) { + try { + e.emplace( + std::move(entry.name), + std::make_shared<GitTreeEntry>(cas, id, entry.type)); + } catch (...) { + return std::nullopt; + } + } + } + return GitTree(std::move(cas), std::move(e), std::move(raw_id)); + } }; class GitTreeEntry { @@ -77,8 +97,8 @@ class GitTreeEntry { [[nodiscard]] auto Hash() const noexcept { return ToHexString(raw_id_); } [[nodiscard]] auto Type() const noexcept { return type_; } - // Use with care. Implementation might read entire object to obtain size. - // Consider using Blob()->size() instead. + // Use with care. Implementation might read entire object to obtain + // size. Consider using Blob()->size() instead. [[nodiscard]] auto Size() const noexcept -> std::optional<std::size_t>; private: |