summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_repo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildtool/file_system/git_repo.cpp')
-rw-r--r--src/buildtool/file_system/git_repo.cpp24
1 files changed, 14 insertions, 10 deletions
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<git_config> cfg,
auto GitRepo::GetSubtreeFromCommit(std::string const& commit,
std::string const& subdir,
anon_logger_ptr const& logger) noexcept
- -> std::optional<std::string> {
+ -> std::variant<bool, std::string> {
#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<git_commit, decltype(&commit_closer)>(
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<git_tree, decltype(&tree_closer)>(
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<git_tree_entry, decltype(&tree_entry_closer)>(
@@ -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<bool>(res)) {
+ return std::nullopt;
+ }
+ return std::get<std::string>(res);
} catch (std::exception const& ex) {
Logger::Log(LogLevel::Error,
"get subtree from path failed with:\n{}",