summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_repo.cpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-05-30 17:58:38 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-06-26 17:57:29 +0200
commit39fc14811a67cc4381de726840e7b852f7d126c9 (patch)
tree296b8e1394ec3a09042db71b48b0d3b8a05d0f15 /src/buildtool/file_system/git_repo.cpp
parent0b924c5c23a89760ddecf8d8f6baa19333f9b667 (diff)
downloadjustbuild-39fc14811a67cc4381de726840e7b852f7d126c9.tar.gz
ObjectType: Add non-upwards symlinks as a known object type...
...but make sure it is still considered a special type. The only non-special entry types remain file, executable, and tree.
Diffstat (limited to 'src/buildtool/file_system/git_repo.cpp')
-rw-r--r--src/buildtool/file_system/git_repo.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp
index 01db8269..e10da57e 100644
--- a/src/buildtool/file_system/git_repo.cpp
+++ b/src/buildtool/file_system/git_repo.cpp
@@ -17,6 +17,7 @@
#include <thread>
#include <unordered_set>
+#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/gsl.hpp"
#include "src/utils/cpp/hex_string.hpp"
@@ -30,7 +31,8 @@ extern "C" {
#ifndef BOOTSTRAP_BUILD_TOOL
namespace {
-std::unordered_set<git_filemode_t> const kSupportedGitFileModes{
+/// \brief libgit2 file modes corresponding to non-special entries.
+std::unordered_set<git_filemode_t> const kNonSpecialGitFileModes{
GIT_FILEMODE_BLOB,
GIT_FILEMODE_BLOB_EXECUTABLE,
GIT_FILEMODE_TREE};
@@ -53,9 +55,9 @@ std::unordered_set<git_filemode_t> const kSupportedGitFileModes{
}
/// \brief Returns true if mode corresponds to a supported object type.
-[[nodiscard]] auto GitFileModeIsSupported(git_filemode_t const& mode) noexcept
+[[nodiscard]] auto GitFileModeIsNonSpecial(git_filemode_t const& mode) noexcept
-> bool {
- return kSupportedGitFileModes.contains(mode);
+ return kNonSpecialGitFileModes.contains(mode);
}
[[nodiscard]] auto GitFileModeToObjectType(git_filemode_t const& mode) noexcept
@@ -67,6 +69,8 @@ std::unordered_set<git_filemode_t> const kSupportedGitFileModes{
return ObjectType::Executable;
case GIT_FILEMODE_TREE:
return ObjectType::Tree;
+ case GIT_FILEMODE_LINK:
+ return ObjectType::Symlink; // condition not tested here
default: {
std::ostringstream str;
str << std::oct << static_cast<int>(mode);
@@ -86,6 +90,8 @@ std::unordered_set<git_filemode_t> const kSupportedGitFileModes{
return GIT_FILEMODE_BLOB_EXECUTABLE;
case ObjectType::Tree:
return GIT_FILEMODE_TREE;
+ case ObjectType::Symlink:
+ return GIT_FILEMODE_LINK;
}
return GIT_FILEMODE_UNREADABLE; // make gcc happy
}
@@ -132,11 +138,12 @@ std::unordered_set<git_filemode_t> const kSupportedGitFileModes{
std::string name = git_tree_entry_name(entry);
auto const* oid = git_tree_entry_id(entry);
if (auto raw_id = ToRawString(*oid)) {
- if (not GitFileModeIsSupported(git_tree_entry_filemode(entry))) {
+ if (not GitFileModeIsNonSpecial(git_tree_entry_filemode(entry))) {
return 0; // allow, but not store
}
if (auto type =
GitFileModeToObjectType(git_tree_entry_filemode(entry))) {
+ // no need to test for symlinks, as no symlink entry will reach this
(*entries)[*raw_id].emplace_back(std::move(name), *type);
return 1; // return >=0 on success, 1 == skip subtrees (flat)
}
@@ -156,6 +163,7 @@ std::unordered_set<git_filemode_t> const kSupportedGitFileModes{
if (auto raw_id = ToRawString(*oid)) {
if (auto type =
GitFileModeToObjectType(git_tree_entry_filemode(entry))) {
+ // symlinks need to be checked in caller for non-upwardness
(*entries)[*raw_id].emplace_back(std::move(name), *type);
return 1; // return >=0 on success, 1 == skip subtrees (flat)
}