aboutsummaryrefslogtreecommitdiff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-03-24 14:17:10 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-03-24 14:26:23 +0100
commit7a8de57d3e7e53a4f6d8060c7201f3fbbe6cd325 (patch)
treee418ac74ab2a2dd45e4ea4c8ecb7017d8b76e9b8 /src/nix-store/nix-store.cc
parent4260a22a55d7afc931b22e8c41282fbd0ed18a77 (diff)
Pretty-print 'nix why-depends' / 'nix-store -q --tree' output
Extracted from 678301072f05b650dc15c5edb4c25f08f0d6cace.
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r--src/nix-store/nix-store.cc15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index c14d900ae..806ab7563 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -229,12 +229,6 @@ static StorePathSet maybeUseOutputs(const StorePath & storePath, bool useOutput,
/* Some code to print a tree representation of a derivation dependency
graph. Topological sorting is used to keep the tree relatively
flat. */
-
-const string treeConn = "+---";
-const string treeLine = "| ";
-const string treeNull = " ";
-
-
static void printTree(const StorePath & path,
const string & firstPad, const string & tailPad, StorePathSet & done)
{
@@ -254,10 +248,11 @@ static void printTree(const StorePath & path,
auto sorted = store->topoSortPaths(info->references);
reverse(sorted.begin(), sorted.end());
- for (auto i = sorted.begin(); i != sorted.end(); ++i) {
- auto j = i; ++j;
- printTree(*i, tailPad + treeConn,
- j == sorted.end() ? tailPad + treeNull : tailPad + treeLine,
+ for (const auto &[n, i] : enumerate(sorted)) {
+ bool last = n + 1 == sorted.size();
+ printTree(i,
+ tailPad + (last ? treeLast : treeConn),
+ tailPad + (last ? treeNull : treeLine),
done);
}
}