diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-02-01 16:41:54 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-02-01 22:06:55 +0100 |
commit | 8451298b35353abafe385124cb55e8d4911032ad (patch) | |
tree | 361e15b63cfbd6ce418053b3939d9d5ef6ae6692 /src/libstore | |
parent | 5d70b454be7da683bf9f265d95cd0066140ea956 (diff) |
Factor out TreeInfo
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/fetchers/fetchers.cc | 6 | ||||
-rw-r--r-- | src/libstore/fetchers/fetchers.hh | 6 | ||||
-rw-r--r-- | src/libstore/fetchers/git.cc | 34 | ||||
-rw-r--r-- | src/libstore/fetchers/github.cc | 6 | ||||
-rw-r--r-- | src/libstore/fetchers/mercurial.cc | 34 | ||||
-rw-r--r-- | src/libstore/fetchers/tarball.cc | 4 | ||||
-rw-r--r-- | src/libstore/fetchers/tree-info.hh | 13 |
7 files changed, 67 insertions, 36 deletions
diff --git a/src/libstore/fetchers/fetchers.cc b/src/libstore/fetchers/fetchers.cc index 16f674401..256ef66f2 100644 --- a/src/libstore/fetchers/fetchers.cc +++ b/src/libstore/fetchers/fetchers.cc @@ -83,11 +83,11 @@ std::pair<Tree, std::shared_ptr<const Input>> Input::fetchTree(ref<Store> store) if (tree.actualPath == "") tree.actualPath = store->toRealPath(store->printStorePath(tree.storePath)); - if (!tree.narHash) - tree.narHash = store->queryPathInfo(tree.storePath)->narHash; + if (!tree.info.narHash) + tree.info.narHash = store->queryPathInfo(tree.storePath)->narHash; if (input->narHash) - assert(input->narHash == tree.narHash); + assert(input->narHash == tree.info.narHash); if (narHash && narHash != input->narHash) throw Error("NAR hash mismatch in input '%s', expected '%s', got '%s'", diff --git a/src/libstore/fetchers/fetchers.hh b/src/libstore/fetchers/fetchers.hh index 39e004240..7a7ce7d37 100644 --- a/src/libstore/fetchers/fetchers.hh +++ b/src/libstore/fetchers/fetchers.hh @@ -3,6 +3,7 @@ #include "types.hh" #include "hash.hh" #include "path.hh" +#include "tree-info.hh" #include <memory> #include <variant> @@ -19,10 +20,7 @@ struct Tree { Path actualPath; StorePath storePath; - Hash narHash; - std::optional<Hash> rev; - std::optional<uint64_t> revCount; - std::optional<time_t> lastModified; + TreeInfo info; }; struct Input : std::enable_shared_from_this<Input> diff --git a/src/libstore/fetchers/git.cc b/src/libstore/fetchers/git.cc index 5d0448777..4ad0f6f34 100644 --- a/src/libstore/fetchers/git.cc +++ b/src/libstore/fetchers/git.cc @@ -28,11 +28,11 @@ static void cacheGitInfo(Store & store, const std::string & name, const Tree & t nlohmann::json json; json["storePath"] = store.printStorePath(tree.storePath); json["name"] = name; - json["rev"] = tree.rev->gitRev(); - json["revCount"] = *tree.revCount; - json["lastModified"] = *tree.lastModified; + json["rev"] = tree.info.rev->gitRev(); + json["revCount"] = *tree.info.revCount; + json["lastModified"] = *tree.info.lastModified; - auto cacheInfoPath = getCacheInfoPathFor(name, *tree.rev); + auto cacheInfoPath = getCacheInfoPathFor(name, *tree.info.rev); createDirs(dirOf(cacheInfoPath)); writeFile(cacheInfoPath, json.dump()); } @@ -53,9 +53,11 @@ static std::optional<Tree> lookupGitInfo( Tree tree{ .actualPath = store->toRealPath(store->printStorePath(storePath)), .storePath = std::move(storePath), - .rev = rev, - .revCount = json["revCount"], - .lastModified = json["lastModified"], + .info = TreeInfo { + .rev = rev, + .revCount = json["revCount"], + .lastModified = json["lastModified"], + } }; return tree; } @@ -237,10 +239,12 @@ struct GitInput : Input auto tree = Tree { .actualPath = store->printStorePath(storePath), .storePath = std::move(storePath), - .revCount = haveCommits ? std::stoull(runProgram("git", true, { "-C", actualUrl, "rev-list", "--count", "HEAD" })) : 0, - // FIXME: maybe we should use the timestamp of the last - // modified dirty file? - .lastModified = haveCommits ? std::stoull(runProgram("git", true, { "-C", actualUrl, "log", "-1", "--format=%ct", "HEAD" })) : 0, + .info = TreeInfo { + .revCount = haveCommits ? std::stoull(runProgram("git", true, { "-C", actualUrl, "rev-list", "--count", "HEAD" })) : 0, + // FIXME: maybe we should use the timestamp of the last + // modified dirty file? + .lastModified = haveCommits ? std::stoull(runProgram("git", true, { "-C", actualUrl, "log", "-1", "--format=%ct", "HEAD" })) : 0, + } }; return {std::move(tree), input}; @@ -349,9 +353,11 @@ struct GitInput : Input auto tree = Tree { .actualPath = store->toRealPath(store->printStorePath(storePath)), .storePath = std::move(storePath), - .rev = input->rev, - .revCount = revCount, - .lastModified = lastModified, + .info = TreeInfo { + .rev = input->rev, + .revCount = revCount, + .lastModified = lastModified + } }; cacheGitInfo(*store, name, tree); diff --git a/src/libstore/fetchers/github.cc b/src/libstore/fetchers/github.cc index c8746b723..a4d39d17d 100644 --- a/src/libstore/fetchers/github.cc +++ b/src/libstore/fetchers/github.cc @@ -113,8 +113,10 @@ struct GitHubInput : Input Tree result{ .actualPath = dresult.path, .storePath = store->parseStorePath(dresult.storePath), - .rev = *rev, - .lastModified = *dresult.lastModified + .info = TreeInfo { + .rev = *rev, + .lastModified = *dresult.lastModified, + }, }; #if 0 diff --git a/src/libstore/fetchers/mercurial.cc b/src/libstore/fetchers/mercurial.cc index 1bdab1dbf..b415b7944 100644 --- a/src/libstore/fetchers/mercurial.cc +++ b/src/libstore/fetchers/mercurial.cc @@ -215,12 +215,17 @@ struct MercurialInput : Input if (store->isValidPath(storePath)) { printTalkative("using cached Mercurial store path '%s'", store->printStorePath(storePath)); - return {Tree { - .actualPath = store->printStorePath(storePath), - .storePath = std::move(storePath), - .rev = input->rev, - .revCount = revCount, - }, input}; + return { + Tree { + .actualPath = store->printStorePath(storePath), + .storePath = std::move(storePath), + .info = TreeInfo { + .rev = input->rev, + .revCount = revCount, + }, + }, + input + }; } } catch (SysError & e) { @@ -246,12 +251,17 @@ struct MercurialInput : Input writeFile(storeLink, json.dump()); - return {Tree { - .actualPath = store->printStorePath(storePath), - .storePath = std::move(storePath), - .rev = input->rev, - .revCount = revCount, - }, input}; + return { + Tree { + .actualPath = store->printStorePath(storePath), + .storePath = std::move(storePath), + .info = TreeInfo { + .rev = input->rev, + .revCount = revCount + } + }, + input + }; } }; diff --git a/src/libstore/fetchers/tarball.cc b/src/libstore/fetchers/tarball.cc index 1302299b3..fc4d7542b 100644 --- a/src/libstore/fetchers/tarball.cc +++ b/src/libstore/fetchers/tarball.cc @@ -72,7 +72,9 @@ struct TarballInput : Input Tree { .actualPath = res.path, .storePath = std::move(storePath), - .lastModified = *res.lastModified + .info = TreeInfo { + .lastModified = *res.lastModified, + }, }, input }; diff --git a/src/libstore/fetchers/tree-info.hh b/src/libstore/fetchers/tree-info.hh new file mode 100644 index 000000000..30d4f3d6b --- /dev/null +++ b/src/libstore/fetchers/tree-info.hh @@ -0,0 +1,13 @@ +#pragma once + +namespace nix { + +struct TreeInfo +{ + Hash narHash; + std::optional<Hash> rev; + std::optional<uint64_t> revCount; + std::optional<time_t> lastModified; +}; + +} |