summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-07-24 10:16:34 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-08-07 14:43:19 +0200
commit0afacdb938a9787151f338656fa943679b7ec68b (patch)
tree35a1c490d425e6f1fd9fd5ee6a2a4e75796373b5 /src
parent3b9db9cc3242524da98e17b77acc5c9559f3f40b (diff)
downloadjustbuild-0afacdb938a9787151f338656fa943679b7ec68b.tar.gz
Pass SymlinksCheckFunc to GitRepo as not_null
+ invoke it only if there are symlinks to check + remove the corresponding runtime check since it is replaced by a compile-time check
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/file_system/TARGETS1
-rw-r--r--src/buildtool/file_system/git_repo.cpp19
-rw-r--r--src/buildtool/file_system/git_repo.hpp12
3 files changed, 16 insertions, 16 deletions
diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS
index 724d6b8d..6eb9cc70 100644
--- a/src/buildtool/file_system/TARGETS
+++ b/src/buildtool/file_system/TARGETS
@@ -123,6 +123,7 @@
, ["src/buildtool/common", "bazel_types"]
, ["src/utils/cpp", "expected"]
, ["src/buildtool/storage", "config"]
+ , ["@", "gsl", "", "gsl"]
]
, "stage": ["src", "buildtool", "file_system"]
, "private-deps":
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp
index f87f8e6b..346c1c13 100644
--- a/src/buildtool/file_system/git_repo.cpp
+++ b/src/buildtool/file_system/git_repo.cpp
@@ -1791,7 +1791,7 @@ auto GitRepo::IsRepoFake() const noexcept -> bool {
}
auto GitRepo::ReadTree(std::string const& id,
- SymlinksCheckFunc const& check_symlinks,
+ gsl::not_null<SymlinksCheckFunc> const& check_symlinks,
bool is_hex_id,
bool ignore_special) const noexcept
-> std::optional<tree_entries_t> {
@@ -1851,11 +1851,8 @@ auto GitRepo::ReadTree(std::string const& id,
}
}
// we check symlinks in bulk, optimized for network-backed repos
- if (not check_symlinks) {
- Logger::Log(LogLevel::Debug, "check_symlink callable is empty");
- return std::nullopt;
- }
- if (not check_symlinks(symlinks)) {
+ if (not symlinks.empty() and
+ not std::invoke(check_symlinks.get(), symlinks)) {
Logger::Log(LogLevel::Error,
"found upwards symlinks in Git tree {}",
is_hex_id ? std::string{id} : ToHexString(id));
@@ -1928,11 +1925,11 @@ auto GitRepo::CreateTree(tree_entries_t const& entries) const noexcept
#endif
}
-auto GitRepo::ReadTreeData(std::string const& data,
- std::string const& id,
- SymlinksCheckFunc const& check_symlinks,
- bool is_hex_id) noexcept
- -> std::optional<tree_entries_t> {
+auto GitRepo::ReadTreeData(
+ std::string const& data,
+ std::string const& id,
+ gsl::not_null<SymlinksCheckFunc> const& check_symlinks,
+ bool is_hex_id) noexcept -> std::optional<tree_entries_t> {
#ifndef BOOTSTRAP_BUILD_TOOL
try {
InMemoryODBBackend b{.parent = kInMemoryODBParent};
diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp
index 95fa14a6..1e5ec839 100644
--- a/src/buildtool/file_system/git_repo.hpp
+++ b/src/buildtool/file_system/git_repo.hpp
@@ -23,6 +23,7 @@
#include <utility> // std::move
#include <vector>
+#include "gsl/gsl"
#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/file_system/git_cas.hpp"
#include "src/buildtool/file_system/git_types.hpp"
@@ -107,10 +108,11 @@ class GitRepo {
/// \param check_symlinks Function to check non-upwardness condition.
/// \param is_hex_id Specify whether `id` is hex string or raw.
/// \param ignore_special If set, treat symlinks as absent.
- [[nodiscard]] auto ReadTree(std::string const& id,
- SymlinksCheckFunc const& check_symlinks,
- bool is_hex_id = false,
- bool ignore_special = false) const noexcept
+ [[nodiscard]] auto ReadTree(
+ std::string const& id,
+ gsl::not_null<SymlinksCheckFunc> const& check_symlinks,
+ bool is_hex_id = false,
+ bool ignore_special = false) const noexcept
-> std::optional<tree_entries_t>;
/// \brief Create a flat tree from entries and store tree in CAS.
@@ -132,7 +134,7 @@ class GitRepo {
[[nodiscard]] static auto ReadTreeData(
std::string const& data,
std::string const& id,
- SymlinksCheckFunc const& check_symlinks,
+ gsl::not_null<SymlinksCheckFunc> const& check_symlinks,
bool is_hex_id = false) noexcept -> std::optional<tree_entries_t>;
/// \brief Create a flat shallow (without objects in db) tree and return it.