commit: dd2716c65cdb220668c53fd64239968544266151
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 5 17:35:13 2026 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Feb 5 17:35:13 2026 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dd2716c6
libq/dep: improve printing somewhat
support highlighting based on resolved state
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/dep.c | 84 ++++++++++++++++++++++++++++++++-------------------
qdepends.c | 22 ++------------
tests/qdepends/dotest | 2 +-
3 files changed, 56 insertions(+), 52 deletions(-)
diff --git a/libq/dep.c b/libq/dep.c
index 7be1f646..15758203 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -404,59 +404,42 @@ dep_grow_tree_fail:
return ret;
}
-void dep_print_tree
+static void dep_print_tree_int
(
FILE *fp,
const dep_node_t *root,
size_t space,
array *hlatoms,
const char *hlcolor,
- int verbose
+ int verbose,
+ bool first
)
{
dep_node_t *memb;
size_t s;
int indent = 4; /* Gentoo 4-wide indent standard */
- bool nonewline = false;
- bool dohl = false;
+ bool newline = true;
if (root == NULL)
return;
if (verbose < 0)
{
- nonewline = true;
- verbose = -verbose - 1;
- }
-
- /* handle pseudo root node */
- if (root->parent == NULL)
- {
- array_for_each(root->members, s, memb)
- {
- dep_print_tree(fp, memb, space, hlatoms, hlcolor, verbose);
- }
- if (!nonewline &&
- array_cnt(root->members) > 0)
- fprintf(fp, "\n");
- return;
+ newline = false;
+ verbose = -verbose - 1;
}
- if (hlatoms != NULL &&
- array_cnt(hlatoms) > 0)
- dohl = true;
-
if (verbose > 0)
fprintf(fp, "Node [%s]: ", dep_type_names[root->type]);
- if (nonewline)
+ if (!newline)
{
- if (space > 1)
+ if (!first > 0)
fprintf(fp, " ");
}
else
{
- if (space > 1)
+ if (!first > 0)
fprintf(fp, "\n");
for (s = space; s > 0; s--)
fprintf(fp, "%*s", indent, "");
@@ -476,9 +459,13 @@ void dep_print_tree
bool match = false;
if (root->pkg != NULL)
+ {
a = tree_pkg_atom(root->pkg, false);
+ if (hlatoms == NULL)
+ match = true;
+ }
- if (dohl)
+ if (hlatoms != NULL)
{
size_t i;
depend_atom *m;
@@ -520,13 +507,17 @@ void dep_print_tree
array_for_each(root->members, s, memb)
{
- dep_print_tree(fp, memb,
- singlechild ? 0 : space + 1,
- hlatoms, hlcolor, singlechild ? -verbose - 1 : verbose);
+ dep_print_tree_int(fp,
+ memb,
+ singlechild ? 0 : space + 1,
+ hlatoms,
+ hlcolor,
+ singlechild ? -verbose - 1 : verbose,
+ singlechild ? true : false);
}
if (singlechild ||
- nonewline)
+ !newline)
{
fprintf(fp, " )");
}
@@ -540,6 +531,37 @@ void dep_print_tree
}
}
+void dep_print_tree
+(
+ FILE *fp,
+ const dep_node_t *root,
+ size_t space,
+ array *hlatoms,
+ const char *hlcolor,
+ int verbose
+)
+{
+ dep_node_t *memb;
+ size_t s;
+
+ if (root == NULL)
+ return;
+
+ /* simplify checks from here on out */
+ if (hlatoms != NULL &&
+ array_cnt(hlatoms) == 0)
+ hlatoms = NULL;
+
+ array_for_each(root->members, s, memb)
+ dep_print_tree_int(fp, memb, space, hlatoms, hlcolor, verbose, s == 0);
+
+ if (verbose >= 0 &&
+ array_cnt(root->members) > 0)
+ fprintf(fp, "\n");
+
+ return;
+}
+
void dep_burn_tree
(
dep_node_t *root
diff --git a/qdepends.c b/qdepends.c
index c4a5387f..3d7dad0a 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -198,26 +198,8 @@ qdepends_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
!(state->qmode & QMODE_REVERSE) &&
verbose)
{
- array *match =
- tree_match_atom(state->vdb, datom,
TREE_MATCH_DEFAULT);
-
- /* pull in flags in use if possible */
- if (array_cnt(match) > 0)
- {
- tree_pkg_ctx *pkg = array_get(match, 0);
- depstr = get_depstr(i, pkg);
- if (depstr != NULL) {
- dep_node_t *dep_vdb =
dep_grow_tree(depstr);
- if (dep_vdb != NULL) {
- dep_flatten_tree(dep_vdb, deps);
- dep_burn_tree(dep_vdb);
- } else {
- warn("failed to parse VDB
depstring from %s\n",
- atom_to_string(datom));
- }
- }
- }
- array_free(match);
+ if (!state->resolve)
+ dep_resolve_tree(dep_tree, state->vdb);
} else {
if (state->qmode & QMODE_FILTERUSE)
dep_prune_use(dep_tree, ev_use);
diff --git a/tests/qdepends/dotest b/tests/qdepends/dotest
index ca25f651..f5037d28 100755
--- a/tests/qdepends/dotest
+++ b/tests/qdepends/dotest
@@ -40,7 +40,7 @@ test() {
if [[ ! -e ${good} ]] ; then
cp list "${good}"
fi
- diff -u --label "${cmd[*]}" list "${good}"
+ diff -u --label "${cmd[*]}" "${good}" list
tend $? "${num} ${cmd[*]}"
}