diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-08-29 19:01:36 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-12-21 14:44:08 +0100 |
commit | 2c994adbd2d5778bb881bd792a57294f86e143b1 (patch) | |
tree | 653250cbd6c5c38667ac69de406be4735ba4f541 /src/buildtool/file_system/git_repo.hpp | |
parent | ecff253633ada6ca88db8ab207c593ebde033044 (diff) | |
download | justbuild-2c994adbd2d5778bb881bd792a57294f86e143b1.tar.gz |
Git: Wrap libgit2 raw pointers
Diffstat (limited to 'src/buildtool/file_system/git_repo.hpp')
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index a9ef232a..ecd3c776 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -17,11 +17,6 @@ #include "src/buildtool/file_system/git_cas.hpp" -extern "C" { -using git_repository = struct git_repository; -using git_strarray = struct git_strarray; -} - /// \brief Git repository logic. /// Models both a real repository, owning the underlying ODB /// (non-thread-safe), as well as a "fake" repository, which only wraps an @@ -48,6 +43,7 @@ class GitRepo { std::unordered_map<std::string, std::vector<tree_entry_t>>; GitRepo() = delete; // no default ctor + ~GitRepo() noexcept = default; // allow only move, no copy GitRepo(GitRepo const&) = delete; @@ -246,11 +242,12 @@ class GitRepo { anon_logger_ptr const& logger) noexcept -> std::optional<std::filesystem::path>; - ~GitRepo() noexcept; - private: + // IMPORTANT! The GitCAS object must be defined before the repo object to + // keep the GitContext alive until cleanup ends. GitCASPtr git_cas_{nullptr}; - git_repository* repo_{nullptr}; + std::unique_ptr<git_repository, decltype(&repo_closer)> repo_{nullptr, + repo_closer}; // default to real repo, as that is non-thread-safe bool is_repo_fake_{false}; |