1 |
commit: 24e232b949803a0d650387c61eb32c95d7270647 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Jan 2 11:17:53 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jan 2 11:17:53 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=24e232b9 |
7 |
|
8 |
libq/tree: have tree_foreach_pkg take a query atom |
9 |
|
10 |
Allow to reduce the search by having a query atom. This will skip |
11 |
categories and packages not matching the atom, possibly avoiding lots of |
12 |
work. |
13 |
|
14 |
This needs to be exploited from applets where necessary. |
15 |
|
16 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
17 |
|
18 |
TODO.md | 2 -- |
19 |
libq/tree.c | 79 +++++++++++++++++++++++++++++++++++++++++++++---------------- |
20 |
libq/tree.h | 21 +++++++--------- |
21 |
qcheck.c | 4 ++-- |
22 |
qdepends.c | 4 ++-- |
23 |
qfile.c | 4 ++-- |
24 |
qkeyword.c | 4 ++-- |
25 |
qlist.c | 2 +- |
26 |
qmerge.c | 65 +++++++++++++++++--------------------------------- |
27 |
qsearch.c | 4 ++-- |
28 |
quse.c | 6 ++--- |
29 |
11 files changed, 103 insertions(+), 92 deletions(-) |
30 |
|
31 |
diff --git a/TODO.md b/TODO.md |
32 |
index d89dda1..71a0ce1 100644 |
33 |
--- a/TODO.md |
34 |
+++ b/TODO.md |
35 |
@@ -9,8 +9,6 @@ |
36 |
`ACCEPT_LICENSE="${ACCEPT_LICENSE} bar"`<br> |
37 |
we end up getting just:<br> |
38 |
`ACCEPT_LICENSE=" bar"` |
39 |
-- tree\_foreach\_pkg should have variant that takes an atom (or just |
40 |
- cat?) to reduce search space |
41 |
- tree\_get\_atoms should return atoms iso string set, needs a rewrite |
42 |
to use foreach\_pkg and get\_atom -- set is ready for storing objects |
43 |
now |
44 |
|
45 |
diff --git a/libq/tree.c b/libq/tree.c |
46 |
index 377af83..8996e55 100644 |
47 |
--- a/libq/tree.c |
48 |
+++ b/libq/tree.c |
49 |
@@ -57,8 +57,6 @@ tree_open_int(const char *sroot, const char *tdir, bool quiet) |
50 |
goto cv_error; |
51 |
|
52 |
ctx->do_sort = false; |
53 |
- ctx->catsortfunc = alphasort; |
54 |
- ctx->pkgsortfunc = tree_pkg_compar; |
55 |
return ctx; |
56 |
|
57 |
cv_error: |
58 |
@@ -237,23 +235,31 @@ tree_next_cat(tree_ctx *ctx) |
59 |
{ |
60 |
/* search for a category directory */ |
61 |
tree_cat_ctx *cat_ctx = NULL; |
62 |
+ const struct dirent *de; |
63 |
|
64 |
if (ctx->do_sort) { |
65 |
if (ctx->cat_de == NULL) { |
66 |
ctx->cat_cnt = scandirat(ctx->tree_fd, |
67 |
- ".", &ctx->cat_de, tree_filter_cat, ctx->catsortfunc); |
68 |
+ ".", &ctx->cat_de, tree_filter_cat, alphasort); |
69 |
ctx->cat_cur = 0; |
70 |
} |
71 |
|
72 |
while (ctx->cat_cur < ctx->cat_cnt) { |
73 |
- cat_ctx = tree_open_cat(ctx, ctx->cat_de[ctx->cat_cur++]->d_name); |
74 |
+ de = ctx->cat_de[ctx->cat_cur++]; |
75 |
+ |
76 |
+ /* match if cat is requested */ |
77 |
+ if (ctx->query_atom != NULL && ctx->query_atom->CATEGORY != NULL && |
78 |
+ strcmp(ctx->query_atom->CATEGORY, de->d_name) != 0) |
79 |
+ continue; |
80 |
+ |
81 |
+ cat_ctx = tree_open_cat(ctx, de->d_name); |
82 |
if (!cat_ctx) |
83 |
continue; |
84 |
+ |
85 |
break; |
86 |
} |
87 |
} else { |
88 |
/* cheaper "streaming" variant */ |
89 |
- const struct dirent *de; |
90 |
do { |
91 |
de = readdir(ctx->dir); |
92 |
if (!de) |
93 |
@@ -262,6 +268,11 @@ tree_next_cat(tree_ctx *ctx) |
94 |
if (tree_filter_cat(de) == 0) |
95 |
continue; |
96 |
|
97 |
+ /* match if cat is requested */ |
98 |
+ if (ctx->query_atom != NULL && ctx->query_atom->CATEGORY != NULL && |
99 |
+ strcmp(ctx->query_atom->CATEGORY, de->d_name) != 0) |
100 |
+ continue; |
101 |
+ |
102 |
cat_ctx = tree_open_cat(ctx, de->d_name); |
103 |
if (!cat_ctx) |
104 |
continue; |
105 |
@@ -327,6 +338,17 @@ tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name) |
106 |
pkg_ctx->cat_ctx = cat_ctx; |
107 |
pkg_ctx->atom = NULL; |
108 |
pkg_ctx->meta = NULL; |
109 |
+ |
110 |
+ /* see if this pkg matches the query, here we can finally check |
111 |
+ * version conditions like >=, etc. */ |
112 |
+ if (cat_ctx->ctx->query_atom != NULL) { |
113 |
+ (void)tree_get_atom(pkg_ctx, false); |
114 |
+ if (atom_compare(pkg_ctx->atom, cat_ctx->ctx->query_atom) != EQUAL) { |
115 |
+ tree_close_pkg(pkg_ctx); |
116 |
+ return NULL; |
117 |
+ } |
118 |
+ } |
119 |
+ |
120 |
return pkg_ctx; |
121 |
} |
122 |
|
123 |
@@ -348,6 +370,7 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx) |
124 |
{ |
125 |
tree_pkg_ctx *pkg_ctx = NULL; |
126 |
const struct dirent *de; |
127 |
+ depend_atom *qa = cat_ctx->ctx->query_atom; |
128 |
|
129 |
if (cat_ctx->ctx->do_sort) { |
130 |
if (cat_ctx->pkg_ctxs == NULL) { |
131 |
@@ -360,11 +383,22 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx) |
132 |
if (tree_filter_pkg(de) == 0) |
133 |
continue; |
134 |
|
135 |
+ /* perform package name check, for we don't have an atom |
136 |
+ * yet, and creating it is expensive, which we better |
137 |
+ * defer to pkg time, and filter most stuff out here |
138 |
+ * note that we might over-match, but that's easier than |
139 |
+ * trying to deal with end of string or '-' here (which |
140 |
+ * still wouldn't be 100% because name rules are complex) */ |
141 |
+ if (qa != NULL && qa->PN != NULL && |
142 |
+ strncmp(qa->PN, de->d_name, strlen(qa->PN)) != 0) |
143 |
+ continue; |
144 |
+ |
145 |
if (cat_ctx->pkg_cnt == pkg_size) { |
146 |
pkg_size += 256; |
147 |
cat_ctx->pkg_ctxs = xrealloc(cat_ctx->pkg_ctxs, |
148 |
sizeof(*cat_ctx->pkg_ctxs) * pkg_size); |
149 |
} |
150 |
+ |
151 |
name = xstrdup(de->d_name); |
152 |
pkg_ctx = cat_ctx->pkg_ctxs[cat_ctx->pkg_cnt++] = |
153 |
tree_open_pkg(cat_ctx, name); |
154 |
@@ -374,9 +408,9 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx) |
155 |
} |
156 |
} |
157 |
|
158 |
- if (cat_ctx->ctx->pkgsortfunc != NULL && cat_ctx->pkg_cnt > 1) { |
159 |
+ if (cat_ctx->pkg_cnt > 1) { |
160 |
qsort(cat_ctx->pkg_ctxs, cat_ctx->pkg_cnt, |
161 |
- sizeof(*cat_ctx->pkg_ctxs), cat_ctx->ctx->pkgsortfunc); |
162 |
+ sizeof(*cat_ctx->pkg_ctxs), tree_pkg_compar); |
163 |
} |
164 |
} |
165 |
|
166 |
@@ -392,6 +426,11 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx) |
167 |
if (tree_filter_pkg(de) == 0) |
168 |
continue; |
169 |
|
170 |
+ /* perform package name check as for the sorted variant */ |
171 |
+ if (qa != NULL && qa->PN != NULL && |
172 |
+ strncmp(qa->PN, de->d_name, strlen(qa->PN)) != 0) |
173 |
+ continue; |
174 |
+ |
175 |
pkg_ctx = tree_open_pkg(cat_ctx, de->d_name); |
176 |
if (!pkg_ctx) |
177 |
continue; |
178 |
@@ -428,8 +467,6 @@ tree_next_pkg(tree_cat_ctx *cat_ctx) |
179 |
pkgdir->portroot_fd = -1; |
180 |
pkgdir->tree_fd = cat_ctx->fd; |
181 |
pkgdir->do_sort = ctx->do_sort; |
182 |
- pkgdir->catsortfunc = ctx->catsortfunc; |
183 |
- pkgdir->pkgsortfunc = ctx->pkgsortfunc; |
184 |
pkgdir->repo = ctx->repo; |
185 |
pkgdir->cachetype = ctx->cachetype; |
186 |
|
187 |
@@ -440,7 +477,7 @@ tree_next_pkg(tree_cat_ctx *cat_ctx) |
188 |
* directory or something */ |
189 |
if (ctx->ebuilddir_cat_ctx == NULL) { |
190 |
ctx->ebuilddir_pkg_ctx = NULL; |
191 |
- return NULL; |
192 |
+ continue; |
193 |
} |
194 |
|
195 |
/* "zap" the pkg such that it looks like CAT/P */ |
196 |
@@ -1155,7 +1192,8 @@ tree_close_pkg(tree_pkg_ctx *pkg_ctx) |
197 |
} |
198 |
|
199 |
static int |
200 |
-tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv) |
201 |
+tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, |
202 |
+ void *priv, depend_atom *query) |
203 |
{ |
204 |
char *p = ctx->pkgs; |
205 |
char *q; |
206 |
@@ -1239,6 +1277,11 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv) |
207 |
if (atom != NULL) |
208 |
atom_implode(atom); |
209 |
atom = atom_explode(c); |
210 |
+ /* pretend this entry is bogus if it doesn't match query */ |
211 |
+ if (query != NULL && atom_compare(atom, query) != EQUAL) { |
212 |
+ atom_implode(atom); |
213 |
+ atom = NULL; |
214 |
+ } |
215 |
#define match_key(X) match_key2(X,X) |
216 |
#define match_key2(X,Y) \ |
217 |
} else if (strcmp(p, #X) == 0) { \ |
218 |
@@ -1270,9 +1313,8 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv) |
219 |
} |
220 |
|
221 |
int |
222 |
-tree_foreach_pkg(tree_ctx *ctx, |
223 |
- tree_pkg_cb callback, void *priv, tree_cat_filter filter, |
224 |
- bool sort, void *catsortfunc, void *pkgsortfunc) |
225 |
+tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv, |
226 |
+ bool sort, depend_atom *query) |
227 |
{ |
228 |
tree_cat_ctx *cat_ctx; |
229 |
tree_pkg_ctx *pkg_ctx; |
230 |
@@ -1283,18 +1325,12 @@ tree_foreach_pkg(tree_ctx *ctx, |
231 |
|
232 |
/* handle Packages (binpkgs index) file separately */ |
233 |
if (ctx->cachetype == CACHE_PACKAGES) |
234 |
- return tree_foreach_packages(ctx, callback, priv); |
235 |
+ return tree_foreach_packages(ctx, callback, priv, query); |
236 |
|
237 |
ctx->do_sort = sort; |
238 |
- if (catsortfunc != NULL) |
239 |
- ctx->catsortfunc = catsortfunc; |
240 |
- if (pkgsortfunc != NULL) |
241 |
- ctx->pkgsortfunc = pkgsortfunc; |
242 |
|
243 |
ret = 0; |
244 |
while ((cat_ctx = tree_next_cat(ctx))) { |
245 |
- if (filter && !filter(cat_ctx, priv)) |
246 |
- continue; |
247 |
while ((pkg_ctx = tree_next_pkg(cat_ctx))) { |
248 |
ret |= callback(pkg_ctx, priv); |
249 |
tree_close_pkg(pkg_ctx); |
250 |
@@ -1319,6 +1355,7 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete) |
251 |
tree_ctx *ctx = pkg_ctx->cat_ctx->ctx; |
252 |
if (ctx->cachetype == CACHE_VDB) { |
253 |
if (pkg_ctx->atom->SLOT == NULL) { |
254 |
+ /* FIXME: use tree_meta_get !!! */ |
255 |
if (pkg_ctx->slot == NULL) |
256 |
tree_pkg_vdb_eat(pkg_ctx, "SLOT", |
257 |
&pkg_ctx->slot, &pkg_ctx->slot_len); |
258 |
|
259 |
diff --git a/libq/tree.h b/libq/tree.h |
260 |
index 8a37cbb..eb60296 100644 |
261 |
--- a/libq/tree.h |
262 |
+++ b/libq/tree.h |
263 |
@@ -1,5 +1,5 @@ |
264 |
/* |
265 |
- * Copyright 2005-2019 Gentoo Foundation |
266 |
+ * Copyright 2005-2020 Gentoo Foundation |
267 |
* Distributed under the terms of the GNU General Public License v2 |
268 |
*/ |
269 |
|
270 |
@@ -27,8 +27,6 @@ struct tree_ctx { |
271 |
struct dirent **cat_de; |
272 |
size_t cat_cnt; |
273 |
size_t cat_cur; |
274 |
- void *catsortfunc; |
275 |
- void *pkgsortfunc; |
276 |
bool do_sort:1; |
277 |
enum { |
278 |
CACHE_UNSET = 0, |
279 |
@@ -45,6 +43,7 @@ struct tree_ctx { |
280 |
char *repo; |
281 |
char *pkgs; |
282 |
size_t pkgslen; |
283 |
+ depend_atom *query_atom; |
284 |
}; |
285 |
|
286 |
/* Category context */ |
287 |
@@ -110,9 +109,8 @@ struct tree_metadata_xml { |
288 |
} *email; |
289 |
}; |
290 |
|
291 |
-/* Global helpers */ |
292 |
+/* foreach pkg callback function signature */ |
293 |
typedef int (tree_pkg_cb)(tree_pkg_ctx *, void *priv); |
294 |
-typedef int (tree_cat_filter)(tree_cat_ctx *, void *priv); |
295 |
|
296 |
tree_ctx *tree_open(const char *sroot, const char *portdir); |
297 |
tree_ctx *tree_open_vdb(const char *sroot, const char *svdb); |
298 |
@@ -140,13 +138,12 @@ char *tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *ke |
299 |
tree_metadata_xml *tree_pkg_metadata(tree_pkg_ctx *pkg_ctx); |
300 |
void tree_close_metadata(tree_metadata_xml *meta_ctx); |
301 |
void tree_close_pkg(tree_pkg_ctx *pkg_ctx); |
302 |
-int tree_foreach_pkg(tree_ctx *ctx, |
303 |
- tree_pkg_cb callback, void *priv, tree_cat_filter filter, |
304 |
- bool sort, void *catsortfunc, void *pkgsortfunc); |
305 |
-#define tree_foreach_pkg_fast(ctx, cb, priv, filter) \ |
306 |
- tree_foreach_pkg(ctx, cb, priv, filter, false, NULL, NULL); |
307 |
-#define tree_foreach_pkg_sorted(ctx, cb, priv) \ |
308 |
- tree_foreach_pkg(ctx, cb, priv, NULL, true, NULL, NULL); |
309 |
+int tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv, |
310 |
+ bool sort, depend_atom *query); |
311 |
+#define tree_foreach_pkg_fast(ctx, cb, priv, query) \ |
312 |
+ tree_foreach_pkg(ctx, cb, priv, false, query); |
313 |
+#define tree_foreach_pkg_sorted(ctx, cb, priv, query) \ |
314 |
+ tree_foreach_pkg(ctx, cb, priv, true, query); |
315 |
struct dirent *tree_get_next_dir(DIR *dir); |
316 |
set *tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms); |
317 |
depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete); |
318 |
|
319 |
diff --git a/qcheck.c b/qcheck.c |
320 |
index ab4356b..66a4ee7 100644 |
321 |
--- a/qcheck.c |
322 |
+++ b/qcheck.c |
323 |
@@ -1,5 +1,5 @@ |
324 |
/* |
325 |
- * Copyright 2005-2019 Gentoo Foundation |
326 |
+ * Copyright 2005-2020 Gentoo Foundation |
327 |
* Distributed under the terms of the GNU General Public License v2 |
328 |
* |
329 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
330 |
@@ -434,7 +434,7 @@ int qcheck_main(int argc, char **argv) |
331 |
vdb = tree_open_vdb(portroot, portvdb); |
332 |
ret = -1; |
333 |
if (vdb != NULL) { |
334 |
- ret = tree_foreach_pkg_sorted(vdb, qcheck_cb, &state); |
335 |
+ ret = tree_foreach_pkg_sorted(vdb, qcheck_cb, &state, NULL); |
336 |
tree_close(vdb); |
337 |
} |
338 |
if (array_cnt(regex_arr) > 0) { |
339 |
|
340 |
diff --git a/qdepends.c b/qdepends.c |
341 |
index 9969d90..44821b6 100644 |
342 |
--- a/qdepends.c |
343 |
+++ b/qdepends.c |
344 |
@@ -1,5 +1,5 @@ |
345 |
/* |
346 |
- * Copyright 2005-2019 Gentoo Authors |
347 |
+ * Copyright 2005-2020 Gentoo Authors |
348 |
* Distributed under the terms of the GNU General Public License v2 |
349 |
* |
350 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
351 |
@@ -376,7 +376,7 @@ int qdepends_main(int argc, char **argv) |
352 |
t = tree_open(portroot, overlay); |
353 |
if (t != NULL) { |
354 |
ret = tree_foreach_pkg_sorted(t, |
355 |
- qdepends_results_cb, &state); |
356 |
+ qdepends_results_cb, &state, NULL); |
357 |
tree_close(t); |
358 |
} |
359 |
} |
360 |
|
361 |
diff --git a/qfile.c b/qfile.c |
362 |
index b1aab8d..0b01061 100644 |
363 |
--- a/qfile.c |
364 |
+++ b/qfile.c |
365 |
@@ -1,5 +1,5 @@ |
366 |
/* |
367 |
- * Copyright 2005-2019 Gentoo Foundation |
368 |
+ * Copyright 2005-2020 Gentoo Foundation |
369 |
* Distributed under the terms of the GNU General Public License v2 |
370 |
* |
371 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
372 |
@@ -569,7 +569,7 @@ int qfile_main(int argc, char **argv) |
373 |
if (nb_of_queries > 0) { |
374 |
tree_ctx *vdb = tree_open_vdb(portroot, portvdb); |
375 |
if (vdb != NULL) { |
376 |
- found += tree_foreach_pkg_sorted(vdb, qfile_cb, &state); |
377 |
+ found += tree_foreach_pkg_sorted(vdb, qfile_cb, &state, NULL); |
378 |
tree_close(vdb); |
379 |
} |
380 |
} |
381 |
|
382 |
diff --git a/qkeyword.c b/qkeyword.c |
383 |
index 70f75de..f777960 100644 |
384 |
--- a/qkeyword.c |
385 |
+++ b/qkeyword.c |
386 |
@@ -1,5 +1,5 @@ |
387 |
/* |
388 |
- * Copyright 2005-2019 Gentoo Foundation |
389 |
+ * Copyright 2005-2020 Gentoo Foundation |
390 |
* Distributed under the terms of the GNU General Public License v2 |
391 |
* |
392 |
* Copyright 2006 Thomas A. Cort - <tcort@g.o> |
393 |
@@ -799,7 +799,7 @@ qkeyword_traverse(tree_pkg_cb func, void *priv) |
394 |
array_for_each(overlays, n, overlay) { |
395 |
tree_ctx *t = tree_open(portroot, overlay); |
396 |
if (t != NULL) { |
397 |
- ret |= tree_foreach_pkg_sorted(t, qkeyword_results_cb, priv); |
398 |
+ ret |= tree_foreach_pkg_sorted(t, qkeyword_results_cb, priv, NULL); |
399 |
tree_close(t); |
400 |
} |
401 |
} |
402 |
|
403 |
diff --git a/qlist.c b/qlist.c |
404 |
index f77eaea..12d63f8 100644 |
405 |
--- a/qlist.c |
406 |
+++ b/qlist.c |
407 |
@@ -494,7 +494,7 @@ int qlist_main(int argc, char **argv) |
408 |
else |
409 |
vdb = tree_open_vdb(portroot, portvdb); |
410 |
if (vdb != NULL) { |
411 |
- ret = tree_foreach_pkg_sorted(vdb, qlist_cb, &state); |
412 |
+ ret = tree_foreach_pkg_sorted(vdb, qlist_cb, &state, NULL); |
413 |
tree_close(vdb); |
414 |
} |
415 |
free(state.buf); |
416 |
|
417 |
diff --git a/qmerge.c b/qmerge.c |
418 |
index a2d06ab..6d9439f 100644 |
419 |
--- a/qmerge.c |
420 |
+++ b/qmerge.c |
421 |
@@ -1,5 +1,5 @@ |
422 |
/* |
423 |
- * Copyright 2005-2019 Gentoo Authors |
424 |
+ * Copyright 2005-2020 Gentoo Authors |
425 |
* Distributed under the terms of the GNU General Public License v2 |
426 |
* |
427 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
428 |
@@ -272,37 +272,15 @@ qmerge_initialize(void) |
429 |
free(buf); |
430 |
} |
431 |
|
432 |
-struct qmerge_bv_state { |
433 |
- const char *catname; |
434 |
- const char *pkgname; |
435 |
- const char *slot; |
436 |
- char buf[4096]; |
437 |
- char *retbuf; |
438 |
-}; |
439 |
- |
440 |
-static int |
441 |
-qmerge_filter_cat(tree_cat_ctx *cat_ctx, void *priv) |
442 |
-{ |
443 |
- struct qmerge_bv_state *state = priv; |
444 |
- return !state->catname || strcmp(cat_ctx->name, state->catname) == 0; |
445 |
-} |
446 |
- |
447 |
-/* HACK: pull this in, knowing that qlist will be in the final link, we |
448 |
- * should however figure out how to do what match does here from e.g. |
449 |
- * atom */ |
450 |
-extern bool qlist_match( |
451 |
- tree_pkg_ctx *pkg_ctx, |
452 |
- const char *name, |
453 |
- depend_atom **name_atom, |
454 |
- bool exact); |
455 |
- |
456 |
+static char _best_version_retbuf[4096]; |
457 |
static int |
458 |
qmerge_best_version_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
459 |
{ |
460 |
- struct qmerge_bv_state *state = priv; |
461 |
- if (qlist_match(pkg_ctx, state->buf, NULL, true)) |
462 |
- snprintf(state->retbuf, sizeof(state->buf), "%s/%s:%s", |
463 |
- pkg_ctx->cat_ctx->name, pkg_ctx->name, state->slot); |
464 |
+ depend_atom *sa = priv; |
465 |
+ depend_atom *a = tree_get_atom(pkg_ctx, true); /* need SLOT */ |
466 |
+ if (atom_compare(a, sa) == EQUAL) |
467 |
+ snprintf(_best_version_retbuf, sizeof(_best_version_retbuf), |
468 |
+ "%s/%s:%s", a->CATEGORY, a->PF, a->SLOT); |
469 |
return 0; |
470 |
} |
471 |
|
472 |
@@ -310,15 +288,7 @@ static char * |
473 |
best_version(const char *catname, const char *pkgname, const char *slot) |
474 |
{ |
475 |
static int vdb_check = 1; |
476 |
- static char retbuf[4096]; |
477 |
- |
478 |
tree_ctx *vdb; |
479 |
- struct qmerge_bv_state state = { |
480 |
- .catname = catname, |
481 |
- .pkgname = pkgname, |
482 |
- .slot = slot, |
483 |
- .retbuf = retbuf, |
484 |
- }; |
485 |
|
486 |
/* Make sure these dirs exist before we try walking them */ |
487 |
switch (vdb_check) { |
488 |
@@ -336,18 +306,18 @@ best_version(const char *catname, const char *pkgname, const char *slot) |
489 |
goto done; |
490 |
} |
491 |
|
492 |
- retbuf[0] = '\0'; |
493 |
- snprintf(state.buf, sizeof(state.buf), "%s%s%s:%s", |
494 |
- catname ? : "", catname ? "/" : "", pkgname, slot); |
495 |
+ snprintf(_best_version_retbuf, sizeof(_best_version_retbuf), |
496 |
+ "%s%s%s:%s", catname ? : "", catname ? "/" : "", pkgname, slot); |
497 |
vdb = tree_open_vdb(portroot, portvdb); |
498 |
if (vdb != NULL) { |
499 |
- tree_foreach_pkg_fast(vdb, |
500 |
- qmerge_best_version_cb, &state, qmerge_filter_cat); |
501 |
+ depend_atom *sa = atom_explode(_best_version_retbuf); |
502 |
+ tree_foreach_pkg_fast(vdb, qmerge_best_version_cb, sa, sa); |
503 |
tree_close(vdb); |
504 |
+ atom_implode(sa); |
505 |
} |
506 |
|
507 |
done: |
508 |
- return retbuf; |
509 |
+ return _best_version_retbuf; |
510 |
} |
511 |
|
512 |
static int |
513 |
@@ -1810,6 +1780,15 @@ print_Pkg(int full, const depend_atom *atom, const struct pkg_t *pkg) |
514 |
} |
515 |
} |
516 |
|
517 |
+/* HACK: pull this in, knowing that qlist will be in the final link, we |
518 |
+ * should however figure out how to do what match does here from e.g. |
519 |
+ * atom */ |
520 |
+extern bool qlist_match( |
521 |
+ tree_pkg_ctx *pkg_ctx, |
522 |
+ const char *name, |
523 |
+ depend_atom **name_atom, |
524 |
+ bool exact); |
525 |
+ |
526 |
static int |
527 |
qmerge_unmerge_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
528 |
{ |
529 |
|
530 |
diff --git a/qsearch.c b/qsearch.c |
531 |
index a26e2d6..31b183c 100644 |
532 |
--- a/qsearch.c |
533 |
+++ b/qsearch.c |
534 |
@@ -1,5 +1,5 @@ |
535 |
/* |
536 |
- * Copyright 2005-2019 Gentoo Authors |
537 |
+ * Copyright 2005-2020 Gentoo Authors |
538 |
* Distributed under the terms of the GNU General Public License v2 |
539 |
* |
540 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
541 |
@@ -174,7 +174,7 @@ int qsearch_main(int argc, char **argv) |
542 |
array_for_each(overlays, n, overlay) { |
543 |
tree_ctx *t = tree_open(portroot, overlay); |
544 |
if (t != NULL) { |
545 |
- ret |= tree_foreach_pkg_sorted(t, qsearch_cb, &state); |
546 |
+ ret |= tree_foreach_pkg_sorted(t, qsearch_cb, &state, NULL); |
547 |
tree_close(t); |
548 |
} |
549 |
} |
550 |
|
551 |
diff --git a/quse.c b/quse.c |
552 |
index be34e48..a8585be 100644 |
553 |
--- a/quse.c |
554 |
+++ b/quse.c |
555 |
@@ -1,5 +1,5 @@ |
556 |
/* |
557 |
- * Copyright 2005-2019 Gentoo Foundation |
558 |
+ * Copyright 2005-2020 Gentoo Foundation |
559 |
* Distributed under the terms of the GNU General Public License v2 |
560 |
* |
561 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
562 |
@@ -719,14 +719,14 @@ int quse_main(int argc, char **argv) |
563 |
} else if (state.do_installed) { |
564 |
tree_ctx *t = tree_open_vdb(portroot, portvdb); |
565 |
state.overlay = NULL; |
566 |
- tree_foreach_pkg_sorted(t, quse_results_cb, &state); |
567 |
+ tree_foreach_pkg_sorted(t, quse_results_cb, &state, NULL); |
568 |
tree_close(t); |
569 |
} else { |
570 |
array_for_each(overlays, n, overlay) { |
571 |
tree_ctx *t = tree_open(portroot, overlay); |
572 |
state.overlay = overlay; |
573 |
if (t != NULL) { |
574 |
- tree_foreach_pkg_sorted(t, quse_results_cb, &state); |
575 |
+ tree_foreach_pkg_sorted(t, quse_results_cb, &state, NULL); |
576 |
tree_close(t); |
577 |
} |
578 |
} |