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 7B5D91382C5 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 BCDF2E084A; Sat, 20 Feb 2021 11:44:48 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 83787E084A 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 57F72340FEB 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 E306C4C6 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: <1613818601.b8c3bbcde2425b2b6160c1fc865eeebe705417c2.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qwhich.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: b8c3bbcde2425b2b6160c1fc865eeebe705417c2 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: bccad322-b71e-4c4e-8c4e-a2be473d07a4 X-Archives-Hash: 8fded39dfdfb3e7c4d74c9a9b442c2ea commit: b8c3bbcde2425b2b6160c1fc865eeebe705417c2 Author: Fabian Groffen gentoo org> AuthorDate: Sat Feb 20 10:56:41 2021 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sat Feb 20 10:56:41 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b8c3bbcd qwhich: add option for latest version match, print ebuild for vdb matches - add -l to match latest version per package, e.g. query for dash would return both app-shells/dash as well as app-emacs/dash - for vdb matches, return the path to the (cached) ebuild in there, unless -d is given, of course, then print path Signed-off-by: Fabian Groffen gentoo.org> qwhich.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/qwhich.c b/qwhich.c index 3a0c791..b55b6e4 100644 --- a/qwhich.c +++ b/qwhich.c @@ -19,7 +19,7 @@ #include "atom.h" #include "tree.h" -#define QWHICH_FLAGS "IbtpdfF:" COMMON_FLAGS +#define QWHICH_FLAGS "IbtpdflF:" COMMON_FLAGS static struct option const qwhich_long_opts[] = { {"vdb", no_argument, NULL, 'I'}, {"binpkg", no_argument, NULL, 'b'}, @@ -27,6 +27,7 @@ static struct option const qwhich_long_opts[] = { {"pretty", no_argument, NULL, 'p'}, {"dir", no_argument, NULL, 'd'}, {"first", no_argument, NULL, 'f'}, + {"latest", no_argument, NULL, 'l'}, {"format", a_argument, NULL, 'F'}, COMMON_LONG_OPTS }; @@ -36,7 +37,8 @@ static const char * const qwhich_opts_help[] = { "Look in main tree and overlays", "Print (pretty) atom instead of path for use with -F", "Print directory instead of path", - "Stop searching after first match", + "Stop searching after first match (implies -l)", + "Only return latest version for each match", "Print matched using given format string", COMMON_OPTS_HELP }; @@ -51,6 +53,7 @@ struct qwhich_mode { char print_atom:1; char print_path:1; char match_first:1; + char match_latest:1; const char *fmt; }; @@ -76,28 +79,29 @@ int qwhich_main(int argc, char **argv) switch (ret) { COMMON_GETOPTS_CASES(qwhich) - case 'I': m.do_vdb = true; break; - case 'b': m.do_binpkg = true; break; - case 't': m.do_tree = true; break; - case 'p': m.print_atom = true; break; - case 'd': m.print_path = true; break; - case 'f': m.match_first = true; break; - case 'F': m.fmt = optarg; break; + case 'I': m.do_vdb = true; break; + case 'b': m.do_binpkg = true; break; + case 't': m.do_tree = true; break; + case 'p': m.print_atom = true; break; + case 'd': m.print_path = true; break; + case 'f': m.match_first = true; break; + case 'l': m.match_latest = true; break; + case 'F': m.fmt = optarg; break; } } - /* defaults: no options at all, enable first match, + /* defaults: no options at all, enable latest match, * no selectors, enable tree + overlays */ if (!m.do_vdb && !m.do_binpkg && !m.do_tree) { if (!m.print_atom && !m.print_path && !m.match_first && m.fmt == NULL) - m.match_first = true; + m.match_latest = true; m.do_tree = true; } /* when printing path, we better just match the first, else we get a * lot of dups */ - if (m.print_path) - m.match_first = true; + if (m.print_path || m.match_first) + m.match_latest = true; /* set format if none given */ if (m.fmt == NULL) { @@ -150,8 +154,9 @@ int qwhich_main(int argc, char **argv) repolen = 0; array_for_each(atoms, i, atom) { - tmc = tree_match_atom(t, atom, - m.match_first ? TREE_MATCH_FIRST : TREE_MATCH_DEFAULT); + tmc = tree_match_atom(t, atom, TREE_MATCH_DEFAULT | + (m.match_latest ? TREE_MATCH_LATEST : 0) | + (m.match_first ? TREE_MATCH_FIRST : 0)); for (tmcw = tmc; tmcw != NULL; tmcw = tmcw->next) { if (m.print_atom) { printf("%s\n", atom_format(m.fmt, tmcw->atom)); @@ -172,6 +177,11 @@ int qwhich_main(int argc, char **argv) DKBLUE, tmcw->atom->PN, BLUE, tmcw->atom->P, DKGREEN, NORM); + } else if (t->cachetype == CACHE_VDB && !m.print_path) { + printf("%s%s/%s%s%s.ebuild%s\n", + DKBLUE, tmcw->path, + BLUE, tmcw->atom->P, + DKGREEN, NORM); } else { printf("%s%s%s\n", DKBLUE, tmcw->path, NORM); }