Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/
Date: Thu, 26 May 2022 14:36:39
Message-Id: 1653557231.8ca9d1625448544f72aa0d45a1cbbdfa8dcfb22e.grobian@gentoo
1 commit: 8ca9d1625448544f72aa0d45a1cbbdfa8dcfb22e
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Thu May 26 09:27:11 2022 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Thu May 26 09:27:11 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8ca9d162
7
8 libq/dep: add dep_resolve_tree function
9
10 allow resolving a dep-specification to atoms found in a tree, e.g. see
11 what would get selected
12
13 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
14
15 libq/dep.c | 77 +++++++++++++++++++++++++++++++++++++++-----------------------
16 libq/dep.h | 12 ++++++----
17 2 files changed, 56 insertions(+), 33 deletions(-)
18
19 diff --git a/libq/dep.c b/libq/dep.c
20 index 99629e7..4138a1c 100644
21 --- a/libq/dep.c
22 +++ b/libq/dep.c
23 @@ -1,5 +1,5 @@
24 /*
25 - * Copyright 2005-2019 Gentoo Foundation
26 + * Copyright 2005-2022 Gentoo Foundation
27 * Distributed under the terms of the GNU General Public License v2
28 *
29 * Copyright 2005-2010 Ned Ludd - <solar@g.o>
30 @@ -20,6 +20,7 @@
31 #include "atom.h"
32 #include "dep.h"
33 #include "set.h"
34 +#include "tree.h"
35 #include "xarray.h"
36 #include "xasprintf.h"
37
38 @@ -62,8 +63,6 @@ static void
39 _dep_burn_node(dep_node *node)
40 {
41 assert(node);
42 - if (node->info_on_heap)
43 - free(node->info);
44 if (node->atom)
45 atom_implode(node->atom);
46 free(node);
47 @@ -237,7 +236,6 @@ dep_print_tree(
48 {
49 size_t s;
50 int indent = 4; /* Gentoo 4-wide indent standard */
51 - depend_atom *d = NULL;
52 bool singlechild = false;
53 bool nonewline = false;
54
55 @@ -260,33 +258,31 @@ dep_print_tree(
56 if (root->type == DEP_OR)
57 fprintf(fp, "|| (");
58 if (root->info) {
59 - if (hlatoms != NULL && array_cnt(hlatoms) > 0 &&
60 - root->type == DEP_NORM)
61 - {
62 - size_t i;
63 - depend_atom *m;
64 - char *oslot;
65 -
66 - d = root->atom;
67 - d->pfx_op = d->sfx_op = ATOM_OP_NONE;
68 -
69 - array_for_each(hlatoms, i, m) {
70 - oslot = d->SLOT;
71 - if (m->SLOT == NULL)
72 - d->SLOT = NULL;
73 -
74 - if (atom_compare(m, d) == EQUAL) {
75 - m = NULL;
76 - break;
77 + if (root->type == DEP_NORM) {
78 + bool dohl = false;
79 +
80 + if (hlatoms != NULL && array_cnt(hlatoms) > 0)
81 + {
82 + size_t i;
83 + depend_atom *m;
84 +
85 + array_for_each(hlatoms, i, m) {
86 + /* make m query, such that any specifics (SLOT,
87 + * pfx/sfx) from the depstring are ignored while
88 + * highlighting */
89 + if (atom_compare(root->atom, m) == EQUAL) {
90 + dohl = true;
91 + break;
92 + }
93 }
94 - d->SLOT = oslot;
95 }
96
97 - if (m == NULL) { /* match found */
98 - fprintf(fp, "%s%s%s", hlcolor, root->info, NORM);
99 - } else {
100 - fprintf(fp, "%s", root->info);
101 - }
102 + fprintf(fp, "%s%s%s",
103 + dohl ? hlcolor : "",
104 + atom_to_string(root->atom),
105 + dohl ? NORM : "");
106 + if (root->atom_resolved && verbose > 0)
107 + fprintf(fp, " # %s", root->info);
108 } else {
109 fprintf(fp, "%s", root->info);
110 }
111 @@ -355,6 +351,31 @@ dep_prune_use(dep_node *root, set *use)
112 dep_prune_use(root->children, use);
113 }
114
115 +void
116 +dep_resolve_tree(dep_node *root, tree_ctx *t)
117 +{
118 + if (root->type != DEP_NULL) {
119 + if (root->type == DEP_NORM && root->atom) {
120 + depend_atom *d = root->atom;
121 + tree_match_ctx *r = tree_match_atom(t, d,
122 + TREE_MATCH_DEFAULT |
123 + TREE_MATCH_LATEST);
124 + if (r != NULL) {
125 + atom_implode(d);
126 + root->atom = atom_clone(r->atom);
127 + root->atom_resolved = 1;
128 + tree_match_close(r);
129 + }
130 + }
131 +
132 + if (root->children)
133 + dep_resolve_tree(root->children, t);
134 + }
135 +
136 + if (root->neighbor)
137 + dep_resolve_tree(root->neighbor, t);
138 +}
139 +
140 void
141 dep_flatten_tree(const dep_node *root, array_t *out)
142 {
143
144 diff --git a/libq/dep.h b/libq/dep.h
145 index 1055d29..68d5c75 100644
146 --- a/libq/dep.h
147 +++ b/libq/dep.h
148 @@ -1,5 +1,5 @@
149 /*
150 - * Copyright 2005-2019 Gentoo Foundation
151 + * Copyright 2005-2022 Gentoo Foundation
152 * Distributed under the terms of the GNU General Public License v2
153 */
154
155 @@ -9,6 +9,7 @@
156 #include "atom.h"
157 #include "colors.h"
158 #include "set.h"
159 +#include "tree.h"
160 #include "xarray.h"
161
162 typedef enum {
163 @@ -28,10 +29,10 @@ static const char * const _dep_names[] = {
164 };
165
166 struct _dep_node {
167 - dep_type type;
168 - char *info;
169 - char info_on_heap;
170 - depend_atom *atom;
171 + dep_type type;
172 + char *info;
173 + char atom_resolved:1;
174 + depend_atom *atom;
175 struct _dep_node *parent;
176 struct _dep_node *neighbor;
177 struct _dep_node *children;
178 @@ -47,6 +48,7 @@ typedef struct _dep_node dep_node;
179
180 dep_node *dep_grow_tree(const char *depend);
181 void dep_print_tree(FILE *fp, const dep_node *root, size_t space, array_t *m, const char *c, int verbose);
182 +void dep_resolve_tree(dep_node *root, tree_ctx *t);
183 void dep_burn_tree(dep_node *root);
184 void dep_prune_use(dep_node *root, set *use);
185 void dep_flatten_tree(const dep_node *root, array_t *out);