diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-01-23 14:53:03 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-01-24 15:47:31 +0100 |
commit | 7f98d19a8c6a6697e246338d2c3a0640cd9528c8 (patch) | |
tree | 9013ea406c9d945ef0a622a89bd38b3830fa82b5 /src | |
parent | 7c3313a3baaa3695081a9c17b521931877babad6 (diff) | |
download | justbuild-7f98d19a8c6a6697e246338d2c3a0640cd9528c8.tar.gz |
Just-MR: Remove obsolete GET_BRANCH_REFNAME critical Git operation
As now all remote Git operations in GitRepo require at most just
the branch name, there is no more need to inquire the repository
about branch refspecs.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 41 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 8 | ||||
-rw-r--r-- | src/other_tools/git_operations/git_operations.cpp | 35 | ||||
-rw-r--r-- | src/other_tools/git_operations/git_ops_types.hpp | 3 | ||||
-rw-r--r-- | src/other_tools/ops_maps/critical_git_op_map.cpp | 3 |
5 files changed, 2 insertions, 88 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) |