summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/file_system/git_tree.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/buildtool/file_system/git_tree.cpp b/src/buildtool/file_system/git_tree.cpp
index e7a2f41d..e0b25593 100644
--- a/src/buildtool/file_system/git_tree.cpp
+++ b/src/buildtool/file_system/git_tree.cpp
@@ -14,7 +14,9 @@
#include "src/buildtool/file_system/git_tree.hpp"
+#include <algorithm>
#include <sstream>
+#include <vector>
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/logging/log_level.hpp"
@@ -55,6 +57,25 @@ namespace {
return entry;
}
+class SymlinksChecker final {
+ public:
+ explicit SymlinksChecker(gsl::not_null<GitCASPtr> const& cas) noexcept
+ : cas_{*cas} {}
+
+ [[nodiscard]] auto operator()(
+ std::vector<bazel_re::Digest> const& ids) const noexcept -> bool {
+ return std::all_of(
+ ids.begin(), ids.end(), [&cas = cas_](bazel_re::Digest const& id) {
+ auto content = cas.ReadObject(ArtifactDigest(id).hash(),
+ /*is_hex_id=*/true);
+ return content.has_value() and PathIsNonUpwards(*content);
+ });
+ };
+
+ private:
+ GitCAS const& cas_;
+};
+
} // namespace
auto GitTree::Read(std::filesystem::path const& repo_path,
@@ -70,22 +91,11 @@ auto GitTree::Read(std::filesystem::path const& repo_path,
auto GitTree::Read(gsl::not_null<GitCASPtr> const& cas,
std::string const& tree_id,
bool ignore_special) noexcept -> std::optional<GitTree> {
- // create symlinks checker
- auto check_symlinks = [&cas](std::vector<bazel_re::Digest> const& ids) {
- for (auto const& id : ids) {
- auto content =
- cas->ReadObject(ArtifactDigest(id).hash(), /*is_hex_id=*/true);
- if (not content or not PathIsNonUpwards(*content)) {
- return false;
- }
- }
- return true;
- };
if (auto raw_id = FromHexString(tree_id)) {
auto repo = GitRepo::Open(cas);
if (repo != std::nullopt) {
if (auto entries = repo->ReadTree(*raw_id,
- check_symlinks,
+ SymlinksChecker{cas},
/*is_hex_id=*/false,
ignore_special)) {
// NOTE: the raw_id value is NOT recomputed when
@@ -146,20 +156,9 @@ auto GitTreeEntry::Tree(bool ignore_special) const& noexcept
if (repo == std::nullopt) {
return std::nullopt;
}
- // create symlinks checker
- auto check_symlinks =
- [cas = cas_](std::vector<bazel_re::Digest> const& ids) {
- for (auto const& id : ids) {
- auto content = cas->ReadObject(
- ArtifactDigest(id).hash(), /*is_hex_id=*/true);
- if (not content or not PathIsNonUpwards(*content)) {
- return false;
- }
- }
- return true;
- };
+
if (auto entries = repo->ReadTree(raw_id_,
- check_symlinks,
+ SymlinksChecker{cas_},
/*is_hex_id=*/false,
ignore_special)) {
return GitTree::FromEntries(