From 4ce6ec5563c0aa277b455c9c1ded7e8556402c68 Mon Sep 17 00:00:00 2001 From: Sascha Roloff Date: Tue, 5 Jul 2022 19:46:33 +0200 Subject: Git tree can return size --- src/buildtool/file_system/git_tree.cpp | 7 +++++++ src/buildtool/file_system/git_tree.hpp | 1 + 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/buildtool/file_system/git_tree.cpp b/src/buildtool/file_system/git_tree.cpp index 8d220e30..30c98261 100644 --- a/src/buildtool/file_system/git_tree.cpp +++ b/src/buildtool/file_system/git_tree.cpp @@ -78,6 +78,13 @@ auto GitTree::LookupEntryByPath( return LookupEntryPyPath(*this, resolved.begin(), resolved.end()); } +auto GitTree::Size() const noexcept -> std::optional { + if (auto header = cas_->ReadHeader(raw_id_)) { + return header->first; + } + return std::nullopt; +} + auto GitTreeEntry::Blob() const noexcept -> std::optional { if (not IsBlob()) { return std::nullopt; diff --git a/src/buildtool/file_system/git_tree.hpp b/src/buildtool/file_system/git_tree.hpp index eb1c2147..25218634 100644 --- a/src/buildtool/file_system/git_tree.hpp +++ b/src/buildtool/file_system/git_tree.hpp @@ -47,6 +47,7 @@ class GitTree { [[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_; } + [[nodiscard]] auto Size() const noexcept -> std::optional; private: gsl::not_null cas_; -- cgit v1.2.3