Merge remote-tracking branch 'tweag/fuzzyMatching' into flakes

This commit is contained in:
Eelco Dolstra 2019-05-03 12:46:16 +02:00
commit f662850b60

View file

@ -161,7 +161,23 @@ const Registries EvalState::getFlakeRegistries()
} }
static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const Registries & registries, static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const Registries & registries,
std::vector<FlakeRef> pastSearches = {}) std::vector<FlakeRef> pastSearches = {});
FlakeRef updateFlakeRef(EvalState & state, const FlakeRef & newRef, const Registries & registries, std::vector<FlakeRef> pastSearches)
{
std::string errorMsg = "found cycle in flake registries: ";
for (FlakeRef oldRef : pastSearches) {
errorMsg += oldRef.to_string();
if (oldRef == newRef)
throw Error(errorMsg);
errorMsg += " - ";
}
pastSearches.push_back(newRef);
return lookupFlake(state, newRef, registries, pastSearches);
}
static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const Registries & registries,
std::vector<FlakeRef> pastSearches)
{ {
if (registries.empty() && !flakeRef.isDirect()) if (registries.empty() && !flakeRef.isDirect())
throw Error("indirect flake reference '%s' is not allowed", flakeRef); throw Error("indirect flake reference '%s' is not allowed", flakeRef);
@ -170,21 +186,15 @@ static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const
auto i = registry->entries.find(flakeRef); auto i = registry->entries.find(flakeRef);
if (i != registry->entries.end()) { if (i != registry->entries.end()) {
auto newRef = i->second; auto newRef = i->second;
if (std::get_if<FlakeRef::IsAlias>(&flakeRef.data)) { return updateFlakeRef(state, newRef, registries, pastSearches);
if (flakeRef.ref || flakeRef.rev) { }
newRef.ref = flakeRef.ref;
newRef.rev = flakeRef.rev; auto j = registry->entries.find(flakeRef.baseRef());
} if (j != registry->entries.end()) {
} auto newRef = j->second;
std::string errorMsg = "found cycle in flake registries: "; newRef.ref = flakeRef.ref;
for (FlakeRef oldRef : pastSearches) { newRef.rev = flakeRef.rev;
errorMsg += oldRef.to_string(); return updateFlakeRef(state, newRef, registries, pastSearches);
if (oldRef == newRef)
throw Error(errorMsg);
errorMsg += " - ";
}
pastSearches.push_back(newRef);
return lookupFlake(state, newRef, registries, pastSearches);
} }
} }