diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-05-23 15:19:28 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-05-31 15:21:02 +0200 |
commit | bc93b16bf6eccf23d7018444872867f97f5dc94d (patch) | |
tree | 412c03a39f98eec84d98ab10f0af3ab586d6c7e6 /src/buildtool/file_system/git_tree.hpp | |
parent | da9c8f50b1a841830f3323f0438de2f3a0974022 (diff) | |
download | justbuild-bc93b16bf6eccf23d7018444872867f97f5dc94d.tar.gz |
FileRoot: Add ignore-special roots logic
Diffstat (limited to 'src/buildtool/file_system/git_tree.hpp')
-rw-r--r-- | src/buildtool/file_system/git_tree.hpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/buildtool/file_system/git_tree.hpp b/src/buildtool/file_system/git_tree.hpp index 5007b106..b634ffb2 100644 --- a/src/buildtool/file_system/git_tree.hpp +++ b/src/buildtool/file_system/git_tree.hpp @@ -45,8 +45,13 @@ class GitTree { /// \brief Read tree with given id from CAS. /// \param cas Git CAS that contains the tree id. /// \param tree_id Tree id as as hex string. + /// \param ignore_special If set, treat symlinks as absent. + /// NOTE: If ignore_special==true, the stored entries might differ from the + /// actual tree, so the stored ID is set to empty to signal that it should + /// not be used. [[nodiscard]] static auto Read(gsl::not_null<GitCASPtr> const& cas, - std::string const& tree_id) noexcept + std::string const& tree_id, + bool ignore_special = false) noexcept -> std::optional<GitTree>; /// \brief Lookup by dir entry name. '.' and '..' are not allowed. @@ -68,15 +73,22 @@ class GitTree { gsl::not_null<GitCASPtr> cas_; entries_t entries_; std::string raw_id_; + // If set, ignore all fast tree lookups and always traverse + bool ignore_special_; GitTree(gsl::not_null<GitCASPtr> const& cas, entries_t&& entries, - std::string raw_id) noexcept - : cas_{cas}, entries_{std::move(entries)}, raw_id_{std::move(raw_id)} {} + std::string raw_id, + bool ignore_special = false) noexcept + : cas_{cas}, + entries_{std::move(entries)}, + raw_id_{std::move(raw_id)}, + ignore_special_{ignore_special} {} [[nodiscard]] static auto FromEntries(gsl::not_null<GitCASPtr> const& cas, GitRepo::tree_entries_t&& entries, - std::string raw_id) noexcept + std::string raw_id, + bool ignore_special = false) noexcept -> std::optional<GitTree> { entries_t e{}; e.reserve(entries.size()); @@ -91,7 +103,7 @@ class GitTree { } } } - return GitTree(cas, std::move(e), std::move(raw_id)); + return GitTree(cas, std::move(e), std::move(raw_id), ignore_special); } }; @@ -106,8 +118,9 @@ class GitTreeEntry { [[nodiscard]] auto IsTree() const noexcept { return IsTreeObject(type_); } [[nodiscard]] auto Blob() const noexcept -> std::optional<std::string>; - [[nodiscard]] auto Tree() && = delete; - [[nodiscard]] auto Tree() const& noexcept -> std::optional<GitTree> const&; + [[nodiscard]] auto Tree(bool) && = delete; + [[nodiscard]] auto Tree(bool ignore_special = false) const& noexcept + -> std::optional<GitTree> const&; [[nodiscard]] auto Hash() const noexcept { return ToHexString(raw_id_); } [[nodiscard]] auto Type() const noexcept { return type_; } |