commit: 82f8dc2ee9ba0ff97924df0dcc3feba3935b979c
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 7 17:14:08 2022 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Apr 7 17:14:08 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=82f8dc2e
libq/dep: print single nodes on a single line
condense conditional and use-deps to a single line when there's a single
target, e.g.:
use? ( cat/pkg )
instead of
use? (
cat/pkg
)
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/dep.c | 34 +++++++++++++++++++++++++++++-----
tests/qdepends/list03.good | 4 +---
tests/qdepends/list04.good | 4 +---
tests/qdepends/list05.good | 4 +---
4 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/libq/dep.c b/libq/dep.c
index d431367..99629e7 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -238,6 +238,13 @@ dep_print_tree(
size_t s;
int indent = 4; /* Gentoo 4-wide indent standard */
depend_atom *d = NULL;
+ bool singlechild = false;
+ bool nonewline = false;
+
+ if (verbose < 0) {
+ nonewline = true;
+ verbose = -verbose - 1;
+ }
assert(root);
if (root->type == DEP_NULL)
@@ -248,7 +255,8 @@ dep_print_tree(
if (verbose > 0)
fprintf(fp, "Node [%s]: ", _dep_names[root->type]);
- /*printf("Node %p [%s] %p %p %p: ", root, _dep_names[root->type],
root->parent, root->neighbor, root->children);*/
+ /*printf("Node %p [%s] %p %p %p: ", root, _dep_names[root->type],
+ * root->parent, root->neighbor, root->children);*/
if (root->type == DEP_OR)
fprintf(fp, "|| (");
if (root->info) {
@@ -286,14 +294,30 @@ dep_print_tree(
if (root->type == DEP_USE)
fprintf(fp, "? (");
}
- fprintf(fp, "\n");
+
+ if (root->children &&
+ root->children->children == NULL &&
+ root->children->neighbor == NULL)
+ {
+ singlechild = true;
+ }
+
+ if (singlechild)
+ fprintf(fp, " ");
+ else if (!nonewline)
+ fprintf(fp, "\n");
if (root->children)
- dep_print_tree(fp, root->children, space+1, hlatoms, hlcolor,
verbose);
+ dep_print_tree(fp, root->children,
+ singlechild ? 0 : space + 1,
+ hlatoms, hlcolor, singlechild ?
-verbose - 1 : verbose);
if (root->type == DEP_OR || root->type == DEP_USE) {
- for (s = space; s; --s)
- fprintf(fp, "%*s", indent, "");
+ if (singlechild)
+ fprintf(fp, " ");
+ else
+ for (s = space; s; --s)
+ fprintf(fp, "%*s", indent, "");
fprintf(fp, ")\n");
}
this_node_sucks:
diff --git a/tests/qdepends/list03.good b/tests/qdepends/list03.good
index f66b636..d0eb5d2 100644
--- a/tests/qdepends/list03.good
+++ b/tests/qdepends/list03.good
@@ -1,5 +1,3 @@
DEPEND="
- foo? (
- a/b
- )
+ foo? ( a/b )
"
diff --git a/tests/qdepends/list04.good b/tests/qdepends/list04.good
index 2457caf..7f0887a 100644
--- a/tests/qdepends/list04.good
+++ b/tests/qdepends/list04.good
@@ -1,5 +1,3 @@
DEPEND="
- || (
- a/b
- )
+ || ( a/b )
"
diff --git a/tests/qdepends/list05.good b/tests/qdepends/list05.good
index 0b7d420..868efae 100644
--- a/tests/qdepends/list05.good
+++ b/tests/qdepends/list05.good
@@ -1,9 +1,7 @@
DEPEND="
|| (
|| (
- || (
- x
- )
+ || ( x )
a
)
)