diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-11-03T12·33+0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-11-03T12·55+0100 |
commit | 0e77aa398240d04e4169208d14ea620b8507b732 (patch) | |
tree | d0b2d5fec349aac57e2cc182e1d14479a53c007c /src/libexpr | |
parent | 9ccea31dc26b38c676824e3f7f5471c0cb901e3b (diff) |
fetchGit: Don't do a remote fetch if we already have the rev
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops/fetchgit.cc | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/libexpr/primops/fetchgit.cc b/src/libexpr/primops/fetchgit.cc index 4b5ead320c81..1d8f55bcd518 100644 --- a/src/libexpr/primops/fetchgit.cc +++ b/src/libexpr/primops/fetchgit.cc @@ -45,8 +45,10 @@ GitInfo exportGit(ref<Store> store, const std::string & uri, PathFilter filter = [&](const Path & p) -> bool { assert(hasPrefix(p, uri)); auto st = lstat(p); - if (S_ISDIR(st.st_mode)) return true; 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; return files.count(file); }; @@ -80,21 +82,27 @@ GitInfo exportGit(ref<Store> store, const std::string & uri, time_t now = time(0); struct stat st; if (stat(localRefFile.c_str(), &st) != 0 || - st.st_mtime < now - settings.tarballTtl) + st.st_mtime <= now - settings.tarballTtl) { - Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", uri)); - - // FIXME: git stderr messes up our progress indicator, so - // we're using --quiet for now. Should process its stderr. - runProgram("git", true, { "-C", cacheDir, "fetch", "--quiet", "--force", "--", uri, *ref + ":" + localRef }); - - struct timeval times[2]; - times[0].tv_sec = now; - times[0].tv_usec = 0; - times[1].tv_sec = now; - times[1].tv_usec = 0; - - utimes(localRefFile.c_str(), times); + if (rev == "" || + chomp(runProgram( + RunOptions("git", { "-C", cacheDir, "cat-file", "-t", rev }) + .killStderr(true)).second) != "commit") + { + Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", uri)); + + // FIXME: git stderr messes up our progress indicator, so + // we're using --quiet for now. Should process its stderr. + runProgram("git", true, { "-C", cacheDir, "fetch", "--quiet", "--force", "--", uri, *ref + ":" + localRef }); + + struct timeval times[2]; + times[0].tv_sec = now; + times[0].tv_usec = 0; + times[1].tv_sec = now; + times[1].tv_usec = 0; + + utimes(localRefFile.c_str(), times); + } } // FIXME: check whether rev is an ancestor of ref. |