summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildtool/file_system/git_repo.cpp41
-rw-r--r--src/buildtool/file_system/git_repo.hpp8
-rw-r--r--src/other_tools/git_operations/git_operations.cpp35
-rw-r--r--src/other_tools/git_operations/git_ops_types.hpp3
-rw-r--r--src/other_tools/ops_maps/critical_git_op_map.cpp3
-rw-r--r--test/other_tools/git_operations/critical_git_ops.test.cpp16
6 files changed, 5 insertions, 101 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp
index d2d6c8ef..e7db261a 100644
--- a/src/buildtool/file_system/git_repo.cpp
+++ b/src/buildtool/file_system/git_repo.cpp
@@ -758,47 +758,6 @@ auto GitRepo::GetHeadCommit(anon_logger_ptr const& logger) noexcept
#endif // BOOTSTRAP_BUILD_TOOL
}
-auto GitRepo::GetBranchLocalRefname(std::string const& branch,
- anon_logger_ptr const& logger) noexcept
- -> std::optional<std::string> {
-#ifdef BOOTSTRAP_BUILD_TOOL
- return std::nullopt;
-#else
- try {
- // only possible for real repository!
- if (IsRepoFake()) {
- (*logger)("cannot retrieve branch refname using a fake repository!",
- true /*fatal*/);
- return std::nullopt;
- }
- // get local reference of branch
- git_reference* local_ref = nullptr;
- if (git_branch_lookup(
- &local_ref, repo_.get(), branch.c_str(), GIT_BRANCH_LOCAL) !=
- 0) {
- (*logger)(fmt::format("retrieving branch {} local reference in git "
- "repository {} failed with:\n{}",
- branch,
- GetGitCAS()->git_path_.string(),
- GitLastError()),
- true /*fatal*/);
- // release resources
- git_reference_free(local_ref);
- return std::nullopt;
- }
- auto refname = std::string(git_reference_name(local_ref));
- // release resources
- git_reference_free(local_ref);
- return refname;
- } catch (std::exception const& ex) {
- Logger::Log(LogLevel::Error,
- "get branch local refname failed with:\n{}",
- ex.what());
- return std::nullopt;
- }
-#endif // BOOTSTRAP_BUILD_TOOL
-}
-
auto GitRepo::GetCommitFromRemote(std::string const& repo_url,
std::string const& branch,
anon_logger_ptr const& logger) noexcept
diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp
index 3e3bf178..160a67df 100644
--- a/src/buildtool/file_system/git_repo.hpp
+++ b/src/buildtool/file_system/git_repo.hpp
@@ -138,14 +138,6 @@ class GitRepo {
[[nodiscard]] auto GetHeadCommit(anon_logger_ptr const& logger) noexcept
-> std::optional<std::string>;
- /// \brief Get the local refname of a given branch.
- /// Only possible with real repository and thus non-thread-safe.
- /// Returns the refname as a string, or nullopt if failure.
- /// It guarantees the logger is called exactly once with fatal if failure.
- [[nodiscard]] auto GetBranchLocalRefname(
- std::string const& branch,
- anon_logger_ptr const& logger) noexcept -> std::optional<std::string>;
-
/// \brief Retrieve commit hash from remote branch given its name.
/// Only possible with real repository and thus non-thread-safe.
/// Returns the retrieved commit hash, or nullopt if failure.
diff --git a/src/other_tools/git_operations/git_operations.cpp b/src/other_tools/git_operations/git_operations.cpp
index bf6b29b3..cdefaef9 100644
--- a/src/other_tools/git_operations/git_operations.cpp
+++ b/src/other_tools/git_operations/git_operations.cpp
@@ -141,38 +141,3 @@ auto CriticalGitOps::GitGetHeadId(GitOpParams const& crit_op_params,
// success
return GitOpValue({git_repo->GetGitCAS(), *head_commit});
}
-
-auto CriticalGitOps::GitGetBranchRefname(
- GitOpParams const& crit_op_params,
- AsyncMapConsumerLoggerPtr const& logger) -> GitOpValue {
- // Make sure folder we want to access exists
- if (not FileSystemManager::Exists(crit_op_params.target_path)) {
- (*logger)(fmt::format("target directory {} does not exist!",
- crit_op_params.target_path.string()),
- true /*fatal*/);
- return GitOpValue{nullptr, std::nullopt};
- }
- // Open a GitRepo at given location
- auto git_repo = GitRepo::Open(crit_op_params.target_path);
- if (git_repo == std::nullopt) {
- (*logger)(fmt::format("could not open git repository {}",
- crit_op_params.target_path.string()),
- true /*fatal*/);
- return GitOpValue{nullptr, std::nullopt};
- }
- // setup wrapped logger
- auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>(
- [logger](auto const& msg, bool fatal) {
- (*logger)(
- fmt::format("While doing get branch refname Git op:\n{}", msg),
- fatal);
- });
- // Get branch refname
- auto branch_refname =
- git_repo->GetBranchLocalRefname(crit_op_params.branch, wrapped_logger);
- if (branch_refname == std::nullopt) {
- return GitOpValue{nullptr, std::nullopt};
- }
- // success
- return GitOpValue{git_repo->GetGitCAS(), *branch_refname};
-}
diff --git a/src/other_tools/git_operations/git_ops_types.hpp b/src/other_tools/git_operations/git_ops_types.hpp
index 078474e6..6befeee3 100644
--- a/src/other_tools/git_operations/git_ops_types.hpp
+++ b/src/other_tools/git_operations/git_ops_types.hpp
@@ -52,8 +52,7 @@ enum class GitOpType {
INITIAL_COMMIT,
ENSURE_INIT,
KEEP_TAG,
- GET_HEAD_ID,
- GET_BRANCH_REFNAME
+ GET_HEAD_ID
};
/// \brief Common return value for all critical Git operations
diff --git a/src/other_tools/ops_maps/critical_git_op_map.cpp b/src/other_tools/ops_maps/critical_git_op_map.cpp
index a365a1d8..7fd3df20 100644
--- a/src/other_tools/ops_maps/critical_git_op_map.cpp
+++ b/src/other_tools/ops_maps/critical_git_op_map.cpp
@@ -19,8 +19,7 @@ GitOpKeyMap const GitOpKey::map_ = {
{GitOpType::INITIAL_COMMIT, CriticalGitOps::GitInitialCommit},
{GitOpType::ENSURE_INIT, CriticalGitOps::GitEnsureInit},
{GitOpType::KEEP_TAG, CriticalGitOps::GitKeepTag},
- {GitOpType::GET_HEAD_ID, CriticalGitOps::GitGetHeadId},
- {GitOpType::GET_BRANCH_REFNAME, CriticalGitOps::GitGetBranchRefname}};
+ {GitOpType::GET_HEAD_ID, CriticalGitOps::GitGetHeadId}};
/// \brief Create a CriticalOpMap object
auto CreateCriticalGitOpMap(CriticalGitOpGuardPtr const& crit_git_op_ptr)
diff --git a/test/other_tools/git_operations/critical_git_ops.test.cpp b/test/other_tools/git_operations/critical_git_ops.test.cpp
index 7c74d352..c7fedda0 100644
--- a/test/other_tools/git_operations/critical_git_ops.test.cpp
+++ b/test/other_tools/git_operations/critical_git_ops.test.cpp
@@ -128,10 +128,6 @@ TEST_CASE("Crtitical git operations", "[critical_git_op_map]") {
// 5. Get head commit -> needs a repo with a commit
auto path_get_head_id = TestUtilsMP::CreateTestRepoWithCheckout(*prefix);
REQUIRE(path_get_head_id);
- // 6. Get local branch refname -> needs a repo with a commit
- auto path_get_branch_refname =
- TestUtilsMP::CreateTestRepoWithCheckout(*prefix);
- REQUIRE(path_get_branch_refname);
// create the map
auto crit_op_guard = std::make_shared<CriticalGitOpGuard>();
@@ -141,9 +137,9 @@ TEST_CASE("Crtitical git operations", "[critical_git_op_map]") {
// should retrieve the value from the map, not call the operation again.
// helper lists
const std::vector<size_t> ops_all{
- 0, 1, 2, 3, 4, 5}; // indices of all ops tested
+ 0, 1, 2, 3, 4}; // indices of all ops tested
const std::vector<size_t> ops_with_result{
- 0, 4, 5}; // indices of ops that return a non-empty string
+ 0, 4}; // indices of ops that return a non-empty string
// Add to the map all ops multiple times
for ([[maybe_unused]] auto const& i :
{0, 0, 0}) { // replace once ranges are available
@@ -189,13 +185,7 @@ TEST_CASE("Crtitical git operations", "[critical_git_op_map]") {
"", // git_hash
"", // branch
},
- GitOpType::GET_HEAD_ID},
- GitOpKey{GitOpParams{
- *path_get_branch_refname, // target_path
- "", // git_hash
- "master", // branch
- },
- GitOpType::GET_BRANCH_REFNAME}},
+ GitOpType::GET_HEAD_ID}},
[&ops_all, &ops_with_result](auto const& values) {
// check operations
for (size_t const& i : ops_all) {