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/, tests/qdepends/
Date: Sun, 05 May 2019 20:05:52
Message-Id: 1557086680.73915971f03cabcbb64accab0c65a14d01904dd5.grobian@gentoo
1 commit: 73915971f03cabcbb64accab0c65a14d01904dd5
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Sun May 5 20:04:40 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Sun May 5 20:04:40 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=73915971
7
8 qdepends: allow custom formatting
9
10 This isn't yet fully useful, since information like SLOT, REPO, etc.
11 isn't available in the parsed atoms.
12
13 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
14
15 TODO.md | 2 +-
16 man/include/qdepends.desc | 4 +++-
17 man/qdepends.1 | 12 +++++++-----
18 qdepends.c | 43 +++++++++++++++++++------------------------
19 tests/qdepends/dotest | 2 +-
20 5 files changed, 31 insertions(+), 32 deletions(-)
21
22 diff --git a/TODO.md b/TODO.md
23 index e433123..bc4f524 100644
24 --- a/TODO.md
25 +++ b/TODO.md
26 @@ -10,7 +10,7 @@
27
28 - standardize/unify/clean up misc handling of colors
29 define rules:
30 - BOLD CATEGORY/ BLUE PKG GREEN ::REPO NORM [ MAGENTA USE NORM ]
31 + BOLD CATEGORY/ BLUE PKG BKBLUE -VER YELLOW :SLOT GREEN ::REPO NORM [ MAGENTA USE NORM ]
32
33 - remove odd rmspace for each string in libq/set.c (allows a lot less
34 malloc/frees)
35
36 diff --git a/man/include/qdepends.desc b/man/include/qdepends.desc
37 index 070032e..b9954c9 100644
38 --- a/man/include/qdepends.desc
39 +++ b/man/include/qdepends.desc
40 @@ -27,4 +27,6 @@ dependencies for the package are shown. When colours are enabled, the
41 matched atom is highlighted in the list. In addition to just querying
42 DEPEND, the default mode changed to query all DEPEND-variables, and
43 return the unique atoms found in them. Automatic regular expression
44 -match support was removed.
45 +match support was removed. The \fB-N\fR option was removed, as the same
46 +effect can be achieved via the new \fB-F\fR option or \fB-q\fR option.
47 +The \fB-f\fR option was renamed to \fB-S\fR.
48
49 diff --git a/man/qdepends.1 b/man/qdepends.1
50 index 1020b9a..bee3bc1 100644
51 --- a/man/qdepends.1
52 +++ b/man/qdepends.1
53 @@ -35,7 +35,9 @@ dependencies for the package are shown. When colours are enabled, the
54 matched atom is highlighted in the list. In addition to just querying
55 DEPEND, the default mode changed to query all DEPEND-variables, and
56 return the unique atoms found in them. Automatic regular expression
57 -match support was removed.
58 +match support was removed. The \fB-N\fR option was removed, as the same
59 +effect can be achieved via the new \fB-F\fR option or \fB-q\fR option.
60 +The \fB-f\fR option was renamed to \fB-S\fR.
61 .SH OPTIONS
62 .TP
63 \fB\-d\fR, \fB\-\-depend\fR
64 @@ -56,10 +58,7 @@ package that references \fI<arg>\fR in DEPEND, RDEPEND, PDEPEND or BDEPEND.
65 This can be useful to find consumers of a given package, e.g.\ to
66 search for packages that have \fIlogwatch\fR in their DEPEND.
67 .TP
68 -\fB\-N\fR, \fB\-\-name\-only\fR
69 -Only show category/package, instead of category/package-version.
70 -.TP
71 -\fB\-f\fR, \fB\-\-format\fR
72 +\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR
73 Pretty-print DEPEND declaration to be used in an ebuild. This
74 option initiates a very different mode of operation. Instead of
75 printing searching through packages, it constructs a multi-line
76 @@ -70,6 +69,9 @@ a single dependency declaration. When used with the \fB\-q\fR
77 option, only the pretty-printed dependency declaration is printed,
78 e.g.\ the DEPEND= part is skipped.
79 .TP
80 +\fB\-S\fR, \fB\-\-pretty\fR
81 +Pretty format specified depend strings.
82 +.TP
83 \fB\-\-root\fR \fI<arg>\fR
84 Set the ROOT env var.
85 .TP
86
87 diff --git a/qdepends.c b/qdepends.c
88 index 09156f6..9cfe095 100644
89 --- a/qdepends.c
90 +++ b/qdepends.c
91 @@ -22,15 +22,15 @@
92 #include "xasprintf.h"
93 #include "xregex.h"
94
95 -#define QDEPENDS_FLAGS "drpbfNQu" COMMON_FLAGS
96 +#define QDEPENDS_FLAGS "drpbQF:S" COMMON_FLAGS
97 static struct option const qdepends_long_opts[] = {
98 {"depend", no_argument, NULL, 'd'},
99 {"rdepend", no_argument, NULL, 'r'},
100 {"pdepend", no_argument, NULL, 'p'},
101 {"bdepend", no_argument, NULL, 'b'},
102 {"query", no_argument, NULL, 'Q'},
103 - {"name-only", no_argument, NULL, 'N'},
104 - {"format", no_argument, NULL, 'f'},
105 + {"format", a_argument, NULL, 'F'},
106 + {"pretty", no_argument, NULL, 'S'},
107 COMMON_LONG_OPTS
108 };
109 static const char * const qdepends_opts_help[] = {
110 @@ -39,14 +39,12 @@ static const char * const qdepends_opts_help[] = {
111 "Show PDEPEND info",
112 "Show BDEPEND info",
113 "Query reverse deps",
114 - "Only show package name",
115 + "Print matched atom using given format string",
116 "Pretty format specified depend strings",
117 COMMON_OPTS_HELP
118 };
119 #define qdepends_usage(ret) usage(ret, QDEPENDS_FLAGS, qdepends_long_opts, qdepends_opts_help, NULL, lookup_applet_idx("qdepends"))
120
121 -static char qdep_name_only = 0;
122 -
123 /* structures / types / etc ... */
124 struct qdepends_opt_state {
125 unsigned char qmode;
126 @@ -55,6 +53,7 @@ struct qdepends_opt_state {
127 set *udeps;
128 char *depend;
129 size_t depend_len;
130 + const char *format;
131 };
132
133 #define QMODE_DEPEND (1<<0)
134 @@ -141,8 +140,7 @@ qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
135
136 ret = 1;
137
138 - printf("%s%s/%s%s%s:", BOLD, catname, BLUE,
139 - qdep_name_only ? datom->PN : pkgname, NORM);
140 + printf("%s:", atom_format(state->format, datom, 0));
141 }
142
143 xarrayfree_int(state->deps);
144 @@ -179,11 +177,8 @@ qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
145 if (atom == NULL) {
146 ret = 1;
147
148 - if (!firstmatch) {
149 - printf("%s%s/%s%s%s:",
150 - BOLD, catname, BLUE,
151 - qdep_name_only ? datom->PN : pkgname, NORM);
152 - }
153 + if (!firstmatch)
154 + printf("%s:", atom_format(state->format, datom, 0));
155 firstmatch = true;
156
157 printf("\n%s=\"\n", *dfile);
158 @@ -209,12 +204,8 @@ qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
159 if (fatom == NULL) {
160 ret = 1;
161
162 - if (!firstmatch) {
163 - printf("%s%s/%s%s%s:",
164 - BOLD, catname, BLUE,
165 - qdep_name_only ? datom->PN : pkgname,
166 - NORM);
167 - }
168 + if (!firstmatch)
169 + printf("%s:", atom_format(state->format, datom, 0));
170 firstmatch = true;
171
172 snprintf(buf, sizeof(buf), "%s%s%s",
173 @@ -263,10 +254,14 @@ int qdepends_main(int argc, char **argv)
174 .qmode = 0,
175 .depend = NULL,
176 .depend_len = 0,
177 + .format = "%[CATEGORY]%[PF]",
178 };
179 size_t i;
180 int ret;
181 - bool do_format = false;
182 + bool do_pretty = false;
183 +
184 + if (quiet)
185 + state.format = "%[CATEGORY]%[PN]";
186
187 while ((ret = GETOPT_LONG(QDEPENDS, qdepends, "")) != -1) {
188 switch (ret) {
189 @@ -277,8 +272,8 @@ int qdepends_main(int argc, char **argv)
190 case 'p': state.qmode |= QMODE_PDEPEND; break;
191 case 'b': state.qmode |= QMODE_BDEPEND; break;
192 case 'Q': state.qmode |= QMODE_REVERSE; break;
193 - case 'N': qdep_name_only = 1; break;
194 - case 'f': do_format = true; break;
195 + case 'S': do_pretty = true; break;
196 + case 'F': state.format = optarg; break;
197 }
198 }
199
200 @@ -290,10 +285,10 @@ int qdepends_main(int argc, char **argv)
201 QMODE_BDEPEND;
202 }
203
204 - if ((argc == optind) && !do_format)
205 + if ((argc == optind) && !do_pretty)
206 qdepends_usage(EXIT_FAILURE);
207
208 - if (do_format) {
209 + if (do_pretty) {
210 while (optind < argc) {
211 if (!qdepends_print_depend(stdout, argv[optind++]))
212 return EXIT_FAILURE;
213
214 diff --git a/tests/qdepends/dotest b/tests/qdepends/dotest
215 index 6a8c3d6..ebf0e81 100755
216 --- a/tests/qdepends/dotest
217 +++ b/tests/qdepends/dotest
218 @@ -44,7 +44,7 @@ test() {
219 tend $? "${num} ${cmd[*]}"
220 }
221
222 -testf() { test "$1" "${3:-0}" -f "$2"; }
223 +testf() { test "$1" "${3:-0}" -S "$2"; }
224
225 # basic sanity checks
226 testf 00 '|' 1