Remove redundant resolvedRef fields since they're already in SourceInfo

This commit is contained in:
Eelco Dolstra 2019-05-28 13:12:43 +02:00
parent 4846304541
commit dda4f7167b
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
4 changed files with 36 additions and 34 deletions

View file

@ -397,13 +397,17 @@ LockFile entryToLockFile(const LockFile::FlakeEntry & entry)
LockFile::FlakeEntry dependenciesToFlakeEntry(const ResolvedFlake & resolvedFlake)
{
LockFile::FlakeEntry entry(resolvedFlake.flake.resolvedRef, resolvedFlake.flake.sourceInfo.narHash);
LockFile::FlakeEntry entry(
resolvedFlake.flake.sourceInfo.resolvedRef,
resolvedFlake.flake.sourceInfo.narHash);
for (auto & info : resolvedFlake.flakeDeps)
entry.flakeEntries.insert_or_assign(info.first.to_string(), dependenciesToFlakeEntry(info.second));
for (auto & nonFlake : resolvedFlake.nonFlakeDeps) {
LockFile::NonFlakeEntry nonEntry(nonFlake.resolvedRef, nonFlake.sourceInfo.narHash);
LockFile::NonFlakeEntry nonEntry(
nonFlake.sourceInfo.resolvedRef,
nonFlake.sourceInfo.narHash);
entry.nonFlakeEntries.insert_or_assign(nonFlake.alias, nonEntry);
}
@ -540,11 +544,11 @@ void callFlake(EvalState & state, const ResolvedFlake & resFlake, Value & v)
state.store->isValidPath(path);
mkString(*state.allocAttr(v, state.sOutPath), path, {path});
if (resFlake.flake.resolvedRef.rev) {
if (resFlake.flake.sourceInfo.resolvedRef.rev) {
mkString(*state.allocAttr(v, state.symbols.create("rev")),
resFlake.flake.resolvedRef.rev->gitRev());
resFlake.flake.sourceInfo.resolvedRef.rev->gitRev());
mkString(*state.allocAttr(v, state.symbols.create("shortRev")),
resFlake.flake.resolvedRef.rev->gitShortRev());
resFlake.flake.sourceInfo.resolvedRef.rev->gitShortRev());
}
if (resFlake.flake.sourceInfo.revCount)

View file

@ -92,7 +92,6 @@ struct Flake
{
FlakeId id;
FlakeRef originalRef;
FlakeRef resolvedRef;
std::string description;
SourceInfo sourceInfo;
std::vector<FlakeRef> requires;
@ -100,18 +99,17 @@ struct Flake
Value * vProvides; // FIXME: gc
unsigned int epoch;
Flake(const FlakeRef & origRef, const SourceInfo & sourceInfo) : originalRef(origRef),
resolvedRef(sourceInfo.resolvedRef), sourceInfo(sourceInfo) {};
Flake(const FlakeRef & origRef, const SourceInfo & sourceInfo)
: originalRef(origRef), sourceInfo(sourceInfo) {};
};
struct NonFlake
{
FlakeAlias alias;
FlakeRef originalRef;
FlakeRef resolvedRef;
SourceInfo sourceInfo;
NonFlake(const FlakeRef & origRef, const SourceInfo & sourceInfo) :
originalRef(origRef), resolvedRef(sourceInfo.resolvedRef), sourceInfo(sourceInfo) {};
NonFlake(const FlakeRef & origRef, const SourceInfo & sourceInfo)
: originalRef(origRef), sourceInfo(sourceInfo) {};
};
Flake getFlake(EvalState &, const FlakeRef &, bool impureIsAllowed);

View file

