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: man/include/, man/, /
Date: Wed, 12 Jun 2019 09:13:30
Message-Id: 1560330704.753605792fab143ded32ebabbf85cc840151f0d2.grobian@gentoo
1 commit: 753605792fab143ded32ebabbf85cc840151f0d2
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jun 12 09:11:44 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Wed Jun 12 09:11:44 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=75360579
7
8 quse: add mode for querying installed packages (only)
9
10 Instead of traversing the tree(s), look in the VDB (= installed
11 packages). While doing this, when using -v, we can print the enabled
12 flags next to the flag and its description, as with `equery uses'.
13
14 Bug: https://bugs.gentoo.org/656550
15 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
16
17 man/include/quse.optdesc.yaml | 4 +++
18 man/quse.1 | 7 +++-
19 quse.c | 81 +++++++++++++++++++++++++++++++++++--------
20 3 files changed, 76 insertions(+), 16 deletions(-)
21
22 diff --git a/man/include/quse.optdesc.yaml b/man/include/quse.optdesc.yaml
23 index 79a98fa..693aade 100644
24 --- a/man/include/quse.optdesc.yaml
25 +++ b/man/include/quse.optdesc.yaml
26 @@ -4,3 +4,7 @@ verbose: |
27 Also shows problems encountered during parsing. These are mostly
28 diagnostic and indicate possible incorrectness in the results.
29 quiet: Ignored for compatibility with other qapplets.
30 +installed: |
31 + Only search installed packages. Together with \fB-v\fR this shows
32 + USE-flags and their descriptions, and currently enabled flags
33 + prefixed with an asterisk (\fI*\fR).
34
35 diff --git a/man/quse.1 b/man/quse.1
36 index 7f559fd..0a031ba 100644
37 --- a/man/quse.1
38 +++ b/man/quse.1
39 @@ -1,5 +1,5 @@
40 .\" generated by mkman.py, please do NOT edit!
41 -.TH quse "1" "May 2019" "Gentoo Foundation" "quse"
42 +.TH quse "1" "Jun 2019" "Gentoo Foundation" "quse"
43 .SH NAME
44 quse \- find pkgs using useflags
45 .SH SYNOPSIS
46 @@ -22,6 +22,11 @@ Use the LICENSE vs IUSE.
47 \fB\-D\fR, \fB\-\-describe\fR
48 Describe the USE flag.
49 .TP
50 +\fB\-I\fR, \fB\-\-installed\fR
51 +Only search installed packages. Together with \fB-v\fR this shows
52 +USE-flags and their descriptions, and currently enabled flags
53 +prefixed with an asterisk (\fI*\fR).
54 +.TP
55 \fB\-p\fR \fI<arg>\fR, \fB\-\-package\fR \fI<arg>\fR
56 Restrict matching to package or category.
57 .TP
58
59 diff --git a/quse.c b/quse.c
60 index c7fbe81..751f767 100644
61 --- a/quse.c
62 +++ b/quse.c
63 @@ -21,17 +21,19 @@
64 #include <ctype.h>
65 #include <assert.h>
66
67 +#include "set.h"
68 #include "rmspace.h"
69 #include "tree.h"
70 #include "xarray.h"
71 #include "xregex.h"
72
73 -#define QUSE_FLAGS "eaLDp:R" COMMON_FLAGS
74 +#define QUSE_FLAGS "eaLDIp:R" COMMON_FLAGS
75 static struct option const quse_long_opts[] = {
76 {"exact", no_argument, NULL, 'e'},
77 {"all", no_argument, NULL, 'a'},
78 {"license", no_argument, NULL, 'L'},
79 {"describe", no_argument, NULL, 'D'},
80 + {"installed", no_argument, NULL, 'I'},
81 {"package", a_argument, NULL, 'p'},
82 {"repo", no_argument, NULL, 'R'},
83 COMMON_LONG_OPTS
84 @@ -41,6 +43,7 @@ static const char * const quse_opts_help[] = {
85 "List all ebuilds, don't match anything",
86 "Use the LICENSE vs IUSE",
87 "Describe the USE flag",
88 + "Only search installed packages",
89 "Restrict matching to package or category",
90 "Show repository the ebuild originates from",
91 COMMON_OPTS_HELP
92 @@ -56,6 +59,7 @@ struct quse_state {
93 bool do_regex:1;
94 bool do_describe:1;
95 bool do_licence:1;
96 + bool do_installed:1;
97 bool do_list:1;
98 bool do_repo:1;
99 depend_atom *match;
100 @@ -407,6 +411,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
101 depend_atom *atom = NULL; /* pacify compiler */
102 char buf[8192];
103 tree_pkg_meta *meta;
104 + set *use = NULL;
105 bool match;
106 char *p;
107 char *q;
108 @@ -432,16 +437,44 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
109 }
110 }
111
112 - meta = tree_pkg_read(pkg_ctx);
113 - if (meta == NULL)
114 - return 0;
115 + if (state->overlay != NULL) {
116 + meta = tree_pkg_read(pkg_ctx);
117 + if (meta == NULL)
118 + return 0;
119 + if (meta->IUSE == NULL)
120 + return 0;
121 + } else {
122 + size_t dummy;
123
124 - if (meta->IUSE == NULL)
125 - return 0;
126 + meta = xzalloc(sizeof(*meta));
127 +
128 + dummy = 0;
129 + if (!tree_pkg_vdb_eat(pkg_ctx, "IUSE", &meta->IUSE, &dummy)) {
130 + free(meta);
131 + return 0;
132 + }
133 +
134 + dummy = 0;
135 + tree_pkg_vdb_eat(pkg_ctx, "LICENSE", &meta->LICENSE, &dummy);
136 +
137 + s = NULL;
138 + dummy = 0;
139 + tree_pkg_vdb_eat(pkg_ctx, "USE", &s, &dummy);
140 + p = s;
141 + while ((q = strchr(p, (int)' ')) != NULL) {
142 + *q++ = '\0';
143 + use = add_set(p, use);
144 + p = q;
145 + }
146 + if (*p != '\0')
147 + use = add_set(p, use);
148 + free(s);
149 + }
150
151 if (verbose) {
152 portdirfd = openat(pkg_ctx->cat_ctx->ctx->portroot_fd,
153 - state->overlay, O_RDONLY | O_CLOEXEC | O_PATH);
154 + state->overlay == NULL ? main_overlay : state->overlay,
155 + O_RDONLY | O_CLOEXEC | O_PATH);
156 if (portdirfd == -1)
157 return 0;
158 }
159 @@ -566,7 +599,9 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
160 quse_search_profiles_desc(portdirfd, &us);
161
162 for (i = 0; i < cnt; i++) {
163 - printf(" %c%s%s%s%*s %s\n",
164 + match = use != NULL && contains_set(us.argv[i], use);
165 + printf("%s%c%s%s%s%*s %s\n",
166 + match ? "*" : " ",
167 us.argv[i][-1],
168 /* selected ? RED : NORM */ MAGENTA,
169 us.argv[i],
170 @@ -585,7 +620,16 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
171 }
172 }
173
174 - tree_close_meta(meta);
175 + if (state->overlay != NULL) {
176 + tree_close_meta(meta);
177 + } else {
178 + free(meta->IUSE);
179 + if (meta->LICENSE != NULL)
180 + free(meta->LICENSE);
181 + free(meta);
182 + if (use != NULL)
183 + free_set(use);
184 + }
185 if (verbose)
186 close(portdirfd);
187
188 @@ -603,6 +647,7 @@ int quse_main(int argc, char **argv)
189 .do_regex = true,
190 .do_describe = false,
191 .do_licence = false,
192 + .do_installed = false,
193 .do_repo = false,
194 .match = NULL,
195 .overlay = NULL,
196 @@ -610,12 +655,13 @@ int quse_main(int argc, char **argv)
197
198 while ((i = GETOPT_LONG(QUSE, quse, "")) != -1) {
199 switch (i) {
200 - case 'e': state.do_regex = false; break;
201 - case 'a': state.do_all = true; break;
202 - case 'L': state.do_licence = true; break;
203 - case 'D': state.do_describe = true; break;
204 - case 'R': state.do_repo = true; break;
205 - case 'p': match = optarg; break;
206 + case 'e': state.do_regex = false; break;
207 + case 'a': state.do_all = true; break;
208 + case 'L': state.do_licence = true; break;
209 + case 'D': state.do_describe = true; break;
210 + case 'I': state.do_installed = true; break;
211 + case 'R': state.do_repo = true; break;
212 + case 'p': match = optarg; break;
213 COMMON_GETOPTS_CASES(quse)
214 }
215 }
216 @@ -646,6 +692,11 @@ int quse_main(int argc, char **argv)
217 if (state.do_describe) {
218 array_for_each(overlays, n, overlay)
219 quse_describe_flag(portroot, overlay, &state);
220 + } else if (state.do_installed) {
221 + tree_ctx *t = tree_open_vdb(portroot, portvdb);
222 + state.overlay = NULL;
223 + tree_foreach_pkg_sorted(t, quse_results_cb, &state);
224 + tree_close(t);
225 } else {
226 array_for_each(overlays, n, overlay) {
227 tree_ctx *t = tree_open(portroot, overlay);