Skip to content

Commit

Permalink
fetchGit: don't use std::filesystem to filter git repos
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
blitz committed Mar 29, 2020
1 parent f686efe commit 40c023e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/libexpr/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/libexpr/primops/fetchGit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "hash.hh"
#include "tarfile.hh"

#include <filesystem>
#include <sys/time.h>

#include <regex>
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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 });
Expand All @@ -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 }));

Expand Down

0 comments on commit 40c023e

Please sign in to comment.