From 36a124260361ba8dfa43bf43a067dcc48064c93f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 15 Jul 2020 21:08:46 +0200 Subject: [PATCH] nix why-depends: Fix shortest path calculation This was completely broken since d8972317fc4314864619cadd5620ae780da657a3. --- src/nix/why-depends.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index 167c974ee..49da01c0a 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -106,7 +106,11 @@ struct CmdWhyDepends : SourceExprCommand std::map graph; 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. for (auto & node : graph) @@ -115,8 +119,6 @@ struct CmdWhyDepends : SourceExprCommand /* Run Dijkstra's shortest path algorithm to get the distance of every path in the closure to 'dependency'. */ - graph.emplace(dependencyPath, Node { .path = dependencyPath, .dist = 0 }); - std::priority_queue queue; queue.push(&graph.at(dependencyPath));