From 1c58ad2ffa698d17b7be56eab69a40ace64d0e21 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 14 Sep 2017 11:17:32 +0200 Subject: [PATCH] nix why-depends: Fix showing self-references --- src/nix/why-depends.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index a6750ac95..f31469cbc 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -1,6 +1,4 @@ #include "command.hh" -#include "common-args.hh" -#include "shared.hh" #include "store-api.hh" #include "progress-bar.hh" #include "fs-accessor.hh" @@ -59,9 +57,17 @@ struct CmdWhyDepends : SourceExprCommand { return { Example{ - "To show which files in Hello's closure depend on Glibc:", + "To show one path through the dependency graph leading from Hello to Glibc:", "nix why-depends nixpkgs.hello nixpkgs.glibc" }, + Example{ + "To show all files and paths in the dependency graph leading from Thunderbird to libX11:", + "nix why-depends --all nixpkgs.thunderbird nixpkgs.xorg.libX11" + }, + Example{ + "To show why Glibc depends on itself:", + "nix why-depends nixpkgs.glibc nixpkgs.glibc" + }, }; } @@ -141,9 +147,9 @@ struct CmdWhyDepends : SourceExprCommand and `dependency`. */ std::function printNode; - const string treeConn = "├───"; - const string treeLast = "└───"; - const string treeLine = "│ "; + const string treeConn = "╠═══"; + const string treeLast = "╚═══"; + const string treeLine = "║ "; const string treeNull = " "; struct BailOut { }; @@ -156,7 +162,9 @@ struct CmdWhyDepends : SourceExprCommand firstPad != "" ? "=> " : "", node.path); - if (node.path == dependencyPath && !all) throw BailOut(); + if (node.path == dependencyPath && !all + && packagePath != dependencyPath) + throw BailOut(); if (node.visited) return; node.visited = true; @@ -167,7 +175,7 @@ struct CmdWhyDepends : SourceExprCommand std::set hashes; for (auto & ref : node.refs) { - if (ref == node.path) continue; + if (ref == node.path && packagePath != dependencyPath) continue; auto & node2 = graph.at(ref); if (node2.dist == inf) continue; refs.emplace(node2.dist, &node2);