mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 14:36:16 +02:00
Remove superfluous TreeInfo::rev field
This commit is contained in:
parent
b9d64f9318
commit
887730aab3
9 changed files with 36 additions and 38 deletions
|
@ -567,17 +567,21 @@ LockedFlake lockFlake(
|
||||||
return LockedFlake { .flake = std::move(flake), .lockFile = std::move(newLockFile) };
|
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));
|
assert(state.store->isValidPath(sourceInfo.storePath));
|
||||||
auto pathS = state.store->printStorePath(sourceInfo.storePath);
|
auto pathS = state.store->printStorePath(sourceInfo.storePath);
|
||||||
mkString(*state.allocAttr(vAttrs, state.sOutPath), pathS, {pathS});
|
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")),
|
mkString(*state.allocAttr(vAttrs, state.symbols.create("rev")),
|
||||||
sourceInfo.info.rev->gitRev());
|
rev->gitRev());
|
||||||
mkString(*state.allocAttr(vAttrs, state.symbols.create("shortRev")),
|
mkString(*state.allocAttr(vAttrs, state.symbols.create("shortRev")),
|
||||||
sourceInfo.info.rev->gitShortRev());
|
rev->gitShortRev());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceInfo.info.revCount)
|
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});
|
mkString(*state.allocAttr(v, state.sOutPath), pathS, {pathS});
|
||||||
|
|
||||||
emitSourceInfoAttrs(state, sourceInfo, v);
|
emitSourceInfoAttrs(state, resolvedRef, sourceInfo, v);
|
||||||
|
|
||||||
v.attrs->sort();
|
v.attrs->sort();
|
||||||
}
|
}
|
||||||
|
@ -672,7 +676,7 @@ void callFlake(EvalState & state,
|
||||||
|
|
||||||
auto & vSourceInfo = *state.allocValue();
|
auto & vSourceInfo = *state.allocValue();
|
||||||
state.mkAttrs(vSourceInfo, 8);
|
state.mkAttrs(vSourceInfo, 8);
|
||||||
emitSourceInfoAttrs(state, *flake.sourceInfo, vSourceInfo);
|
emitSourceInfoAttrs(state, flake.resolvedRef, *flake.sourceInfo, vSourceInfo);
|
||||||
vSourceInfo.attrs->sort();
|
vSourceInfo.attrs->sort();
|
||||||
|
|
||||||
vInputs.attrs->push_back(Attr(state.sSelf, &vRes));
|
vInputs.attrs->push_back(Attr(state.sSelf, &vRes));
|
||||||
|
|
|
@ -58,10 +58,6 @@ static TreeInfo parseTreeInfo(const nlohmann::json & json)
|
||||||
else
|
else
|
||||||
throw Error("attribute 'narHash' missing in lock file");
|
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");
|
j = i2.find("revCount");
|
||||||
if (j != i2.end())
|
if (j != i2.end())
|
||||||
info.revCount = *j;
|
info.revCount = *j;
|
||||||
|
@ -97,8 +93,6 @@ static nlohmann::json treeInfoToJson(const TreeInfo & info)
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
assert(info.narHash);
|
assert(info.narHash);
|
||||||
json["narHash"] = info.narHash.to_string(SRI);
|
json["narHash"] = info.narHash.to_string(SRI);
|
||||||
if (info.rev)
|
|
||||||
json["rev"] = info.rev->gitRev();
|
|
||||||
if (info.revCount)
|
if (info.revCount)
|
||||||
json["revCount"] = *info.revCount;
|
json["revCount"] = *info.revCount;
|
||||||
if (info.lastModified)
|
if (info.lastModified)
|
||||||
|
|
|
@ -57,14 +57,14 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va
|
||||||
// FIXME: use name
|
// FIXME: use name
|
||||||
auto input = inputFromURL(parsedUrl);
|
auto input = inputFromURL(parsedUrl);
|
||||||
|
|
||||||
auto tree = input->fetchTree(state.store).first;
|
auto [tree, input2] = input->fetchTree(state.store);
|
||||||
|
|
||||||
state.mkAttrs(v, 8);
|
state.mkAttrs(v, 8);
|
||||||
auto storePath = state.store->printStorePath(tree.storePath);
|
auto storePath = state.store->printStorePath(tree.storePath);
|
||||||
mkString(*state.allocAttr(v, state.sOutPath), storePath, PathSet({storePath}));
|
mkString(*state.allocAttr(v, state.sOutPath), storePath, PathSet({storePath}));
|
||||||
// Backward compatibility: set 'rev' to
|
// Backward compatibility: set 'rev' to
|
||||||
// 0000000000000000000000000000000000000000 for a dirty tree.
|
// 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("rev")), rev2.gitRev());
|
||||||
mkString(*state.allocAttr(v, state.symbols.create("shortRev")), rev2.gitShortRev());
|
mkString(*state.allocAttr(v, state.symbols.create("shortRev")), rev2.gitShortRev());
|
||||||
assert(tree.info.revCount);
|
assert(tree.info.revCount);
|
||||||
|
|
|
@ -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());
|
mkString(*state.allocAttr(v, state.symbols.create("branch")), *input2->getRef());
|
||||||
// Backward compatibility: set 'rev' to
|
// Backward compatibility: set 'rev' to
|
||||||
// 0000000000000000000000000000000000000000 for a dirty tree.
|
// 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("rev")), rev2.gitRev());
|
||||||
mkString(*state.allocAttr(v, state.symbols.create("shortRev")), std::string(rev2.gitRev(), 0, 12));
|
mkString(*state.allocAttr(v, state.symbols.create("shortRev")), std::string(rev2.gitRev(), 0, 12));
|
||||||
if (tree.info.revCount)
|
if (tree.info.revCount)
|
||||||
|
|
|
@ -23,21 +23,25 @@ static Path getCacheInfoPathFor(const std::string & name, const Hash & rev)
|
||||||
return cacheDir + "/" + linkName + ".link";
|
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;
|
nlohmann::json json;
|
||||||
json["storePath"] = store.printStorePath(tree.storePath);
|
json["storePath"] = store.printStorePath(tree.storePath);
|
||||||
json["name"] = name;
|
json["name"] = name;
|
||||||
json["rev"] = tree.info.rev->gitRev();
|
json["rev"] = rev.gitRev();
|
||||||
json["revCount"] = *tree.info.revCount;
|
json["revCount"] = *tree.info.revCount;
|
||||||
json["lastModified"] = *tree.info.lastModified;
|
json["lastModified"] = *tree.info.lastModified;
|
||||||
|
|
||||||
auto cacheInfoPath = getCacheInfoPathFor(name, *tree.info.rev);
|
auto cacheInfoPath = getCacheInfoPathFor(name, rev);
|
||||||
createDirs(dirOf(cacheInfoPath));
|
createDirs(dirOf(cacheInfoPath));
|
||||||
writeFile(cacheInfoPath, json.dump());
|
writeFile(cacheInfoPath, json.dump());
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::optional<Tree> lookupGitInfo(
|
static std::optional<std::pair<Hash, Tree>> lookupGitInfo(
|
||||||
ref<Store> store,
|
ref<Store> store,
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
const Hash & rev)
|
const Hash & rev)
|
||||||
|
@ -50,16 +54,14 @@ static std::optional<Tree> lookupGitInfo(
|
||||||
auto storePath = store->parseStorePath((std::string) json["storePath"]);
|
auto storePath = store->parseStorePath((std::string) json["storePath"]);
|
||||||
|
|
||||||
if (store->isValidPath(storePath)) {
|
if (store->isValidPath(storePath)) {
|
||||||
Tree tree{
|
return {{rev, Tree{
|
||||||
.actualPath = store->toRealPath(store->printStorePath(storePath)),
|
.actualPath = store->toRealPath(store->printStorePath(storePath)),
|
||||||
.storePath = std::move(storePath),
|
.storePath = std::move(storePath),
|
||||||
.info = TreeInfo {
|
.info = TreeInfo {
|
||||||
.rev = rev,
|
|
||||||
.revCount = json["revCount"],
|
.revCount = json["revCount"],
|
||||||
.lastModified = json["lastModified"],
|
.lastModified = json["lastModified"],
|
||||||
}
|
}
|
||||||
};
|
}}};
|
||||||
return tree;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SysError & e) {
|
} catch (SysError & e) {
|
||||||
|
@ -181,8 +183,10 @@ struct GitInput : Input
|
||||||
assert(!rev || rev->type == htSHA1);
|
assert(!rev || rev->type == htSHA1);
|
||||||
|
|
||||||
if (rev) {
|
if (rev) {
|
||||||
if (auto tree = lookupGitInfo(store, name, *rev))
|
if (auto tree = lookupGitInfo(store, name, *rev)) {
|
||||||
return {std::move(*tree), input};
|
input->rev = tree->first;
|
||||||
|
return {std::move(tree->second), input};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto [isLocal, actualUrl_] = getActualUrl();
|
auto [isLocal, actualUrl_] = getActualUrl();
|
||||||
|
@ -326,8 +330,10 @@ struct GitInput : Input
|
||||||
input->rev = Hash(chomp(readFile(localRefFile)), htSHA1);
|
input->rev = Hash(chomp(readFile(localRefFile)), htSHA1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto tree = lookupGitInfo(store, name, *input->rev))
|
if (auto tree = lookupGitInfo(store, name, *input->rev)) {
|
||||||
return {std::move(*tree), input};
|
assert(*input->rev == tree->first);
|
||||||
|
return {std::move(tree->second), input};
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: check whether rev is an ancestor of ref.
|
// FIXME: check whether rev is an ancestor of ref.
|
||||||
|
|
||||||
|
@ -354,13 +360,12 @@ struct GitInput : Input
|
||||||
.actualPath = store->toRealPath(store->printStorePath(storePath)),
|
.actualPath = store->toRealPath(store->printStorePath(storePath)),
|
||||||
.storePath = std::move(storePath),
|
.storePath = std::move(storePath),
|
||||||
.info = TreeInfo {
|
.info = TreeInfo {
|
||||||
.rev = input->rev,
|
|
||||||
.revCount = revCount,
|
.revCount = revCount,
|
||||||
.lastModified = lastModified
|
.lastModified = lastModified
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
cacheGitInfo(*store, name, tree);
|
cacheGitInfo(*store, name, tree, *input->rev);
|
||||||
|
|
||||||
return {std::move(tree), input};
|
return {std::move(tree), input};
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,6 @@ struct GitHubInput : Input
|
||||||
.actualPath = dresult.path,
|
.actualPath = dresult.path,
|
||||||
.storePath = store->parseStorePath(dresult.storePath),
|
.storePath = store->parseStorePath(dresult.storePath),
|
||||||
.info = TreeInfo {
|
.info = TreeInfo {
|
||||||
.rev = *rev,
|
|
||||||
.lastModified = *dresult.lastModified,
|
.lastModified = *dresult.lastModified,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -220,7 +220,6 @@ struct MercurialInput : Input
|
||||||
.actualPath = store->printStorePath(storePath),
|
.actualPath = store->printStorePath(storePath),
|
||||||
.storePath = std::move(storePath),
|
.storePath = std::move(storePath),
|
||||||
.info = TreeInfo {
|
.info = TreeInfo {
|
||||||
.rev = input->rev,
|
|
||||||
.revCount = revCount,
|
.revCount = revCount,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -256,7 +255,6 @@ struct MercurialInput : Input
|
||||||
.actualPath = store->printStorePath(storePath),
|
.actualPath = store->printStorePath(storePath),
|
||||||
.storePath = std::move(storePath),
|
.storePath = std::move(storePath),
|
||||||
.info = TreeInfo {
|
.info = TreeInfo {
|
||||||
.rev = input->rev,
|
|
||||||
.revCount = revCount
|
.revCount = revCount
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,7 +5,6 @@ namespace nix {
|
||||||
struct TreeInfo
|
struct TreeInfo
|
||||||
{
|
{
|
||||||
Hash narHash;
|
Hash narHash;
|
||||||
std::optional<Hash> rev; // FIXME: remove
|
|
||||||
std::optional<uint64_t> revCount;
|
std::optional<uint64_t> revCount;
|
||||||
std::optional<time_t> lastModified;
|
std::optional<time_t> lastModified;
|
||||||
|
|
||||||
|
@ -13,7 +12,6 @@ struct TreeInfo
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
narHash == other.narHash
|
narHash == other.narHash
|
||||||
&& rev == other.rev
|
|
||||||
&& revCount == other.revCount
|
&& revCount == other.revCount
|
||||||
&& lastModified == other.lastModified;
|
&& lastModified == other.lastModified;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,8 @@ static void printFlakeInfo(const Store & store, const Flake & flake)
|
||||||
if (flake.description)
|
if (flake.description)
|
||||||
std::cout << fmt("Description: %s\n", *flake.description);
|
std::cout << fmt("Description: %s\n", *flake.description);
|
||||||
std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath));
|
std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath));
|
||||||
if (flake.sourceInfo->info.rev)
|
if (auto rev = flake.resolvedRef.input->getRev())
|
||||||
std::cout << fmt("Revision: %s\n", flake.sourceInfo->info.rev->to_string(Base16, false));
|
std::cout << fmt("Revision: %s\n", rev->to_string(Base16, false));
|
||||||
if (flake.sourceInfo->info.revCount)
|
if (flake.sourceInfo->info.revCount)
|
||||||
std::cout << fmt("Revisions: %s\n", *flake.sourceInfo->info.revCount);
|
std::cout << fmt("Revisions: %s\n", *flake.sourceInfo->info.revCount);
|
||||||
if (flake.sourceInfo->info.lastModified)
|
if (flake.sourceInfo->info.lastModified)
|
||||||
|
@ -100,8 +100,8 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
|
||||||
j["description"] = *flake.description;
|
j["description"] = *flake.description;
|
||||||
j["edition"] = flake.edition;
|
j["edition"] = flake.edition;
|
||||||
j["url"] = flake.resolvedRef.input->to_string();
|
j["url"] = flake.resolvedRef.input->to_string();
|
||||||
if (flake.sourceInfo->info.rev)
|
if (auto rev = flake.resolvedRef.input->getRev())
|
||||||
j["revision"] = flake.sourceInfo->info.rev->to_string(Base16, false);
|
j["revision"] = rev->to_string(Base16, false);
|
||||||
if (flake.sourceInfo->info.revCount)
|
if (flake.sourceInfo->info.revCount)
|
||||||
j["revCount"] = *flake.sourceInfo->info.revCount;
|
j["revCount"] = *flake.sourceInfo->info.revCount;
|
||||||
if (flake.sourceInfo->info.lastModified)
|
if (flake.sourceInfo->info.lastModified)
|
||||||
|
|
Loading…
Reference in a new issue