summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_repo.hpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-09-29 12:16:37 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-02 12:06:50 +0100
commit59988ee056da790018378199e5f0adc69f01de65 (patch)
tree90df2bec7ce6e957f8953084f082ab4bd4cfa42e /src/buildtool/file_system/git_repo.hpp
parent1f997bfa62e5feac45f84fbc2ae7ee62ffd40f3d (diff)
downloadjustbuild-59988ee056da790018378199e5f0adc69f01de65.tar.gz
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.
Diffstat (limited to 'src/buildtool/file_system/git_repo.hpp')
-rw-r--r--src/buildtool/file_system/git_repo.hpp32
1 files changed, 32 insertions, 0 deletions
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<std::string>;
+ /// \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<git_config> cfg,
+ std::string const& repo_path,
+ std::optional<std::string> 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<TreeEntryInfo>;
+ /// \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<std::string> 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<git_config>;
+
private:
/// \brief Wrapped git_repository with guarded destructor.
/// Kept privately nested to avoid misuse of its raw pointer members.