about summary refs log tree commit diff
path: root/src/libexpr/primops
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-11-03T12·48+0100
committerEelco Dolstra <edolstra@gmail.com>2017-11-03T12·55+0100
commitee6ac38848277d80c62fa5c2734ada1b5edc8680 (patch)
treeb334ed6f568806c94f7cfb135327060a04ab9db7 /src/libexpr/primops
parent4dee01da7c7bc5d67dc916f159bfee8a873ac19b (diff)
fetchGit/fetchMercurial: Filter out directories with untracked files
Diffstat (limited to 'src/libexpr/primops')
-rw-r--r--src/libexpr/primops/fetchMercurial.cc12
-rw-r--r--src/libexpr/primops/fetchgit.cc12
2 files changed, 16 insertions, 8 deletions
diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc
index 2a423f61bb89..7def7103bf3d 100644
--- a/src/libexpr/primops/fetchMercurial.cc
+++ b/src/libexpr/primops/fetchMercurial.cc
@@ -47,11 +47,15 @@ HgInfo exportMercurial(ref<Store> store, const std::string & uri,
 
             PathFilter filter = [&](const Path & p) -> bool {
                 assert(hasPrefix(p, uri));
-                auto st = lstat(p);
                 std::string file(p, uri.size() + 1);
-                if (file == ".hg") return false;
-                // FIXME: filter out directories with no tracked files.
-                if (S_ISDIR(st.st_mode)) return true;
+
+                auto st = lstat(p);
+
+                if (S_ISDIR(st.st_mode)) {
+                    auto i = files.lower_bound(file);
+                    return i != files.end() && hasPrefix(*i, file);
+                }
+
                 return files.count(file);
             };
 
diff --git a/src/libexpr/primops/fetchgit.cc b/src/libexpr/primops/fetchgit.cc
index 1d8f55bcd518..baa48f6422b7 100644
--- a/src/libexpr/primops/fetchgit.cc
+++ b/src/libexpr/primops/fetchgit.cc
@@ -44,11 +44,15 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
 
             PathFilter filter = [&](const Path & p) -> bool {
                 assert(hasPrefix(p, uri));
-                auto st = lstat(p);
                 std::string file(p, uri.size() + 1);
-                if (file == ".git") return false;
-                // FIXME: filter out directories with no tracked files.
-                if (S_ISDIR(st.st_mode)) return true;
+
+                auto st = lstat(p);
+
+                if (S_ISDIR(st.st_mode)) {
+                    auto i = files.lower_bound(file);
+                    return i != files.end() && hasPrefix(*i, file);
+                }
+
                 return files.count(file);
             };