summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-02-20 09:52:35 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-03-03 16:20:52 +0100
commit07864376504efde66c1e7b1b5185f84a531fe64c (patch)
tree62afac72f8f5828e7e2a41c838df9bdd221225e3
parent6dcc58ed7745f2446107dce8c1cf69530c866dc1 (diff)
downloadjustbuild-07864376504efde66c1e7b1b5185f84a531fe64c.tar.gz
GitRepoRemote: Add getter for config snapshot
-rw-r--r--src/buildtool/file_system/git_utils.cpp6
-rw-r--r--src/buildtool/file_system/git_utils.hpp3
-rw-r--r--src/other_tools/git_operations/TARGETS1
-rw-r--r--src/other_tools/git_operations/git_repo_remote.cpp9
-rw-r--r--src/other_tools/git_operations/git_repo_remote.hpp8
5 files changed, 27 insertions, 0 deletions
diff --git a/src/buildtool/file_system/git_utils.cpp b/src/buildtool/file_system/git_utils.cpp
index 9fccbd9d..a38fae39 100644
--- a/src/buildtool/file_system/git_utils.cpp
+++ b/src/buildtool/file_system/git_utils.cpp
@@ -148,3 +148,9 @@ void tree_entry_closer(gsl::owner<git_tree_entry*> tree_entry) {
git_tree_entry_free(tree_entry);
#endif
}
+
+void config_closer(gsl::owner<git_config*> cfg) {
+#ifndef BOOTSTRAP_BUILD_TOOL
+ git_config_free(cfg);
+#endif
+}
diff --git a/src/buildtool/file_system/git_utils.hpp b/src/buildtool/file_system/git_utils.hpp
index d301912a..68eb670b 100644
--- a/src/buildtool/file_system/git_utils.hpp
+++ b/src/buildtool/file_system/git_utils.hpp
@@ -33,6 +33,7 @@ struct git_object;
struct git_remote;
struct git_commit;
struct git_tree_entry;
+struct git_config;
}
constexpr std::size_t kWaitTime{2}; // time in ms between tries for git locks
@@ -70,4 +71,6 @@ void commit_closer(gsl::owner<git_commit*> commit);
void tree_entry_closer(gsl::owner<git_tree_entry*> tree_entry);
+void config_closer(gsl::owner<git_config*> cfg);
+
#endif // INCLUDED_SRC_BUILDTOOL_FILE_SYSTEM_GIT_UTILS_HPP
diff --git a/src/other_tools/git_operations/TARGETS b/src/other_tools/git_operations/TARGETS
index 28e514f0..7f5dede1 100644
--- a/src/other_tools/git_operations/TARGETS
+++ b/src/other_tools/git_operations/TARGETS
@@ -29,6 +29,7 @@
, "stage": ["src", "other_tools", "git_operations"]
, "private-deps":
[ ["src/buildtool/logging", "logging"]
+ , ["src/buildtool/file_system", "git_utils"]
, ["@", "fmt", "", "fmt"]
, ["", "libgit2"]
]
diff --git a/src/other_tools/git_operations/git_repo_remote.cpp b/src/other_tools/git_operations/git_repo_remote.cpp
index 177a4301..7d2ee7f4 100644
--- a/src/other_tools/git_operations/git_repo_remote.cpp
+++ b/src/other_tools/git_operations/git_repo_remote.cpp
@@ -15,6 +15,7 @@
#include <src/other_tools/git_operations/git_repo_remote.hpp>
#include "fmt/core.h"
+#include "src/buildtool/file_system/git_utils.hpp"
#include "src/buildtool/logging/logger.hpp"
extern "C" {
@@ -403,3 +404,11 @@ auto GitRepoRemote::FetchViaTmpRepo(std::filesystem::path const& tmp_repo_path,
return false;
}
}
+
+auto GitRepoRemote::GetConfigSnapshot() const -> std::shared_ptr<git_config> {
+ git_config* cfg_ptr{nullptr};
+ if (git_repository_config_snapshot(&cfg_ptr, GetRepoRef().get()) != 0) {
+ return nullptr;
+ }
+ return std::shared_ptr<git_config>(cfg_ptr, config_closer);
+}
diff --git a/src/other_tools/git_operations/git_repo_remote.hpp b/src/other_tools/git_operations/git_repo_remote.hpp
index 83099994..334f7fca 100644
--- a/src/other_tools/git_operations/git_repo_remote.hpp
+++ b/src/other_tools/git_operations/git_repo_remote.hpp
@@ -17,6 +17,10 @@
#include "src/buildtool/file_system/git_repo.hpp"
+extern "C" {
+struct git_config;
+}
+
/// \brief Extension to a Git repository, allowing remote Git operations.
class GitRepoRemote : public GitRepo {
public:
@@ -93,6 +97,10 @@ class GitRepoRemote : public GitRepo {
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 -> std::shared_ptr<git_config>;
+
private:
/// \brief Open "fake" repository wrapper for existing CAS.
explicit GitRepoRemote(GitCASPtr git_cas) noexcept;