Remove superfluous TreeInfo::rev field

This commit is contained in:
Eelco Dolstra 2020-02-01 23:54:20 +01:00
parent b9d64f9318
commit 887730aab3
No known key found for this signature in database
GPG Key ID: 8170B4726D7198DE
9 changed files with 36 additions and 38 deletions

View File

@ -567,17 +567,21 @@ LockedFlake lockFlake(
return LockedFlake { .flake = std::move(flake), .lockFile = std::move(newLockFile) };
}
static void emitSourceInfoAttrs(EvalState & state, const fetchers::Tree & sourceInfo, Value & vAttrs)
static void emitSourceInfoAttrs(
EvalState & state,
const FlakeRef & flakeRef,
const fetchers::Tree & sourceInfo,
Value & vAttrs)
{
assert(state.store->isValidPath(sourceInfo.storePath));
auto pathS = state.store->printStorePath(sourceInfo.storePath);
mkString(*state.allocAttr(vAttrs, state.sOutPath), pathS, {pathS});
if (sourceInfo.info.rev) {
if (auto rev = flakeRef.input->getRev()) {
mkString(*state.allocAttr(vAttrs, state.symbols.create("rev")),
sourceInfo.info.rev->gitRev());
rev->gitRev());
mkString(*state.allocAttr(vAttrs, state.symbols.create("shortRev")),
sourceInfo.info.rev->gitShortRev());
rev->gitShortRev());
}
if (sourceInfo.info.revCount)
@ -639,7 +643,7 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V
mkString(*state.allocAttr(v, state.sOutPath), pathS, {pathS});
emitSourceInfoAttrs(state, sourceInfo, v);
emitSourceInfoAttrs(state, resolvedRef, sourceInfo, v);
v.attrs->sort();
}
@ -672,7 +676,7 @@ void callFlake(EvalState & state,
auto & vSourceInfo = *state.allocValue();
state.mkAttrs(vSourceInfo, 8);
emitSourceInfoAttrs(state, *flake.sourceInfo, vSourceInfo);
emitSourceInfoAttrs(state, flake.resolvedRef, *flake.sourceInfo, vSourceInfo);
vSourceInfo.attrs->sort();
vInputs.attrs->push_back(Attr(state.sSelf, &vRes));

View File

@ -58,10 +58,6 @@ static TreeInfo parseTreeInfo(const nlohmann::json & json)
else
throw Error("attribute 'narHash' missing in lock file");
j = i2.find("rev");
if (j != i2.end())
info.rev = Hash((std::string) *j, htSHA1);
j = i2.find("revCount");
if (j != i2.end())
info.revCount = *j;
@ -97,8 +93,6 @@ static nlohmann::json treeInfoToJson(const TreeInfo & info)
nlohmann::json json;
assert(info.narHash);
json["narHash"] = info.narHash.to_string(SRI);
if (info.rev)
json["rev"] = info.rev->gitRev();
if (info.revCount)
json["revCount"] = *info.revCount;
if (info.lastModified)

View File

@ -57,14 +57,14 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va
// FIXME: use name
auto input = inputFromURL(parsedUrl);
auto tree = input->fetchTree(state.store).first;
auto [tree, input2] = input->fetchTree(state.store);
state.mkAttrs(v, 8);
auto storePath = state.store->printStorePath(tree.storePath);
mkString(*state.allocAttr(v, state.sOutPath), storePath, PathSet({storePath}));
// Backward compatibility: set 'rev' to
// 0000000000000000000000000000000000000000 for a dirty tree.
auto rev2 = tree.info.rev.value_or(Hash(htSHA1));
auto rev2 = input2->getRev().value_or(Hash(htSHA1));
mkString(*state.allocAttr(v, state.symbols.create("rev")), rev2.gitRev());
mkString(*state.allocAttr(v, state.symbols.create("shortRev")), rev2.gitShortRev());
assert(tree.info.revCount);

View File

@ -73,7 +73,7 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar
mkString(*state.allocAttr(v, state.symbols.create("branch")), *input2->getRef());
// Backward compatibility: set 'rev' to
// 0000000000000000000000000000000000000000 for a dirty tree.
auto rev2 = tree.info.rev.value_or(Hash(htSHA1));
auto rev2 = input2->getRev().value_or(Hash(htSHA1));
mkString(*state.allocAttr(v, state.symbols.create("rev")), rev2.gitRev());
mkString(*state.allocAttr(v, state.symbols.create("shortRev")), std::string(rev2.gitRev(), 0, 12));
if (tree.info.revCount)

View File

@ -23,21 +23,25 @@ static Path getCacheInfoPathFor(const std::string & name, const Hash & rev)
return cacheDir + "/" + linkName + ".link";
}
static void cacheGitInfo(Store & store, const std::string & name, const Tree & tree)
static void cacheGitInfo(
Store & store,
const std::string & name,
const Tree & tree,
const Hash & rev)
{
nlohmann::json json;
json["storePath"] = store.printStorePath(tree.storePath);
json["name"] = name;
json["rev"] = tree.info.rev->gitRev();
json["rev"] = rev.gitRev();
json["revCount"] = *tree.info.revCount;
json["lastModified"] = *tree.info.lastModified;
auto cacheInfoPath = getCacheInfoPathFor(name, *tree.info.rev);
auto cacheInfoPath = getCacheInfoPathFor(name, rev);
createDirs(dirOf(cacheInfoPath));
writeFile(cacheInfoPath, json.dump());
}
static std::optional<Tree> lookupGitInfo(
static std::optional<std::pair<Hash, Tree>> lookupGitInfo(
ref<Store> store,
const std::string & name,
const Hash & rev)
@ -50,16 +54,14 @@ static std::optional<Tree> lookupGitInfo(
auto storePath = store->parseStorePath((std::string) json["storePath"]);
if (store->isValidPath(storePath)) {
Tree tree{
return {{rev, Tree{
.actualPath = store->toRealPath(store->printStorePath(storePath)),
.storePath = std::move(storePath),
.info = TreeInfo {
.rev = rev,
.revCount = json["revCount"],
.lastModified = json["lastModified"],
}
};
return tree;
}}};
}
} catch (SysError & e) {
@ -181,8 +183,10 @@ struct GitInput : Input
assert(!rev || rev->type == htSHA1);
if (rev) {
if (auto tree = lookupGitInfo(store, name, *rev))
return {std::move(*tree), input};
if (auto tree = lookupGitInfo(store, name, *rev)) {
input->rev = tree->first;
return {std::move(tree->second), input};
}
}
auto [isLocal, actualUrl_] = getActualUrl();
@ -326,8 +330,10 @@ struct GitInput : Input
input->rev = Hash(chomp(readFile(localRefFile)), htSHA1);
}
if (auto tree = lookupGitInfo(store, name, *input->rev))
return {std::move(*tree), input};
if (auto tree = lookupGitInfo(store, name, *input->rev)) {
assert(*input->rev == tree->first);
return {std::move(tree->second), input};
}
// FIXME: check whether rev is an ancestor of ref.
@ -354,13 +360,12 @@ struct GitInput : Input
.actualPath = store->toRealPath(store->printStorePath(storePath)),
.storePath = std::move(storePath),
.info = TreeInfo {
.rev = input->rev,
.revCount = revCount,
.lastModified = lastModified
}
};
cacheGitInfo(*store, name, tree);
cacheGitInfo(*store, name, tree, *input->rev);
return {std::move(tree), input};
}

