summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_cas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildtool/file_system/git_cas.cpp')
-rw-r--r--src/buildtool/file_system/git_cas.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/buildtool/file_system/git_cas.cpp b/src/buildtool/file_system/git_cas.cpp
index 0f005e46..b96d32fe 100644
--- a/src/buildtool/file_system/git_cas.cpp
+++ b/src/buildtool/file_system/git_cas.cpp
@@ -146,8 +146,8 @@ auto GitCAS::OpenODB(std::filesystem::path const& repo_path) noexcept -> bool {
#else
{ // lock as git_repository API has no thread-safety guarantees
std::unique_lock lock{repo_mutex};
- git_repository* repo = nullptr;
- if (git_repository_open_ext(&repo,
+ git_repository* repo_ptr = nullptr;
+ if (git_repository_open_ext(&repo_ptr,
repo_path.c_str(),
GIT_REPOSITORY_OPEN_NO_SEARCH,
nullptr) != 0) {
@@ -157,16 +157,20 @@ auto GitCAS::OpenODB(std::filesystem::path const& repo_path) noexcept -> bool {
GitLastError());
return false;
}
+ auto const repo =
+ std::unique_ptr<git_repository, decltype(&git_repository_free)>(
+ repo_ptr, git_repository_free);
+
git_odb* odb_ptr{nullptr};
- git_repository_odb(&odb_ptr, repo);
+ git_repository_odb(&odb_ptr, repo.get());
odb_.reset(odb_ptr); // retain odb pointer
// set root
std::filesystem::path git_path{};
- if (git_repository_is_bare(repo) != 0) {
- git_path = ToNormalPath((git_repository_path(repo)));
+ if (git_repository_is_bare(repo.get()) != 0) {
+ git_path = ToNormalPath((git_repository_path(repo.get())));
}
else {
- git_path = ToNormalPath(git_repository_workdir(repo));
+ git_path = ToNormalPath(git_repository_workdir(repo.get()));
}
if (not git_path.is_absolute()) {
try {
@@ -180,8 +184,6 @@ auto GitCAS::OpenODB(std::filesystem::path const& repo_path) noexcept -> bool {
}
}
git_path_ = git_path;
- // release resources
- git_repository_free(repo);
}
if (not odb_) {
Logger::Log(LogLevel::Error,