From da0df360e175b5d25e847fe7aaad2906612b87fb Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 5 Jul 2025 08:48:55 +0200 Subject: [PATCH] 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 --- lix/libstore/path-tree.cc | 10 ++++++++-- tests/unit/libstore/path-tree.cc | 17 +++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lix/libstore/path-tree.cc b/lix/libstore/path-tree.cc index c31e406c3..85f0ec8f1 100644 --- a/lix/libstore/path-tree.cc +++ b/lix/libstore/path-tree.cc @@ -8,6 +8,8 @@ #include #include +#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) ); diff --git a/tests/unit/libstore/path-tree.cc b/tests/unit/libstore/path-tree.cc index 3ea4c6edc..70b419f48 100644 --- a/tests/unit/libstore/path-tree.cc +++ b/tests/unit/libstore/path-tree.cc @@ -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));