mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
fetchGit: don't use std::filesystem to filter git repos
Using std::filesystem means also having to link with -lstdc++fs on some platforms and it's hard to discover for what platforms this is needed. As all the functionality is already implemented as utilities, use those instead.
This commit is contained in:
parent
f686efeed4
commit
40c023ecfe
2 changed files with 10 additions and 11 deletions
|
@ -8,11 +8,7 @@ libexpr_SOURCES := $(wildcard $(d)/*.cc) $(wildcard $(d)/primops/*.cc) $(d)/lexe
|
|||
|
||||
libexpr_LIBS = libutil libstore libnixrust
|
||||
|
||||
ifeq ($(CXX), g++)
|
||||
libexpr_LDFLAGS = -lstdc++fs
|
||||
else
|
||||
libexpr_LDFLAGS =
|
||||
endif
|
||||
|
||||
ifneq ($(OS), FreeBSD)
|
||||
libexpr_LDFLAGS += -ldl
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "hash.hh"
|
||||
#include "tarfile.hh"
|
||||
|
||||
#include <filesystem>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <regex>
|
||||
|
@ -28,6 +27,13 @@ struct GitInfo
|
|||
|
||||
std::regex revRegex("^[0-9a-fA-F]{40}$");
|
||||
|
||||
static bool isNotDotGitDirectory(const Path & path)
|
||||
{
|
||||
static const std::regex gitDirRegex("^(?:.*/)?\\.git$");
|
||||
|
||||
return not std::regex_match(path, gitDirRegex);
|
||||
}
|
||||
|
||||
GitInfo exportGit(ref<Store> store, const std::string & uri,
|
||||
std::optional<std::string> ref, std::string rev,
|
||||
const std::string & name, bool fetchSubmodules)
|
||||
|
@ -175,6 +181,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
|
|||
|
||||
Path tmpDir = createTempDir();
|
||||
AutoDelete delTmpDir(tmpDir, true);
|
||||
PathFilter filter = defaultPathFilter;
|
||||
|
||||
// Submodule support can be improved by adding caching to the submodules themselves. At the moment, only the root
|
||||
// repo is cached.
|
||||
|
@ -193,11 +200,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
|
|||
runProgram("git", true, { "-C", tmpDir, "remote", "add", "origin", uri });
|
||||
runProgram("git", true, { "-C", tmpDir, "submodule", "--quiet", "update", "--init", "--recursive" });
|
||||
|
||||
for (const auto& p : std::filesystem::recursive_directory_iterator(tmpDir)) {
|
||||
if (p.path().filename() == ".git") {
|
||||
std::filesystem::remove_all(p.path());
|
||||
}
|
||||
}
|
||||
filter = isNotDotGitDirectory;
|
||||
} else {
|
||||
auto source = sinkToSource([&](Sink & sink) {
|
||||
RunOptions gitOptions("git", { "-C", cacheDir, "archive", gitInfo.rev });
|
||||
|
@ -208,7 +211,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
|
|||
unpackTarfile(*source, tmpDir);
|
||||
}
|
||||
|
||||
gitInfo.storePath = store->printStorePath(store->addToStore(name, tmpDir));
|
||||
gitInfo.storePath = store->printStorePath(store->addToStore(name, tmpDir, true, htSHA256, filter));
|
||||
|
||||
gitInfo.revCount = std::stoull(runProgram("git", true, { "-C", cacheDir, "rev-list", "--count", gitInfo.rev }));
|
||||
|
||||
|
|
Loading…
Reference in a new issue