aboutsummaryrefslogtreecommitdiff
path: root/src/nix/why-depends.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-17 03:51:02 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-17 03:51:02 +0000
commit02928f76fdf8ab991da404d4216e97d54af19976 (patch)
treed3b05632fbad02a2019d69eee8db445fc95557a0 /src/nix/why-depends.cc
parente3173242362c8421429633c0e9f64ab0211760bd (diff)
parent29542865cee37ab22efe1bd142900b69f6c59f0d (diff)
Merge remote-tracking branch 'upstream/master' into multi-output-hashDerivationModulo
Diffstat (limited to 'src/nix/why-depends.cc')
-rw-r--r--src/nix/why-depends.cc38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc
index c24ae7c8e..167c974ee 100644
--- a/src/nix/why-depends.cc
+++ b/src/nix/why-depends.cc
@@ -37,11 +37,12 @@ struct CmdWhyDepends : SourceExprCommand
expectArg("package", &_package);
expectArg("dependency", &_dependency);
- mkFlag()
- .longName("all")
- .shortName('a')
- .description("show all edges in the dependency graph leading from 'package' to 'dependency', rather than just a shortest path")
- .set(&all, true);
+ addFlag({
+ .longName = "all",
+ .shortName = 'a',
+ .description = "show all edges in the dependency graph leading from 'package' to 'dependency', rather than just a shortest path",
+ .handler = {&all, true},
+ });
}
std::string description() override
@@ -67,13 +68,15 @@ struct CmdWhyDepends : SourceExprCommand
};
}
+ Category category() override { return catSecondary; }
+
void run(ref<Store> store) override
{
auto package = parseInstallable(*this, store, _package, false);
auto packagePath = toStorePath(store, Build, package);
auto dependency = parseInstallable(*this, store, _dependency, false);
auto dependencyPath = toStorePath(store, NoBuild, dependency);
- auto dependencyPathHash = storePathToHash(store->printStorePath(dependencyPath));
+ auto dependencyPathHash = dependencyPath.hashPart();
StorePathSet closure;
store->computeFSClosure({packagePath}, closure, false, false);
@@ -103,16 +106,16 @@ struct CmdWhyDepends : SourceExprCommand
std::map<StorePath, Node> graph;
for (auto & path : closure)
- graph.emplace(path.clone(), Node { .path = path.clone(), .refs = cloneStorePathSet(store->queryPathInfo(path)->references) });
+ graph.emplace(path, Node { .path = path, .refs = store->queryPathInfo(path)->references });
// Transpose the graph.
for (auto & node : graph)
for (auto & ref : node.second.refs)
- graph.find(ref)->second.rrefs.insert(node.first.clone());
+ graph.find(ref)->second.rrefs.insert(node.first);
/* Run Dijkstra's shortest path algorithm to get the distance
of every path in the closure to 'dependency'. */
- graph.emplace(dependencyPath.clone(), Node { .path = dependencyPath.clone(), .dist = 0 });
+ graph.emplace(dependencyPath, Node { .path = dependencyPath, .dist = 0 });
std::priority_queue<Node *> queue;
@@ -143,21 +146,16 @@ struct CmdWhyDepends : SourceExprCommand
and `dependency`. */
std::function<void(Node &, const string &, const string &)> printNode;
- const string treeConn = "╠═══";
- const string treeLast = "╚═══";
- const string treeLine = "║ ";
- const string treeNull = " ";
-
struct BailOut { };
printNode = [&](Node & node, const string & firstPad, const string & tailPad) {
auto pathS = store->printStorePath(node.path);
assert(node.dist != inf);
- std::cout << fmt("%s%s%s%s" ANSI_NORMAL "\n",
+ logger->stdout("%s%s%s%s" ANSI_NORMAL,
firstPad,
node.visited ? "\e[38;5;244m" : "",
- firstPad != "" ? "=> " : "",
+ firstPad != "" ? "→ " : "",
pathS);
if (node.path == dependencyPath && !all
@@ -177,7 +175,7 @@ struct CmdWhyDepends : SourceExprCommand
auto & node2 = graph.at(ref);
if (node2.dist == inf) continue;
refs.emplace(node2.dist, &node2);
- hashes.insert(storePathToHash(store->printStorePath(node2.path)));
+ hashes.insert(std::string(node2.path.hashPart()));
}
/* For each reference, find the files and symlinks that
@@ -213,7 +211,7 @@ struct CmdWhyDepends : SourceExprCommand
p2,
hilite(filterPrintable(
std::string(contents, pos2, pos - pos2 + hash.size() + margin)),
- pos - pos2, storePathHashLen,
+ pos - pos2, StorePath::HashLen,
getColour(hash))));
}
}
@@ -226,7 +224,7 @@ struct CmdWhyDepends : SourceExprCommand
auto pos = target.find(hash);
if (pos != std::string::npos)
hits[hash].emplace_back(fmt("%s -> %s\n", p2,
- hilite(target, pos, storePathHashLen, getColour(hash))));
+ hilite(target, pos, StorePath::HashLen, getColour(hash))));
}
}
};
@@ -237,7 +235,7 @@ struct CmdWhyDepends : SourceExprCommand
RunPager pager;
for (auto & ref : refs) {
- auto hash = storePathToHash(store->printStorePath(ref.second->path));
+ std::string hash(ref.second->path.hashPart());
bool last = all ? ref == *refs.rbegin() : true;