mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +02:00
fetchGit: Don't do a remote fetch if we already have the rev
This commit is contained in:
parent
9ccea31dc2
commit
0e77aa3982
1 changed files with 20 additions and 12 deletions
|
@ -45,8 +45,10 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
|
||||||
PathFilter filter = [&](const Path & p) -> bool {
|
PathFilter filter = [&](const Path & p) -> bool {
|
||||||
assert(hasPrefix(p, uri));
|
assert(hasPrefix(p, uri));
|
||||||
auto st = lstat(p);
|
auto st = lstat(p);
|
||||||
if (S_ISDIR(st.st_mode)) return true;
|
|
||||||
std::string file(p, uri.size() + 1);
|
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);
|
return files.count(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,7 +82,12 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
|
||||||
time_t now = time(0);
|
time_t now = time(0);
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(localRefFile.c_str(), &st) != 0 ||
|
if (stat(localRefFile.c_str(), &st) != 0 ||
|
||||||
st.st_mtime < now - settings.tarballTtl)
|
st.st_mtime <= now - settings.tarballTtl)
|
||||||
|
{
|
||||||
|
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));
|
Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", uri));
|
||||||
|
|
||||||
|
@ -96,6 +103,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
|
||||||
|
|
||||||
utimes(localRefFile.c_str(), times);
|
utimes(localRefFile.c_str(), times);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: check whether rev is an ancestor of ref.
|
// FIXME: check whether rev is an ancestor of ref.
|
||||||
GitInfo gitInfo;
|
GitInfo gitInfo;
|
||||||
|
|
Loading…
Reference in a new issue