From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 8BE9813835A for ; Sat, 20 Feb 2021 11:44:49 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C23DEE085E; Sat, 20 Feb 2021 11:44:48 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 47851E084A for ; Sat, 20 Feb 2021 11:44:48 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4BC96340FCC for ; Sat, 20 Feb 2021 11:44:47 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CF502487 for ; Sat, 20 Feb 2021 11:44:45 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1613818445.90de2c63f3d0d7e546265b02227b96b01dba24f7.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/tree.c libq/tree.h X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 90de2c63f3d0d7e546265b02227b96b01dba24f7 X-VCS-Branch: master Date: Sat, 20 Feb 2021 11:44:45 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: d3d3acc0-f969-4e16-b88c-92db7fda8f59 X-Archives-Hash: b0fb868743f520d6602ad57d01d1ffc6 commit: 90de2c63f3d0d7e546265b02227b96b01dba24f7 Author: Fabian Groffen gentoo org> AuthorDate: Sat Feb 20 10:54:05 2021 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sat Feb 20 10:54:05 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=90de2c63 libq/tree: add ability to match latest version per package in tree_match_atom Allow retrieving the latest version per package matching the input atom. E.g. a search for dash would return both app-shells/dash as well as app-emacs/dash using LATEST, while FIRST would only return the app-emacs one (or whichever came first while traversing). Signed-off-by: Fabian Groffen gentoo.org> libq/tree.c | 42 ++++++++++++++++++++++++++---------------- libq/tree.h | 9 +++++---- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/libq/tree.c b/libq/tree.c index 293d7f7..df52171 100644 --- a/libq/tree.c +++ b/libq/tree.c @@ -1728,26 +1728,36 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int flags) #define search_cat(C) \ { \ + char *lastpn = NULL; \ while ((pkg_ctx = tree_next_pkg(C)) != NULL) { \ atom = tree_get_atom(pkg_ctx, \ query->SLOT != NULL || flags & TREE_MATCH_FULL_ATOM); \ - if (flags & TREE_MATCH_VIRTUAL || \ - strcmp(atom->CATEGORY, "virtual") != 0) { \ - if (atom_compare(atom, query) == EQUAL) { \ - tree_match_ctx *n = xzalloc(sizeof(tree_match_ctx)); \ - n->atom = atom; \ - snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \ - (char *)C->ctx->path, C->name, pkg_ctx->name, \ - C->ctx->cachetype == CACHE_EBUILD ? ".ebuild" : \ - C->ctx->cachetype == CACHE_BINPKGS ? ".tbz2" : ""); \ - if (flags & TREE_MATCH_METADATA) \ - n->meta = tree_pkg_read(pkg_ctx); \ - n->next = ret; \ - ret = n; \ - } \ - if (flags & TREE_MATCH_FIRST && ret != NULL) \ - break; \ + /* skip virtual/ package as requested */ \ + if (!(flags & TREE_MATCH_VIRTUAL || \ + strcmp(atom->CATEGORY, "virtual") != 0)) \ + continue; \ + /* see if this atom matches the query */ \ + if (atom_compare(atom, query) == EQUAL) { \ + tree_match_ctx *n; \ + /* skip over additional versions for match latest */ \ + if (flags & TREE_MATCH_LATEST && lastpn != NULL && \ + strcmp(lastpn, atom->PN) == 0) \ + continue; \ + /* create a new match result */ \ + n = xzalloc(sizeof(tree_match_ctx)); \ + n->atom = atom; \ + snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \ + (char *)C->ctx->path, C->name, pkg_ctx->name, \ + C->ctx->cachetype == CACHE_EBUILD ? ".ebuild" : \ + C->ctx->cachetype == CACHE_BINPKGS ? ".tbz2" : ""); \ + if (flags & TREE_MATCH_METADATA) \ + n->meta = tree_pkg_read(pkg_ctx); \ + n->next = ret; \ + ret = n; \ } \ + lastpn = atom->PN; \ + if (flags & TREE_MATCH_FIRST && ret != NULL) \ + break; \ } \ C->pkg_cur = 0; /* reset to allow another traversal */ \ } diff --git a/libq/tree.h b/libq/tree.h index f756fd4..53fee67 100644 --- a/libq/tree.h +++ b/libq/tree.h @@ -155,10 +155,11 @@ int tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv, set *tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms); depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete); tree_match_ctx *tree_match_atom(tree_ctx *t, depend_atom *q, int flags); -#define TREE_MATCH_FULL_ATOM 1<<1 -#define TREE_MATCH_METADATA 1<<2 -#define TREE_MATCH_FIRST 1<<3 -#define TREE_MATCH_VIRTUAL 1<<4 +#define TREE_MATCH_FULL_ATOM (1<<1) +#define TREE_MATCH_METADATA (1<<2) +#define TREE_MATCH_LATEST (1<<3) +#define TREE_MATCH_VIRTUAL (1<<4) +#define TREE_MATCH_FIRST (1<<5) #define TREE_MATCH_DEFAULT TREE_MATCH_VIRTUAL void tree_match_close(tree_match_ctx *t);