builtins.fetchgit: Cache hash -> store path mappings

This prevents an expensive call to addToStore() in the cached case.
This commit is contained in:
Eelco Dolstra 2017-07-27 16:16:08 +02:00
parent 57b9505731
commit 6d7de7f3de
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -2,6 +2,7 @@
#include "eval-inline.hh"
#include "download.hh"
#include "store-api.hh"
#include "pathlocks.hh"
namespace nix {
@ -28,7 +29,18 @@ Path exportGit(ref<Store> store, const std::string & uri, const std::string & re
unlink(localRefFile.c_str());
debug(format("got revision %s") % commitHash);
printTalkative("using revision %s of repo %s", uri, commitHash);
Path storeLink = cacheDir + "/" + commitHash + ".link";
PathLocks storeLinkLock({storeLink}, fmt("waiting for lock on %1%...", storeLink));
if (pathExists(storeLink)) {
auto storePath = readLink(storeLink);
store->addTempRoot(storePath);
if (store->isValidPath(storePath)) {
return storePath;
}
}
// FIXME: should pipe this, or find some better way to extract a
// revision.
@ -39,7 +51,11 @@ Path exportGit(ref<Store> store, const std::string & uri, const std::string & re
runProgram("tar", true, { "x", "-C", tmpDir }, tar);
return store->addToStore("git-export", tmpDir);
auto storePath = store->addToStore("git-export", tmpDir);
replaceSymlink(storePath, storeLink);
return storePath;
}
static void prim_fetchgit(EvalState & state, const Pos & pos, Value * * args, Value & v)