aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-03 12:46:16 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-03 12:46:16 +0200
commitf662850b60793a069bfddc565ebc336d7f4a39e6 (patch)
tree37d63911ac7ed59ac6afa16f0bb5536bf6a46a7d
parent4588a6ff3caed5ad30c83e2bc65e52a58176e71c (diff)
parent9b3069a88ceff3646d254fa403f41be889e6423d (diff)
Merge remote-tracking branch 'tweag/fuzzyMatching' into flakes
-rw-r--r--src/libexpr/primops/flake.cc42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index 88a0293e3..cc93eee36 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -161,7 +161,23 @@ const Registries EvalState::getFlakeRegistries()
}
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())
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);
if (i != registry->entries.end()) {
auto newRef = i->second;
- if (std::get_if<FlakeRef::IsAlias>(&flakeRef.data)) {
- if (flakeRef.ref || flakeRef.rev) {
- newRef.ref = flakeRef.ref;
- newRef.rev = flakeRef.rev;
- }
- }
- 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);
+ return updateFlakeRef(state, newRef, registries, pastSearches);
+ }
+
+ auto j = registry->entries.find(flakeRef.baseRef());
+ if (j != registry->entries.end()) {
+ auto newRef = j->second;
+ newRef.ref = flakeRef.ref;
+ newRef.rev = flakeRef.rev;
+ return updateFlakeRef(state, newRef, registries, pastSearches);
}
}