diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/main.cpp | 10 | ||||
-rw-r--r-- | src/other_tools/just_mr/utils.hpp | 13 | ||||
-rw-r--r-- | src/other_tools/repo_map/repos_to_setup_map.cpp | 35 |
3 files changed, 42 insertions, 16 deletions
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp index af6589bc..cc33f5f3 100644 --- a/src/other_tools/just_mr/main.cpp +++ b/src/other_tools/just_mr/main.cpp @@ -793,8 +793,11 @@ void DefaultReachableRepositories( repo_desc_pragma ? repo_desc_pragma->get()->At("special") : std::nullopt; auto pragma_special_value = - pragma_special and pragma_special->get()->IsString() - ? std::make_optional(pragma_special->get()->String()) + pragma_special and pragma_special->get()->IsString() and + kPragmaSpecialMap.contains( + pragma_special->get()->String()) + ? std::make_optional(kPragmaSpecialMap.at( + pragma_special->get()->String())) : std::nullopt; ArchiveRepoInfo archive_info = { @@ -817,7 +820,8 @@ void DefaultReachableRepositories( .origin_from_distdir = false}, .repo_type = repo_type_str, .subdir = subdir.empty() ? "." : subdir.string(), - .ignore_special = pragma_special_value == "ignore"}; + .ignore_special = + pragma_special_value == PragmaSpecial::Ignore}; // add to list repos_to_fetch.emplace_back(std::move(archive_info)); } diff --git a/src/other_tools/just_mr/utils.hpp b/src/other_tools/just_mr/utils.hpp index 5caf33d0..67878445 100644 --- a/src/other_tools/just_mr/utils.hpp +++ b/src/other_tools/just_mr/utils.hpp @@ -89,6 +89,19 @@ std::unordered_map<std::string, CheckoutType> const kCheckoutTypeMap = { {"distdir", CheckoutType::Distdir}, {"git tree", CheckoutType::GitTree}}; +/// \brief Pragma "special" value enum +enum class PragmaSpecial : std::uint8_t { + Ignore, + ResolvePartially, + ResolveCompletely +}; + +/// \brief Pragma "special" value map +std::unordered_map<std::string, PragmaSpecial> const kPragmaSpecialMap = { + {"ignore", PragmaSpecial::Ignore}, + {"resolve-partially", PragmaSpecial::ResolvePartially}, + {"resolve-completely", PragmaSpecial::ResolveCompletely}}; + namespace JustMR { struct Paths { diff --git a/src/other_tools/repo_map/repos_to_setup_map.cpp b/src/other_tools/repo_map/repos_to_setup_map.cpp index 19dc7538..a07ebaa6 100644 --- a/src/other_tools/repo_map/repos_to_setup_map.cpp +++ b/src/other_tools/repo_map/repos_to_setup_map.cpp @@ -97,8 +97,10 @@ void GitCheckout(ExpressionPtr const& repo_desc, ? repo_desc_pragma->get()->At("special") : std::nullopt; auto pragma_special_value = - pragma_special and pragma_special->get()->IsString() - ? std::make_optional(pragma_special->get()->String()) + pragma_special and pragma_special->get()->IsString() and + kPragmaSpecialMap.contains(pragma_special->get()->String()) + ? std::make_optional( + kPragmaSpecialMap.at(pragma_special->get()->String())) : std::nullopt; // populate struct GitRepoInfo git_repo_info = { @@ -107,7 +109,7 @@ void GitCheckout(ExpressionPtr const& repo_desc, .branch = repo_desc_branch->get()->String(), .subdir = subdir.empty() ? "." : subdir.string(), .origin = repo_name, - .ignore_special = pragma_special_value == "ignore"}; + .ignore_special = pragma_special_value == PragmaSpecial::Ignore}; // get the WS root as git tree commit_git_map->ConsumeAfterKeysReady( ts, @@ -185,8 +187,10 @@ void ArchiveCheckout(ExpressionPtr const& repo_desc, ? repo_desc_pragma->get()->At("special") : std::nullopt; auto pragma_special_value = - pragma_special and pragma_special->get()->IsString() - ? std::make_optional(pragma_special->get()->String()) + pragma_special and pragma_special->get()->IsString() and + kPragmaSpecialMap.contains(pragma_special->get()->String()) + ? std::make_optional( + kPragmaSpecialMap.at(pragma_special->get()->String())) : std::nullopt; // populate struct ArchiveRepoInfo archive_repo_info = { @@ -206,7 +210,7 @@ void ArchiveCheckout(ExpressionPtr const& repo_desc, .origin_from_distdir = false}, .repo_type = repo_type, .subdir = subdir.empty() ? "." : subdir.string(), - .ignore_special = pragma_special_value == "ignore"}; + .ignore_special = pragma_special_value == PragmaSpecial::Ignore}; // get the WS root as git tree content_git_map->ConsumeAfterKeysReady( ts, @@ -266,8 +270,10 @@ void FileCheckout(ExpressionPtr const& repo_desc, ? repo_desc_pragma->get()->At("special") : std::nullopt; auto pragma_special_value = - pragma_special and pragma_special->get()->IsString() - ? std::make_optional(pragma_special->get()->String()) + pragma_special and pragma_special->get()->IsString() and + kPragmaSpecialMap.contains(pragma_special->get()->String()) + ? std::make_optional( + kPragmaSpecialMap.at(pragma_special->get()->String())) : std::nullopt; // check "to_git" pragma auto pragma_to_git = @@ -276,7 +282,8 @@ void FileCheckout(ExpressionPtr const& repo_desc, pragma_to_git->get()->Bool()) { // get the WS root as git tree FpathInfo fpath_info = { - .fpath = fpath, .ignore_special = pragma_special_value == "ignore"}; + .fpath = fpath, + .ignore_special = pragma_special_value == PragmaSpecial::Ignore}; fpath_git_map->ConsumeAfterKeysReady( ts, {std::move(fpath_info)}, @@ -301,7 +308,7 @@ void FileCheckout(ExpressionPtr const& repo_desc, // get the WS root as filesystem location nlohmann::json cfg({}); cfg["workspace_root"] = - nlohmann::json::array({pragma_special_value == "ignore" + nlohmann::json::array({pragma_special_value == PragmaSpecial::Ignore ? FileRoot::kFileIgnoreSpecialMarker : "file", fpath.string()}); // explicit array @@ -572,15 +579,17 @@ void GitTreeCheckout(ExpressionPtr const& repo_desc, ? repo_desc_pragma->get()->At("special") : std::nullopt; auto pragma_special_value = - pragma_special and pragma_special->get()->IsString() - ? std::make_optional(pragma_special->get()->String()) + pragma_special and pragma_special->get()->IsString() and + kPragmaSpecialMap.contains(pragma_special->get()->String()) + ? std::make_optional( + kPragmaSpecialMap.at(pragma_special->get()->String())) : std::nullopt; // populate struct TreeIdInfo tree_id_info = { .hash = repo_desc_hash->get()->String(), .env_vars = std::move(env), .command = std::move(cmd), - .ignore_special = pragma_special_value == "ignore"}; + .ignore_special = pragma_special_value == PragmaSpecial::Ignore}; // get the WS root as git tree tree_id_git_map->ConsumeAfterKeysReady( ts, |