diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-08-19 16:01:16 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-08-26 12:12:00 +0200 |
commit | c889b852a652115f4a6936a96ebdee9410571997 (patch) | |
tree | e553f21acab38fc4466adda19a378952df6a7eb6 /src | |
parent | a312e71b59340f7b6d8dc5aac9202137ae81d02b (diff) | |
download | justbuild-c889b852a652115f4a6936a96ebdee9410571997.tar.gz |
GitOps: Pass source directory to GitInitialCommit operation
While there, ensure optional Git operation parameters are checked
before use for the operations that require them.
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/git_operations/git_operations.cpp | 38 | ||||
-rw-r--r-- | src/other_tools/git_operations/git_ops_types.hpp | 15 | ||||
-rw-r--r-- | src/other_tools/ops_maps/content_cas_map.cpp | 1 | ||||
-rw-r--r-- | src/other_tools/ops_maps/git_tree_fetch_map.cpp | 2 | ||||
-rw-r--r-- | src/other_tools/ops_maps/import_to_git_map.cpp | 2 | ||||
-rw-r--r-- | src/other_tools/root_maps/commit_git_map.cpp | 2 | ||||
-rw-r--r-- | src/other_tools/root_maps/content_git_map.cpp | 3 | ||||
-rw-r--r-- | src/other_tools/root_maps/distdir_git_map.cpp | 1 | ||||
-rw-r--r-- | src/other_tools/root_maps/fpath_git_map.cpp | 1 | ||||
-rw-r--r-- | src/other_tools/root_maps/tree_id_git_map.cpp | 1 |
10 files changed, 57 insertions, 9 deletions
diff --git a/src/other_tools/git_operations/git_operations.cpp b/src/other_tools/git_operations/git_operations.cpp index bfd1d18f..5135743f 100644 --- a/src/other_tools/git_operations/git_operations.cpp +++ b/src/other_tools/git_operations/git_operations.cpp @@ -25,6 +25,19 @@ auto CriticalGitOps::GitInitialCommit(GitOpParams const& crit_op_params, AsyncMapConsumerLoggerPtr const& logger) -> GitOpValue { +#ifndef NDEBUG + // Check required fields have been set + if (not crit_op_params.message) { + (*logger)("missing message for operation creating commit", + true /*fatal*/); + return {.git_cas = nullptr, .result = std::nullopt}; + } + if (not crit_op_params.source_path) { + (*logger)("missing source_path for operation creating commit", + true /*fatal*/); + return {.git_cas = nullptr, .result = std::nullopt}; + } +#endif // Create and open a GitRepoRemote at given target location auto git_repo = GitRepoRemote::InitAndOpen(crit_op_params.target_path, /*is_bare=*/false); @@ -41,10 +54,11 @@ auto CriticalGitOps::GitInitialCommit(GitOpParams const& crit_op_params, fmt::format("While doing initial commit Git op:\n{}", msg), fatal); }); - // Stage and commit all at the target location - auto commit_hash = git_repo->CommitDirectory(crit_op_params.target_path, - crit_op_params.message.value(), - wrapped_logger); + // Commit all at the target directory + auto commit_hash = + git_repo->CommitDirectory(crit_op_params.source_path.value(), + crit_op_params.message.value(), + wrapped_logger); if (commit_hash == std::nullopt) { return {.git_cas = nullptr, .result = std::nullopt}; } @@ -81,6 +95,14 @@ auto CriticalGitOps::GitEnsureInit(GitOpParams const& crit_op_params, auto CriticalGitOps::GitKeepTag(GitOpParams const& crit_op_params, AsyncMapConsumerLoggerPtr const& logger) -> GitOpValue { +#ifndef NDEBUG + // Check required fields have been set + if (not crit_op_params.message) { + (*logger)("missing message for operation tagging a commit", + true /*fatal*/); + return {.git_cas = nullptr, .result = std::nullopt}; + } +#endif // 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!", @@ -149,6 +171,14 @@ auto CriticalGitOps::GitGetHeadId(GitOpParams const& crit_op_params, auto CriticalGitOps::GitKeepTree(GitOpParams const& crit_op_params, AsyncMapConsumerLoggerPtr const& logger) -> GitOpValue { +#ifndef NDEBUG + // Check required fields have been set + if (not crit_op_params.message) { + (*logger)("missing message for operation keeping a tree comitted", + true /*fatal*/); + return {.git_cas = nullptr, .result = std::nullopt}; + } +#endif // 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!", diff --git a/src/other_tools/git_operations/git_ops_types.hpp b/src/other_tools/git_operations/git_ops_types.hpp index 3dfdd4a8..2c60b086 100644 --- a/src/other_tools/git_operations/git_ops_types.hpp +++ b/src/other_tools/git_operations/git_ops_types.hpp @@ -28,16 +28,21 @@ struct GitOpParams { std::filesystem::path target_path{}; /*key*/ std::string git_hash{}; /*key*/ std::optional<std::string> message{ - std::nullopt}; // useful for commits and tags + std::nullopt}; // mandatory for commits and tags + std::optional<std::filesystem::path> source_path{ + std::nullopt}; // mandatory for commits std::optional<bool> init_bare{std::nullopt}; // useful for git init - GitOpParams(std::filesystem::path const& target_path_, - std::string git_hash_, - std::optional<std::string> message_ = std::nullopt, - std::optional<bool> init_bare_ = std::nullopt) + GitOpParams( + std::filesystem::path const& target_path_, + std::string git_hash_, + std::optional<std::string> message_ = std::nullopt, + std::optional<std::filesystem::path> source_path_ = std::nullopt, + std::optional<bool> init_bare_ = std::nullopt) : target_path{std::filesystem::absolute(ToNormalPath(target_path_))}, git_hash{std::move(git_hash_)}, message{std::move(message_)}, + source_path{std::move(source_path_)}, init_bare{init_bare_} {}; [[nodiscard]] auto operator==(GitOpParams const& other) const noexcept diff --git a/src/other_tools/ops_maps/content_cas_map.cpp b/src/other_tools/ops_maps/content_cas_map.cpp index 0c6ccd25..95518326 100644 --- a/src/other_tools/ops_maps/content_cas_map.cpp +++ b/src/other_tools/ops_maps/content_cas_map.cpp @@ -138,6 +138,7 @@ auto CreateContentCASMap( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; diff --git a/src/other_tools/ops_maps/git_tree_fetch_map.cpp b/src/other_tools/ops_maps/git_tree_fetch_map.cpp index cceda079..7a4d9e0a 100644 --- a/src/other_tools/ops_maps/git_tree_fetch_map.cpp +++ b/src/other_tools/ops_maps/git_tree_fetch_map.cpp @@ -272,6 +272,7 @@ auto CreateGitTreeFetchMap( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; @@ -457,6 +458,7 @@ auto CreateGitTreeFetchMap( "", // git_hash fmt::format("Content of tree {}", key.hash), // message + tmp_dir->GetPath() // source_path }, .op_type = GitOpType::INITIAL_COMMIT}; critical_git_op_map->ConsumeAfterKeysReady( diff --git a/src/other_tools/ops_maps/import_to_git_map.cpp b/src/other_tools/ops_maps/import_to_git_map.cpp index 7e9331b0..e883e0dd 100644 --- a/src/other_tools/ops_maps/import_to_git_map.cpp +++ b/src/other_tools/ops_maps/import_to_git_map.cpp @@ -109,6 +109,7 @@ auto CreateImportToGitMap( fmt::format("Content of {} {}", key.repo_type, key.content), // message + key.target_path // source_path }, .op_type = GitOpType::INITIAL_COMMIT}; critical_git_op_map->ConsumeAfterKeysReady( @@ -137,6 +138,7 @@ auto CreateImportToGitMap( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp index 873f7484..2d64d599 100644 --- a/src/other_tools/root_maps/commit_git_map.cpp +++ b/src/other_tools/root_maps/commit_git_map.cpp @@ -691,6 +691,7 @@ void EnsureCommit(GitRepoInfo const& repo_info, storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; @@ -1102,6 +1103,7 @@ auto CreateCommitGitMap( repo_root, // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path not just_mr_paths->git_checkout_locations.contains( fetch_repo) // init_bare }, diff --git a/src/other_tools/root_maps/content_git_map.cpp b/src/other_tools/root_maps/content_git_map.cpp index 38aa21a6..d0b9784c 100644 --- a/src/other_tools/root_maps/content_git_map.cpp +++ b/src/other_tools/root_maps/content_git_map.cpp @@ -546,6 +546,7 @@ void HandleLocallyKnownTree( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; @@ -758,6 +759,7 @@ void HandleKnownInOlderGenerationAfterTagging( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; @@ -1019,6 +1021,7 @@ auto CreateContentGitMap( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; diff --git a/src/other_tools/root_maps/distdir_git_map.cpp b/src/other_tools/root_maps/distdir_git_map.cpp index 2d2ad107..4a7e9b51 100644 --- a/src/other_tools/root_maps/distdir_git_map.cpp +++ b/src/other_tools/root_maps/distdir_git_map.cpp @@ -173,6 +173,7 @@ auto CreateDistdirGitMap( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; diff --git a/src/other_tools/root_maps/fpath_git_map.cpp b/src/other_tools/root_maps/fpath_git_map.cpp index d4a46486..37b0c543 100644 --- a/src/other_tools/root_maps/fpath_git_map.cpp +++ b/src/other_tools/root_maps/fpath_git_map.cpp @@ -350,6 +350,7 @@ auto CreateFilePathGitMap( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; diff --git a/src/other_tools/root_maps/tree_id_git_map.cpp b/src/other_tools/root_maps/tree_id_git_map.cpp index 3a33d11b..78c1cffd 100644 --- a/src/other_tools/root_maps/tree_id_git_map.cpp +++ b/src/other_tools/root_maps/tree_id_git_map.cpp @@ -235,6 +235,7 @@ auto CreateTreeIdGitMap( storage_config->GitRoot(), // target_path "", // git_hash std::nullopt, // message + std::nullopt, // source_path true // init_bare }, .op_type = GitOpType::ENSURE_INIT}; |