summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_cas.cpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-06-02 13:32:29 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-07-13 16:41:37 +0200
commitce5c7d7fd12570868bcdd1145e7184daf31ac147 (patch)
tree935f98b8a9d7dc0626754b1b756c5c3552af524f /src/buildtool/file_system/git_cas.cpp
parent799a6dfcd9e39deee905a77267a3e635d97bedd8 (diff)
downloadjustbuild-ce5c7d7fd12570868bcdd1145e7184daf31ac147.tar.gz
git cas: only compute absolute path if not absolute already
... and in this way, continue to work correctly in the absence of a current working directory. (cherry picked from 06bb4f11a21aae5713d75b496145f6621302ae3a)
Diffstat (limited to 'src/buildtool/file_system/git_cas.cpp')
-rw-r--r--src/buildtool/file_system/git_cas.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/buildtool/file_system/git_cas.cpp b/src/buildtool/file_system/git_cas.cpp
index f134a894..7bddf6b3 100644
--- a/src/buildtool/file_system/git_cas.cpp
+++ b/src/buildtool/file_system/git_cas.cpp
@@ -21,6 +21,7 @@
#include "gsl/gsl"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/hex_string.hpp"
+#include "src/utils/cpp/path.hpp"
#ifndef BOOTSTRAP_BUILD_TOOL
@@ -155,9 +156,21 @@ auto GitCAS::OpenODB(std::filesystem::path const& repo_path) noexcept -> bool {
git_odb* odb_ptr{nullptr};
git_repository_odb(&odb_ptr, repo);
odb_.reset(odb_ptr); // retain odb pointer
- // set root
- git_path_ = std::filesystem::weakly_canonical(std::filesystem::absolute(
- std::filesystem::path(git_repository_path(repo))));
+ // set root
+ std::filesystem::path git_path =
+ ToNormalPath(git_repository_path(repo));
+ if (not git_path.is_absolute()) {
+ try {
+ git_path = std::filesystem::absolute(git_path);
+ } catch (std::exception const& e) {
+ Logger::Log(LogLevel::Error,
+ "Failed to obtain absolute path for {}: {}",
+ git_path.string(),
+ e.what());
+ return false;
+ }
+ }
+ git_path_ = git_path;
// release resources
git_repository_free(repo);
}