mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
Factor out TreeInfo
This commit is contained in:
parent
5d70b454be
commit
8451298b35
13 changed files with 100 additions and 68 deletions
|
@ -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'",
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -72,7 +72,9 @@ struct TarballInput : Input
|
|||
Tree {
|
||||
.actualPath = res.path,
|
||||
.storePath = std::move(storePath),
|
||||
.lastModified = *res.lastModified
|
||||
.info = TreeInfo {
|
||||
.lastModified = *res.lastModified,
|
||||
},
|
||||
},
|
||||
input
|
||||
};
|
||||
|
|
13
src/libstore/fetchers/tree-info.hh
Normal file
13
src/libstore/fetchers/tree-info.hh
Normal file
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue