1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 01:51:47 +02:00

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
This commit is contained in:
regnat 2022-01-19 14:15:45 +01:00
parent 2ad2678c0b
commit dd7c2e0695
4 changed files with 34 additions and 11 deletions

View file

@ -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());