From 3dc81b4b5a89f4e37af45ec9954723c79c3017cf Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 29 Jan 2024 16:27:40 +0100 Subject: serve source tree: Increase server-side granularity in response statuses For archives and Git repositories we should ensure that not finding the witnessing entity (archive content blob or Git commit, respectively) results in a distinct status in the response to a request that sets up roots on the serve endpoint. This will allow just-mr to better handle its interaction with the serve endpoint. --- src/buildtool/file_system/git_repo.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/buildtool/file_system/git_repo.cpp') diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index f679647e..72f85f6a 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -932,9 +932,9 @@ auto GitRepo::FetchFromPath(std::shared_ptr cfg, auto GitRepo::GetSubtreeFromCommit(std::string const& commit, std::string const& subdir, anon_logger_ptr const& logger) noexcept - -> std::optional { + -> std::variant { #ifdef BOOTSTRAP_BUILD_TOOL - return std::nullopt; + return true; #else try { // preferably with a "fake" repository! @@ -955,7 +955,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, GetGitCAS()->git_path_.string(), GitLastError()), true /*fatal*/); - return std::nullopt; + return true; // fatal failure } git_commit* commit_ptr{nullptr}; @@ -968,7 +968,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, true /*fatal*/); // cleanup resources git_commit_free(commit_ptr); - return std::nullopt; + return false; // non-fatal failure } auto commit_obj = std::unique_ptr( commit_ptr, commit_closer); @@ -985,7 +985,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, true /*fatal*/); // cleanup resources git_tree_free(tree_ptr); - return std::nullopt; + return true; // fatal failure } auto tree = std::unique_ptr( tree_ptr, tree_closer); @@ -1004,7 +1004,7 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, true /*fatal*/); // cleanup resources git_tree_entry_free(subtree_entry_ptr); - return std::nullopt; + return true; // fatal failure } auto subtree_entry = std::unique_ptr( @@ -1012,16 +1012,16 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, std::string subtree_hash{ git_oid_tostr_s(git_tree_entry_id(subtree_entry.get()))}; - return subtree_hash; + return subtree_hash; // success } // if no subdir, get hash from tree std::string tree_hash{git_oid_tostr_s(git_tree_id(tree.get()))}; - return tree_hash; + return tree_hash; // success } catch (std::exception const& ex) { Logger::Log(LogLevel::Error, "get subtree from commit failed with:\n{}", ex.what()); - return std::nullopt; + return true; // fatal failure } #endif // BOOTSTRAP_BUILD_TOOL } @@ -1145,7 +1145,11 @@ auto GitRepo::GetSubtreeFromPath(std::filesystem::path const& fpath, // find relative path from root to given path auto subdir = std::filesystem::relative(fpath, *root).string(); // get subtree from head commit and subdir - return GetSubtreeFromCommit(head_commit, subdir, wrapped_logger); + auto res = GetSubtreeFromCommit(head_commit, subdir, wrapped_logger); + if (std::holds_alternative(res)) { + return std::nullopt; + } + return std::get(res); } catch (std::exception const& ex) { Logger::Log(LogLevel::Error, "get subtree from path failed with:\n{}", -- cgit v1.2.3