aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/flake
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-03-27 16:15:50 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-03-27 16:15:50 +0100
commit3fa1e7daced316a5a396dc0cb74dc2f7a89b5f60 (patch)
treede7c3ab461b2ba4982cbb540a551a8df4e0bcbba /src/libexpr/flake
parent7abe3bde8ade2941ca8a3dbb2b73b8cc9de2b1a1 (diff)
Fix diffLockFiles()
Diffstat (limited to 'src/libexpr/flake')
-rw-r--r--src/libexpr/flake/lockfile.cc17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc
index b7a9e20c1..ee04ec64f 100644
--- a/src/libexpr/flake/lockfile.cc
+++ b/src/libexpr/flake/lockfile.cc
@@ -96,8 +96,6 @@ StorePath LockedNode::computeStorePath(Store & store) const
std::shared_ptr<Node> Node::findInput(const InputPath & path)
{
- assert(!path.empty());
-
auto pos = shared_from_this();
for (auto & elem : path) {
@@ -275,32 +273,33 @@ InputPath parseInputPath(std::string_view s)
path.push_back(elem);
}
- if (path.empty())
- throw Error("flake input path is empty");
-
return path;
}
static void flattenLockFile(
std::shared_ptr<const Node> node,
const InputPath & prefix,
+ std::unordered_set<std::shared_ptr<const Node>> & done,
std::map<InputPath, std::shared_ptr<const LockedNode>> & res)
{
- // FIXME: handle cycles
+ if (!done.insert(node).second) return;
+
for (auto &[id, input] : node->inputs) {
auto inputPath(prefix);
inputPath.push_back(id);
if (auto lockedInput = std::dynamic_pointer_cast<const LockedNode>(input))
res.emplace(inputPath, lockedInput);
- flattenLockFile(input, inputPath, res);
+ flattenLockFile(input, inputPath, done, res);
}
}
std::string diffLockFiles(const LockFile & oldLocks, const LockFile & newLocks)
{
+ std::unordered_set<std::shared_ptr<const Node>> done;
std::map<InputPath, std::shared_ptr<const LockedNode>> oldFlat, newFlat;
- flattenLockFile(oldLocks.root, {}, oldFlat);
- flattenLockFile(newLocks.root, {}, newFlat);
+ flattenLockFile(oldLocks.root, {}, done, oldFlat);
+ done.clear();
+ flattenLockFile(newLocks.root, {}, done, newFlat);
auto i = oldFlat.begin();
auto j = newFlat.begin();