From 2ab4fc7b08b47ca04007a56574bb263a1c7324da Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 1 Aug 2023 11:08:04 +0200 Subject: GitRepo: Add method for reading object from tree by its path --- src/buildtool/file_system/git_repo.hpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/buildtool/file_system/git_repo.hpp') diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index e96f401b..b2e12934 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -49,8 +49,16 @@ class GitRepo { using tree_entries_t = std::unordered_map>; - // Checks whether a list of symlinks given by their hashes are non-upwards, - // based on content read from an actual backend. + // Stores the info of an object read by its path. + struct TreeEntryInfo { + std::string id{}; + ObjectType type; + // if type is symlink, read it in advance + std::optional symlink_content{std::nullopt}; + }; + + // Checks whether a list of symlinks given by their hashes are + // non-upwards, based on content read from an actual backend. using SymlinksCheckFunc = std::function const&)>; @@ -211,6 +219,14 @@ class GitRepo { anon_logger_ptr const& logger) noexcept -> std::optional; + /// \brief Get the object info related to a given path inside a Git tree. + /// Unlike GetSubtreeFromTree, we here ignore errors and only return a value + /// when all is successful. + /// Calling it from a fake repository allows thread-safe use. + [[nodiscard]] auto GetObjectByPathFromTree( + std::string const& tree_id, + std::string const& rel_path) noexcept -> std::optional; + private: /// \brief Wrapped git_repository with guarded destructor. /// Kept privately nested to avoid misuse of its raw pointer members. -- cgit v1.2.3