summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-04-05 16:18:28 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-04-10 15:25:45 +0200
commitc60eb6dfb22f28f638caff578b8815d3c4753bdc (patch)
tree86218d88394db7585377a0eb13a329101e79bd4a /src
parentd3ec6b7294d44e1cd524ac5bbb9048d415950e99 (diff)
downloadjustbuild-c60eb6dfb22f28f638caff578b8815d3c4753bdc.tar.gz
Add KeepTree to critical Git operations
Also improves and extends accordingly the Git operations tests.
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/git_operations/git_operations.cpp34
-rw-r--r--src/other_tools/git_operations/git_operations.hpp8
-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
4 files changed, 46 insertions, 2 deletions
diff --git a/src/other_tools/git_operations/git_operations.cpp b/src/other_tools/git_operations/git_operations.cpp
index 74f1d323..81375130 100644
--- a/src/other_tools/git_operations/git_operations.cpp
+++ b/src/other_tools/git_operations/git_operations.cpp
@@ -143,3 +143,37 @@ auto CriticalGitOps::GitGetHeadId(GitOpParams const& crit_op_params,
// success
return {.git_cas = git_repo->GetGitCAS(), .result = *head_commit};
}
+
+auto CriticalGitOps::GitKeepTree(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 {.git_cas = nullptr, .result = std::nullopt};
+ }
+ // Open a GitRepo at given location
+ auto git_repo = GitRepoRemote::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 {.git_cas = nullptr, .result = std::nullopt};
+ }
+ // setup wrapped logger
+ auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>(
+ [logger](auto const& msg, bool fatal) {
+ (*logger)(fmt::format("While doing keep tree Git op:\n{}", msg),
+ fatal);
+ });
+ // Create tag for given tree
+ if (not git_repo->KeepTree(crit_op_params.git_hash,
+ crit_op_params.message.value(),
+ wrapped_logger)) {
+ return {.git_cas = nullptr, .result = std::nullopt};
+ }
+ // success
+ return {.git_cas = git_repo->GetGitCAS(), .result = ""};
+}
diff --git a/src/other_tools/git_operations/git_operations.hpp b/src/other_tools/git_operations/git_operations.hpp
index e034664e..44eec96a 100644
--- a/src/other_tools/git_operations/git_operations.hpp
+++ b/src/other_tools/git_operations/git_operations.hpp
@@ -53,6 +53,14 @@ class CriticalGitOps {
[[nodiscard]] static auto GitGetHeadId(
GitOpParams const& crit_op_params,
AsyncMapConsumerLoggerPtr const& logger) -> GitOpValue;
+
+ // This operation needs the params: target_path, git_hash (tree), message
+ // Called after resolving symlinks in a tree to retain the resolved tree
+ // by tagging it. Assumes folder exists.
+ // It guarantees the logger is called exactly once with fatal if failure.
+ [[nodiscard]] static auto GitKeepTree(
+ GitOpParams const& crit_op_params,
+ AsyncMapConsumerLoggerPtr const& logger) -> GitOpValue;
};
#endif // INCLUDED_SRC_OTHER_TOOLS_GIT_OPERATIONS_GIT_OPERATIONS_HPP \ No newline at end of file
diff --git a/src/other_tools/git_operations/git_ops_types.hpp b/src/other_tools/git_operations/git_ops_types.hpp
index 0147ee57..c30d5819 100644
--- a/src/other_tools/git_operations/git_ops_types.hpp
+++ b/src/other_tools/git_operations/git_ops_types.hpp
@@ -57,7 +57,8 @@ enum class GitOpType {
INITIAL_COMMIT,
ENSURE_INIT,
KEEP_TAG,
- GET_HEAD_ID
+ GET_HEAD_ID,
+ KEEP_TREE
};
/// \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 7fd3df20..cbab7c42 100644
--- a/src/other_tools/ops_maps/critical_git_op_map.cpp
+++ b/src/other_tools/ops_maps/critical_git_op_map.cpp
@@ -19,7 +19,8 @@ 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_HEAD_ID, CriticalGitOps::GitGetHeadId},
+ {GitOpType::KEEP_TREE, CriticalGitOps::GitKeepTree}};
/// \brief Create a CriticalOpMap object
auto CreateCriticalGitOpMap(CriticalGitOpGuardPtr const& crit_git_op_ptr)