@ -74,12 +74,12 @@ void printFlakeInfo(const Flake & flake, bool json) {
if (json) {
nlohmann::json j;
j["id"] = flake.id;
j["uri"] = flake.resolvedRef.to_string();
j["uri"] = flake.sourceInfo.resolvedRef.to_string();
j["description"] = flake.description;
if (flake.resolvedRef.ref)
j["branch"] = *flake.resolvedRef.ref;
if (flake.resolvedRef.rev)
j["revision"] = flake.resolvedRef.rev->to_string(Base16, false);
if (flake.sourceInfo.resolvedRef.ref)
j["branch"] = *flake.sourceInfo.resolvedRef.ref;
if (flake.sourceInfo.resolvedRef.rev)
j["revision"] = flake.sourceInfo.resolvedRef.rev->to_string(Base16, false);
if (flake.sourceInfo.revCount)
j["revCount"] = *flake.sourceInfo.revCount;
j["path"] = flake.sourceInfo.storePath;
@ -87,12 +87,12 @@ void printFlakeInfo(const Flake & flake, bool json) {
std::cout << j.dump(4) << std::endl;
} else {
std::cout << "ID: " << flake.id << "\n";
std::cout << "URI: " << flake.resolvedRef.to_string() << "\n";
std::cout << "URI: " << flake.sourceInfo.resolvedRef.to_string() << "\n";
std::cout << "Description: " << flake.description << "\n";
if (flake.resolvedRef.ref)
std::cout << "Branch: " << *flake.resolvedRef.ref << "\n";
if (flake.resolvedRef.rev)
std::cout << "Revision: " << flake.resolvedRef.rev->to_string(Base16, false) << "\n";
if (flake.sourceInfo.resolvedRef.ref)
std::cout << "Branch: " << *flake.sourceInfo.resolvedRef.ref << "\n";
if (flake.sourceInfo.resolvedRef.rev)
std::cout << "Revision: " << flake.sourceInfo.resolvedRef.rev->to_string(Base16, false) << "\n";
if (flake.sourceInfo.revCount)
std::cout << "Revcount: " << *flake.sourceInfo.revCount << "\n";
std::cout << "Path: " << flake.sourceInfo.storePath << "\n";
@ -104,22 +104,22 @@ void printNonFlakeInfo(const NonFlake & nonFlake, bool json) {
if (json) {
nlohmann::json j;
j["id"] = nonFlake.alias;
j["uri"] = nonFlake.resolvedRef.to_string();
if (nonFlake.resolvedRef.ref)
j["branch"] = *nonFlake.resolvedRef.ref;
if (nonFlake.resolvedRef.rev)
j["revision"] = nonFlake.resolvedRef.rev->to_string(Base16, false);
j["uri"] = nonFlake.sourceInfo.resolvedRef.to_string();
if (nonFlake.sourceInfo.resolvedRef.ref)
j["branch"] = *nonFlake.sourceInfo.resolvedRef.ref;
if (nonFlake.sourceInfo.resolvedRef.rev)
j["revision"] = nonFlake.sourceInfo.resolvedRef.rev->to_string(Base16, false);
if (nonFlake.sourceInfo.revCount)
j["revCount"] = *nonFlake.sourceInfo.revCount;
j["path"] = nonFlake.sourceInfo.storePath;
std::cout << j.dump(4) << std::endl;
} else {
std::cout << "ID: " << nonFlake.alias << "\n";
std::cout << "URI: " << nonFlake.resolvedRef.to_string() << "\n";
if (nonFlake.resolvedRef.ref)
std::cout << "Branch: " << *nonFlake.resolvedRef.ref;
if (nonFlake.resolvedRef.rev)
std::cout << "Revision: " << nonFlake.resolvedRef.rev->to_string(Base16, false) << "\n";
std::cout << "URI: " << nonFlake.sourceInfo.resolvedRef.to_string() << "\n";
if (nonFlake.sourceInfo.resolvedRef.ref)
std::cout << "Branch: " << *nonFlake.sourceInfo.resolvedRef.ref;
if (nonFlake.sourceInfo.resolvedRef.rev)
std::cout << "Revision: " << nonFlake.sourceInfo.resolvedRef.rev->to_string(Base16, false) << "\n";
if (nonFlake.sourceInfo.revCount)
std::cout << "Revcount: " << *nonFlake.sourceInfo.revCount << "\n";
std::cout << "Path: " << nonFlake.sourceInfo.storePath << "\n";
@ -295,13 +295,13 @@ struct CmdFlakePin : virtual Args, EvalCommand
FlakeRegistry userRegistry = *readRegistry(userRegistryPath);
auto it = userRegistry.entries.find(FlakeRef(alias));
if (it != userRegistry.entries.end()) {
it->second = getFlake(*evalState, it->second, true).resolvedRef;
it->second = getFlake(*evalState, it->second, true).sourceInfo.resolvedRef;
writeRegistry(userRegistry, userRegistryPath);
} else {
std::shared_ptr<FlakeRegistry> globalReg = evalState->getGlobalFlakeRegistry();
it = globalReg->entries.find(FlakeRef(alias));
if (it != globalReg->entries.end()) {
FlakeRef newRef = getFlake(*evalState, it->second, true).resolvedRef;
auto newRef = getFlake(*evalState, it->second, true).sourceInfo.resolvedRef;
userRegistry.entries.insert_or_assign(alias, newRef);
writeRegistry(userRegistry, userRegistryPath);
} else

View file

@ -176,7 +176,7 @@ void makeFlakeClosureGCRoot(Store & store, const FlakeRef & origFlakeRef, const
while (!queue.empty()) {
const ResolvedFlake & flake = queue.front();
queue.pop();
if (!std::get_if<FlakeRef::IsPath>(&flake.flake.resolvedRef.data))
if (!std::get_if<FlakeRef::IsPath>(&flake.flake.sourceInfo.resolvedRef.data))
closure.insert(flake.flake.sourceInfo.storePath);
for (const auto & dep : flake.flakeDeps)
queue.push(dep.second);