From 59988ee056da790018378199e5f0adc69f01de65 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 29 Sep 2023 12:16:37 +0200 Subject: GitRepo: Add method for async fetch from local repository This avoids using the more geenric GitRepoRemote method which has libcurl as a dependency, something that is not needed for this Git operation. --- src/buildtool/file_system/git_repo.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/buildtool/file_system/git_repo.hpp') diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index 7314289a..9c31f21b 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -22,6 +22,7 @@ extern "C" { struct git_repository; +struct git_config; } /// \brief Git repository logic. @@ -162,6 +163,19 @@ class GitRepo { [[nodiscard]] auto GetHeadCommit(anon_logger_ptr const& logger) noexcept -> std::optional; + /// \brief Fetch from given local repository. It can either fetch a given + /// named branch, or it can fetch with base refspecs. + /// Only possible with real repository and thus non-thread-safe. + /// If non-null, use given config snapshot to interact with config entries; + /// otherwise, use a snapshot from the current repo and share pointer to it. + /// Returns a success flag. It guarantees the logger is called exactly once + /// with fatal if failure. + [[nodiscard]] auto FetchFromPath(std::shared_ptr cfg, + std::string const& repo_path, + std::optional const& branch, + anon_logger_ptr const& logger) noexcept + -> bool; + /// \brief Get the tree id of a subtree given the root commit /// Calling it from a fake repository allows thread-safe use. /// Returns the subtree hash, as a string, or nullopt if failure. @@ -238,6 +252,24 @@ class GitRepo { std::string const& tree_id, std::string const& rel_path) noexcept -> std::optional; + /// \brief Fetch from given local repository via a temporary location. Uses + /// tmp dir to fetch asynchronously using libgit2. + /// Caller needs to make sure the temporary directory exists and that the + /// given path is thread- and process-safe! + /// Uses either a given branch, or fetches all (with base refspecs). + /// Returns a success flag. + /// It guarantees the logger is called exactly once with fatal if failure. + [[nodiscard]] auto LocalFetchViaTmpRepo( + std::filesystem::path const& tmp_dir, + std::string const& repo_path, + std::optional const& branch, + anon_logger_ptr const& logger) noexcept -> bool; + + /// \brief Get a snapshot of the repository configuration. + /// Returns nullptr on errors. + [[nodiscard]] auto GetConfigSnapshot() const noexcept + -> std::shared_ptr; + private: /// \brief Wrapped git_repository with guarded destructor. /// Kept privately nested to avoid misuse of its raw pointer members. -- cgit v1.2.3