libstore: print dependency in tree boldly

That way it's easier to spot whether a node is the "final" node in the
graph which is especially helpful for larger graphs.

Change-Id: I460a699f07f5455917792599f4247ebf8f430d93
This commit is contained in:
Maximilian Bosch
2025-07-07 11:44:17 +00:00
parent 325e7e1824
commit da0df360e1
2 changed files with 19 additions and 8 deletions
+8 -2
View File
@@ -8,6 +8,8 @@
#include <boost/algorithm/string/join.hpp>
#include <queue>
#define ANSI_DIM_ALREADY_VISITED "\e[38;5;244m"
namespace nix {
static std::string hilite(const std::string & s, size_t pos, size_t len,
const std::string & colour = ANSI_RED)
@@ -132,7 +134,9 @@ try {
output.push_back(
fmt("%s%s%s%s" ANSI_NORMAL,
firstPad,
node.visited ? "\e[38;5;244m" : "",
node.path == dependencyPath ? ANSI_NORMAL
: node.visited ? ANSI_DIM_ALREADY_VISITED
: "",
firstPad != "" ? "" : "",
pathS)
);
@@ -201,7 +205,9 @@ try {
output.push_back(
fmt("%s%s%s%s" ANSI_NORMAL,
firstPad,
ref.second->visited ? "\e[38;5;244m" : "",
ref.second->path == dependencyPath ? ANSI_BOLD
: ref.second->visited ? ANSI_DIM_ALREADY_VISITED
: "",
last ? treeLast : treeConn,
pathS)
);
+11 -6
View File
@@ -19,12 +19,15 @@ TEST(PathTree, simple)
graph.insert({parent, {child}});
auto graph_data =
aio.blockOn(genGraphString(parent, child, graph, *store, false, false));
aio.blockOn(genGraphString(parent, child, graph, *store, false, false));
// clang-format off
ASSERT_EQ(
graph_data,
"/nix/store/hr8lmmjmd1jk6s3p5ymggyk4am7n2lmb-openssh-10.0p2\n└───/nix/store/"
"q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66\x1B[0m"
"/nix/store/hr8lmmjmd1jk6s3p5ymggyk4am7n2lmb-openssh-10.0p2\n"
"\x1B[1m└───/nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66\x1B[0m"
);
// clang-format on
}
TEST(PathTree, all)
@@ -42,11 +45,13 @@ TEST(PathTree, all)
graph.insert({parent, {intermediate, child}});
graph.insert({child, {}});
// clang-format off
const std::string expected =
"/nix/store/hr8lmmjmd1jk6s3p5ymggyk4am7n2lmb-openssh-10.0p2\n"
"├───/nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66\x1B[0m\n"
"└───/nix/store/6r4zqb04fq5l5l4zghq76wvcpz7dwd35-linux-pam-1.6.1\x1B[0m\n"
" └───/nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66\x1B[0m";
"\x1B[1m├───/nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66\x1B[0m\n"
"└───/nix/store/6r4zqb04fq5l5l4zghq76wvcpz7dwd35-linux-pam-1.6.1\x1B[0m\n"
" \x1B[1m└───/nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66\x1B[0m";
// clang-format on
auto graph_data =
aio.blockOn(genGraphString(parent, child, graph, *store, true, false));