1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

Merge pull request #14079 from obsidiansystems/clean-up-why-depends

Clean up `nix why-depends` store accessor usage, and put back store dir in output
This commit is contained in:
Jörg Thalheim 2025-09-25 08:49:12 +02:00 committed by GitHub
commit eb04a6d3e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -108,8 +108,6 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
auto dependencyPath = *optDependencyPath; auto dependencyPath = *optDependencyPath;
auto dependencyPathHash = dependencyPath.hashPart(); auto dependencyPathHash = dependencyPath.hashPart();
auto accessor = store->getFSAccessor();
auto const inf = std::numeric_limits<size_t>::max(); auto const inf = std::numeric_limits<size_t>::max();
struct Node struct Node
@ -172,8 +170,6 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
{}; {};
printNode = [&](Node & node, const std::string & firstPad, const std::string & tailPad) { printNode = [&](Node & node, const std::string & firstPad, const std::string & tailPad) {
CanonPath pathS(node.path.to_string());
assert(node.dist != inf); assert(node.dist != inf);
if (precise) { if (precise) {
logger->cout( logger->cout(
@ -181,7 +177,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
firstPad, firstPad,
node.visited ? "\e[38;5;244m" : "", node.visited ? "\e[38;5;244m" : "",
firstPad != "" ? "" : "", firstPad != "" ? "" : "",
pathS.abs()); store->printStorePath(node.path));
} }
if (node.path == dependencyPath && !all && packagePath != dependencyPath) if (node.path == dependencyPath && !all && packagePath != dependencyPath)
@ -211,13 +207,13 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
contain the reference. */ contain the reference. */
std::map<std::string, Strings> hits; std::map<std::string, Strings> hits;
std::function<void(const CanonPath &)> visitPath; auto accessor = store->getFSAccessor(node.path);
visitPath = [&](const CanonPath & p) { auto visitPath = [&](this auto && recur, const CanonPath & p) -> void {
auto st = accessor->maybeLstat(p); auto st = accessor->maybeLstat(p);
assert(st); assert(st);
auto p2 = p == pathS ? "/" : p.abs().substr(pathS.abs().size() + 1); auto p2 = p.isRoot() ? p.abs() : p.rel();
auto getColour = [&](const std::string & hash) { auto getColour = [&](const std::string & hash) {
return hash == dependencyPathHash ? ANSI_GREEN : ANSI_BLUE; return hash == dependencyPathHash ? ANSI_GREEN : ANSI_BLUE;
@ -226,7 +222,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
if (st->type == SourceAccessor::Type::tDirectory) { if (st->type == SourceAccessor::Type::tDirectory) {
auto names = accessor->readDirectory(p); auto names = accessor->readDirectory(p);
for (auto & [name, type] : names) for (auto & [name, type] : names)
visitPath(p / name); recur(p / name);
} }
else if (st->type == SourceAccessor::Type::tRegular) { else if (st->type == SourceAccessor::Type::tRegular) {
@ -264,7 +260,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
// FIXME: should use scanForReferences(). // FIXME: should use scanForReferences().
if (precise) if (precise)
visitPath(pathS); visitPath(CanonPath::root);
for (auto & ref : refs) { for (auto & ref : refs) {
std::string hash(ref.second->path.hashPart()); std::string hash(ref.second->path.hashPart());
@ -280,13 +276,12 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
} }
if (!precise) { if (!precise) {
auto pathS = store->printStorePath(ref.second->path);
logger->cout( logger->cout(
"%s%s%s%s" ANSI_NORMAL, "%s%s%s%s" ANSI_NORMAL,
firstPad, firstPad,
ref.second->visited ? "\e[38;5;244m" : "", ref.second->visited ? "\e[38;5;244m" : "",
last ? treeLast : treeConn, last ? treeLast : treeConn,
pathS); store->printStorePath(ref.second->path));
node.visited = true; node.visited = true;
} }