summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_repo.hpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-08-19 09:58:42 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-08-26 12:12:02 +0200
commit959523b077acdbd75adc4c6328e45c43cda3087c (patch)
tree83d1d61b2f83c04c58b0df925b4fece3a48276ab /src/buildtool/file_system/git_repo.hpp
parentc889b852a652115f4a6936a96ebdee9410571997 (diff)
downloadjustbuild-959523b077acdbd75adc4c6328e45c43cda3087c.tar.gz
GitRepo: Add method to create tree from directory
The tree is traversed bottom-up and each entry is explicitly added to the object database: non-directory entries have their content read and are added as blobs with corresponding permissions based on file type (regular, executable, symlink), while subdirectories are added as trees via CreateTree based on the already added blobs.
Diffstat (limited to 'src/buildtool/file_system/git_repo.hpp')
-rw-r--r--src/buildtool/file_system/git_repo.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp
index 31d9eb82..2aabf7ee 100644
--- a/src/buildtool/file_system/git_repo.hpp
+++ b/src/buildtool/file_system/git_repo.hpp
@@ -358,6 +358,25 @@ class GitRepo {
[[nodiscard]] auto GetGitOdb() const noexcept
-> std::unique_ptr<git_odb, decltype(&odb_closer)> const&;
+ using StoreDirEntryFunc =
+ std::function<bool(std::filesystem::path const&, ObjectType type)>;
+
+ /// \brief Helper function to read the entries of a filesystem subdirectory
+ /// and store them to the ODB. It is a modified version of the same-named
+ /// function from FileSystemManager which accepts a subdir and a specific
+ /// logger instead of the default.
+ [[nodiscard]] static auto ReadDirectory(
+ std::filesystem::path const& dir,
+ StoreDirEntryFunc const& read_and_store_entry,
+ anon_logger_ptr const& logger) noexcept -> bool;
+
+ /// \brief Create a tree from the content of a directory by recursively
+ /// adding its entries to the object database.
+ /// \return The raw id of the tree.
+ [[nodiscard]] auto CreateTreeFromDirectory(
+ std::filesystem::path const& dir,
+ anon_logger_ptr const& logger) noexcept -> std::optional<std::string>;
+
/// \brief Helper function to allocate and populate the char** pointer of a
/// git_strarray from a vector of standard strings. User MUST use
/// git_strarray_dispose to deallocate the inner pointer when the strarray