Update src/libfetchers/git-utils.cc

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
Eelco Dolstra 2024-06-12 14:41:35 +02:00 committed by GitHub
parent bd37a70d8f
commit efd4bf6533
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -914,11 +914,16 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink
auto pathComponents = tokenizeString<std::vector<std::string>>(path, "/");
if (!prepareDirs(pathComponents, false)) return;
// We can't just look up the path from the start of the root, since
// some parent directories may not have finished yet, so we compute
// a relative path that helps us find the right git_tree_builder or object.
auto relTarget = CanonPath(path).parent()->makeRelative(target);
auto dir = pendingDirs.rbegin();
// For each ../ component at the start, go up one directory.
// CanonPath::makeRelative() always puts all .. elements at the start,
// so they're all handled by this loop:
std::string_view relTargetLeft(relTarget);
while (hasPrefix(relTargetLeft, "../")) {
if (dir == pendingDirs.rend())