diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-08-01 11:08:04 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-08-07 17:01:01 +0200 |
commit | 2ab4fc7b08b47ca04007a56574bb263a1c7324da (patch) | |
tree | ca34623fc4ea26f3b6b93450e04ecfd76968a6b1 /src/buildtool/file_system/git_repo.hpp | |
parent | c0226e230601972e0b4bf55f74a6514409d47bfe (diff) | |
download | justbuild-2ab4fc7b08b47ca04007a56574bb263a1c7324da.tar.gz |
GitRepo: Add method for reading object from tree by its path
Diffstat (limited to 'src/buildtool/file_system/git_repo.hpp')
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 20 |
1 files changed, 18 insertions, 2 deletions
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<std::string, std::vector<tree_entry_t>>; - // 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<std::string> 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<bool(std::vector<bazel_re::Digest> const&)>; @@ -211,6 +219,14 @@ class GitRepo { anon_logger_ptr const& logger) noexcept -> std::optional<bool>; + /// \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<TreeEntryInfo>; + private: /// \brief Wrapped git_repository with guarded destructor. /// Kept privately nested to avoid misuse of its raw pointer members. |