1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-20 11:11:03 -04:00

nix why-depends: Fix shortest path calculation

This was completely broken since d8972317fc.
This commit is contained in:
Eelco Dolstra 2020-07-15 21:08:46 +02:00
parent cff2157185
commit 36a1242603

View file

@ -106,7 +106,11 @@ struct CmdWhyDepends : SourceExprCommand
std::map<StorePath, Node> graph; std::map<StorePath, Node> graph;
for (auto & path : closure) for (auto & path : closure)
graph.emplace(path, Node { .path = path, .refs = store->queryPathInfo(path)->references }); graph.emplace(path, Node {
.path = path,
.refs = store->queryPathInfo(path)->references,
.dist = path == dependencyPath ? 0 : inf
});
// Transpose the graph. // Transpose the graph.
for (auto & node : graph) for (auto & node : graph)
@ -115,8 +119,6 @@ struct CmdWhyDepends : SourceExprCommand
/* Run Dijkstra's shortest path algorithm to get the distance /* Run Dijkstra's shortest path algorithm to get the distance
of every path in the closure to 'dependency'. */ of every path in the closure to 'dependency'. */
graph.emplace(dependencyPath, Node { .path = dependencyPath, .dist = 0 });
std::priority_queue<Node *> queue; std::priority_queue<Node *> queue;
queue.push(&graph.at(dependencyPath)); queue.push(&graph.at(dependencyPath));