diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2024-06-27 17:22:32 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2024-06-28 11:24:09 +0200 |
commit | ed7e81b9aefaa47e61983d14c2447bbd1f5c95c5 (patch) | |
tree | 366dc9ab8809cc05f4354c2007bd47281a7c2974 /src/buildtool/file_system/git_repo.cpp | |
parent | 956ed669cf71d1ee74dbb573c542a7565c3a90d3 (diff) | |
download | justbuild-ed7e81b9aefaa47e61983d14c2447bbd1f5c95c5.tar.gz |
Use (un)expected for Git repo
Diffstat (limited to 'src/buildtool/file_system/git_repo.cpp')
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index 4fefc76b..39c0970b 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -1060,9 +1060,9 @@ auto GitRepo::KeepTree(std::string const& tree_id, auto GitRepo::GetSubtreeFromCommit(std::string const& commit, std::string const& subdir, anon_logger_ptr const& logger) noexcept - -> std::variant<bool, std::string> { + -> expected<std::string, GitLookupError> { #ifdef BOOTSTRAP_BUILD_TOOL - return true; + return unexpected{GitLookupError::Fatal}; #else try { // preferably with a "fake" repository! @@ -1083,7 +1083,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, GetGitCAS()->git_path_.string(), GitLastError()), true /*fatal*/); - return true; // fatal failure + return unexpected{GitLookupError::Fatal}; } git_commit* commit_ptr{nullptr}; @@ -1096,7 +1096,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, true /*fatal*/); // cleanup resources git_commit_free(commit_ptr); - return false; // non-fatal failure + return unexpected{GitLookupError::NotFound}; // non-fatal failure } auto commit_obj = std::unique_ptr<git_commit, decltype(&commit_closer)>( commit_ptr, commit_closer); @@ -1113,7 +1113,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, true /*fatal*/); // cleanup resources git_tree_free(tree_ptr); - return true; // fatal failure + return unexpected{GitLookupError::Fatal}; } auto tree = std::unique_ptr<git_tree, decltype(&tree_closer)>( tree_ptr, tree_closer); @@ -1132,7 +1132,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, true /*fatal*/); // cleanup resources git_tree_entry_free(subtree_entry_ptr); - return true; // fatal failure + return unexpected{GitLookupError::Fatal}; } auto subtree_entry = std::unique_ptr<git_tree_entry, decltype(&tree_entry_closer)>( @@ -1149,7 +1149,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, Logger::Log(LogLevel::Error, "get subtree from commit failed with:\n{}", ex.what()); - return true; // fatal failure + return unexpected{GitLookupError::Fatal}; } #endif // BOOTSTRAP_BUILD_TOOL } @@ -1274,10 +1274,10 @@ auto GitRepo::GetSubtreeFromPath(std::filesystem::path const& fpath, auto subdir = std::filesystem::relative(fpath, *root).string(); // get subtree from head commit and subdir auto res = GetSubtreeFromCommit(head_commit, subdir, wrapped_logger); - if (std::holds_alternative<bool>(res)) { + if (not res) { return std::nullopt; } - return std::get<std::string>(res); + return *std::move(res); } catch (std::exception const& ex) { Logger::Log(LogLevel::Error, "get subtree from path failed with:\n{}", |