View File

@ -114,7 +114,6 @@ struct GitHubInput : Input
.actualPath = dresult.path,
.storePath = store->parseStorePath(dresult.storePath),
.info = TreeInfo {
.rev = *rev,
.lastModified = *dresult.lastModified,
},
};

View File

@ -220,7 +220,6 @@ struct MercurialInput : Input
.actualPath = store->printStorePath(storePath),
.storePath = std::move(storePath),
.info = TreeInfo {
.rev = input->rev,
.revCount = revCount,
},
},
@ -256,7 +255,6 @@ struct MercurialInput : Input
.actualPath = store->printStorePath(storePath),
.storePath = std::move(storePath),
.info = TreeInfo {
.rev = input->rev,
.revCount = revCount
}
},

View File

@ -5,7 +5,6 @@ namespace nix {
struct TreeInfo
{
Hash narHash;
std::optional<Hash> rev; // FIXME: remove
std::optional<uint64_t> revCount;
std::optional<time_t> lastModified;
@ -13,7 +12,6 @@ struct TreeInfo
{
return
narHash == other.narHash
&& rev == other.rev
&& revCount == other.revCount
&& lastModified == other.lastModified;
}

View File

@ -84,8 +84,8 @@ static void printFlakeInfo(const Store & store, const Flake & flake)
if (flake.description)
std::cout << fmt("Description: %s\n", *flake.description);
std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath));
if (flake.sourceInfo->info.rev)
std::cout << fmt("Revision: %s\n", flake.sourceInfo->info.rev->to_string(Base16, false));
if (auto rev = flake.resolvedRef.input->getRev())
std::cout << fmt("Revision: %s\n", rev->to_string(Base16, false));
if (flake.sourceInfo->info.revCount)
std::cout << fmt("Revisions: %s\n", *flake.sourceInfo->info.revCount);
if (flake.sourceInfo->info.lastModified)
@ -100,8 +100,8 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
j["description"] = *flake.description;
j["edition"] = flake.edition;
j["url"] = flake.resolvedRef.input->to_string();
if (flake.sourceInfo->info.rev)
j["revision"] = flake.sourceInfo->info.rev->to_string(Base16, false);
if (auto rev = flake.resolvedRef.input->getRev())
j["revision"] = rev->to_string(Base16, false);
if (flake.sourceInfo->info.revCount)
j["revCount"] = *flake.sourceInfo->info.revCount;
if (flake.sourceInfo->info.lastModified)