builtins.fetchgit: Respect tarball-ttl

I.e. if the local ref is more recent than tarball-ttl seconds, then
don't check the remote.
This commit is contained in:
Eelco Dolstra 2017-07-27 17:15:09 +02:00
parent 69deca194e
commit 9f64cb89cb
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -4,6 +4,8 @@
#include "store-api.hh" #include "store-api.hh"
#include "pathlocks.hh" #include "pathlocks.hh"
#include <sys/time.h>
namespace nix { namespace nix {
Path exportGit(ref<Store> store, const std::string & uri, const std::string & rev) Path exportGit(ref<Store> store, const std::string & uri, const std::string & rev)
@ -24,8 +26,24 @@ Path exportGit(ref<Store> store, const std::string & uri, const std::string & re
Path localRefFile = cacheDir + "/refs/heads/" + localRef; Path localRefFile = cacheDir + "/refs/heads/" + localRef;
/* If the local ref is older than tarball-ttl seconds, do a git
fetch to update the local ref to the remote ref. */
time_t now = time(0);
struct stat st;
if (stat(localRefFile.c_str(), &st) != 0 ||
st.st_mtime < now - settings.tarballTtl)
{
runProgram("git", true, { "-C", cacheDir, "fetch", "--force", uri, rev + ":" + localRef }); runProgram("git", true, { "-C", cacheDir, "fetch", "--force", uri, rev + ":" + 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);
}
std::string commitHash = chomp(readFile(localRefFile)); std::string commitHash = chomp(readFile(localRefFile));
printTalkative("using revision %s of repo %s", uri, commitHash); printTalkative("using revision %s of repo %s", uri, commitHash);