aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops/fetchGit.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-28 20:34:02 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-29 10:10:36 +0200
commit0f840483c731f48983832f7f627909f8463f05f3 (patch)
tree1f233b2deb5a50e2d03a5b6f8873e1dd3e588601 /src/libexpr/primops/fetchGit.cc
parent479757dc15c2f2020a81e0a94b58e33a89b0a14b (diff)
Add date of last commit to SourceInfo
This is primarily useful for version string generation, where we need a monotonically increasing number. The revcount is the preferred thing to use, but isn't available for GitHub flakes (since it requires fetching the entire history). The last commit timestamp OTOH can be extracted from GitHub tarballs.
Diffstat (limited to 'src/libexpr/primops/fetchGit.cc')
-rw-r--r--src/libexpr/primops/fetchGit.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc
index f6b096c4a..10f6b6f72 100644
--- a/src/libexpr/primops/fetchGit.cc
+++ b/src/libexpr/primops/fetchGit.cc
@@ -69,6 +69,9 @@ GitInfo exportGit(ref<Store> store, std::string uri,
gitInfo.storePath = store->addToStore("source", uri, true, htSHA256, filter);
gitInfo.revCount = std::stoull(runProgram("git", true, { "-C", uri, "rev-list", "--count", "HEAD" }));
+ // FIXME: maybe we should use the timestamp of the last
+ // modified dirty file?
+ gitInfo.lastModified = std::stoull(runProgram("git", true, { "-C", uri, "show", "-s", "--format=%ct", "HEAD" }));
return gitInfo;
}
@@ -85,8 +88,9 @@ GitInfo exportGit(ref<Store> store, std::string uri,
}
deletePath(getCacheDir() + "/nix/git");
+ deletePath(getCacheDir() + "/nix/gitv2");
- Path cacheDir = getCacheDir() + "/nix/gitv2/" + hashString(htSHA256, uri).to_string(Base32, false);
+ Path cacheDir = getCacheDir() + "/nix/gitv3/" + hashString(htSHA256, uri).to_string(Base32, false);
Path repoDir;
if (isLocal) {
@@ -181,6 +185,7 @@ GitInfo exportGit(ref<Store> store, std::string uri,
if (store->isValidPath(storePath)) {
gitInfo.storePath = storePath;
gitInfo.revCount = json["revCount"];
+ gitInfo.lastModified = json["lastModified"];
return gitInfo;
}
@@ -200,6 +205,7 @@ GitInfo exportGit(ref<Store> store, std::string uri,
gitInfo.storePath = store->addToStore(name, tmpDir);
gitInfo.revCount = std::stoull(runProgram("git", true, { "-C", repoDir, "rev-list", "--count", gitInfo.rev.gitRev() }));
+ gitInfo.lastModified = std::stoull(runProgram("git", true, { "-C", repoDir, "show", "-s", "--format=%ct", gitInfo.rev.gitRev() }));
nlohmann::json json;
json["storePath"] = gitInfo.storePath;
@@ -207,6 +213,7 @@ GitInfo exportGit(ref<Store> store, std::string uri,
json["name"] = name;
json["rev"] = gitInfo.rev.gitRev();
json["revCount"] = gitInfo.revCount;
+ json["lastModified"] = gitInfo.lastModified;
writeFile(storeLink, json.dump());