aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulian Stecklina <js@alien8.de>2020-03-29 23:47:48 +0200
committerJulian Stecklina <js@alien8.de>2020-03-30 00:32:42 +0200
commit40c023ecfe49fea6e66db34c5f841fcf7001cbeb (patch)
tree21403b66801810b49b977636b1021bbe5cb3b44d /src
parentf686efeed4d6305101c56136855e2d6b87e649e4 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/local.mk4
-rw-r--r--src/libexpr/primops/fetchGit.cc17
2 files changed, 10 insertions, 11 deletions
diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk
index b6ee82424..9b5fcc561 100644
--- a/src/libexpr/local.mk
+++ b/src/libexpr/local.mk
@@ -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
diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc
index f138b755c..d60e6b803 100644
--- a/src/libexpr/primops/fetchGit.cc
+++ b/src/libexpr/primops/fetchGit.cc
@@ -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 }));