aboutsummaryrefslogtreecommitdiff
path: root/src/nix/why-depends.cc
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2022-01-19 14:15:45 +0100
committerregnat <rg@regnat.ovh>2022-01-19 14:24:14 +0100
commitdd7c2e0695b02639d8fe6c7bc050da14373b9513 (patch)
treef0c609f00ef8bcfcc1b16ac22331ffc008df6509 /src/nix/why-depends.cc
parent2ad2678c0baaa755becdbb7be82e2bb2e8ba1ada (diff)
Make `nix why-depends` quieter by default
Unless `--precise` is passed, make `nix why-depends` only show the dependencies between the store paths, without introspecting them to find the actual references. This also makes it ~3x faster
Diffstat (limited to 'src/nix/why-depends.cc')
-rw-r--r--src/nix/why-depends.cc27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc
index dd43bd1c3..74377c912 100644
--- a/src/nix/why-depends.cc
+++ b/src/nix/why-depends.cc
@@ -31,6 +31,7 @@ struct CmdWhyDepends : SourceExprCommand
{
std::string _package, _dependency;
bool all = false;
+ bool precise = false;
CmdWhyDepends()
{
@@ -56,6 +57,12 @@ struct CmdWhyDepends : SourceExprCommand
.description = "Show all edges in the dependency graph leading from *package* to *dependency*, rather than just a shortest path.",
.handler = {&all, true},
});
+
+ addFlag({
+ .longName = "precise",
+ .description = "For each edge of the graph, inspect the parent node to display the exact location in the path that causes the dependency",
+ .handler = {&precise, true},
+ });
}
std::string description() override
@@ -158,11 +165,19 @@ struct CmdWhyDepends : SourceExprCommand
auto pathS = store->printStorePath(node.path);
assert(node.dist != inf);
- logger->cout("%s%s%s%s" ANSI_NORMAL,
- firstPad,
- node.visited ? "\e[38;5;244m" : "",
- firstPad != "" ? "→ " : "",
- pathS);
+ if (precise) {
+ logger->cout("%s%s%s%s" ANSI_NORMAL,
+ firstPad,
+ node.visited ? "\e[38;5;244m" : "",
+ firstPad != "" ? "→ " : "",
+ pathS);
+ } else {
+ logger->cout("%s%s%s%s" ANSI_NORMAL,
+ firstPad,
+ node.visited ? "\e[38;5;244m" : "",
+ firstPad != "" ? treeLast : "",
+ pathS);
+ }
if (node.path == dependencyPath && !all
&& packagePath != dependencyPath)
@@ -237,7 +252,7 @@ struct CmdWhyDepends : SourceExprCommand
// FIXME: should use scanForReferences().
- visitPath(pathS);
+ if (precise) visitPath(pathS);
for (auto & ref : refs) {
std::string hash(ref.second->path.hashPart());