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 478931382C5 for ; Sat, 20 Feb 2021 11:44:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7D374E0863; Sat, 20 Feb 2021 11:44:51 +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 6492BE0863 for ; Sat, 20 Feb 2021 11:44:51 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (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 29032340FCC for ; Sat, 20 Feb 2021 11:44:50 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 01D184E9 for ; Sat, 20 Feb 2021 11:44:46 +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: <1613821411.d71bb2b7a1360ea49cb1e4d02fec15f9a9c18422.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: d71bb2b7a1360ea49cb1e4d02fec15f9a9c18422 X-VCS-Branch: master Date: Sat, 20 Feb 2021 11:44:46 +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: dd4b330e-78d7-4e37-a11a-681024919def X-Archives-Hash: 72538efc19d0811f126dd38c0641b407 commit: d71bb2b7a1360ea49cb1e4d02fec15f9a9c18422 Author: Fabian Groffen gentoo org> AuthorDate: Sat Feb 20 11:43:31 2021 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sat Feb 20 11:43:31 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d71bb2b7 qwhich: allow shortening paths by using repo name e.g. return something like: gentoo::app-shells/dash/dash-X.Y.ebuild (repo lookup can be performed through q -o) Signed-off-by: Fabian Groffen gentoo.org> qwhich.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/qwhich.c b/qwhich.c index b55b6e4..2119466 100644 --- a/qwhich.c +++ b/qwhich.c @@ -19,13 +19,14 @@ #include "atom.h" #include "tree.h" -#define QWHICH_FLAGS "IbtpdflF:" COMMON_FLAGS +#define QWHICH_FLAGS "IbtpdRflF:" COMMON_FLAGS static struct option const qwhich_long_opts[] = { {"vdb", no_argument, NULL, 'I'}, {"binpkg", no_argument, NULL, 'b'}, {"tree", no_argument, NULL, 't'}, {"pretty", no_argument, NULL, 'p'}, {"dir", no_argument, NULL, 'd'}, + {"repo", no_argument, NULL, 'R'}, {"first", no_argument, NULL, 'f'}, {"latest", no_argument, NULL, 'l'}, {"format", a_argument, NULL, 'F'}, @@ -37,6 +38,7 @@ 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", + "Print repository name instead of path for tree/overlay matches", "Stop searching after first match (implies -l)", "Only return latest version for each match", "Print matched using given format string", @@ -52,6 +54,7 @@ struct qwhich_mode { char do_tree:1; char print_atom:1; char print_path:1; + char print_repo:1; char match_first:1; char match_latest:1; const char *fmt; @@ -71,6 +74,7 @@ int qwhich_main(int argc, char **argv) size_t n; int ret; tree_ctx *t; + char *repo; int repolen; memset(&m, 0, sizeof(m)); @@ -84,6 +88,7 @@ int qwhich_main(int argc, char **argv) case 't': m.do_tree = true; break; case 'p': m.print_atom = true; break; case 'd': m.print_path = true; break; + case 'R': m.print_repo = true; break; case 'f': m.match_first = true; break; case 'l': m.match_latest = true; break; case 'F': m.fmt = optarg; break; @@ -146,12 +151,20 @@ int qwhich_main(int argc, char **argv) /* at least keep the IO constrained to a tree at a time */ array_for_each(trees, j, t) { - if (t->cachetype == CACHE_METADATA_MD5) - repolen = strlen(t->path) - (sizeof("/metadata/md5-cache") - 1); - else if (t->cachetype == CACHE_METADATA_PMS) - repolen = strlen(t->path) - (sizeof("/metadata/cache") - 1); - else - repolen = 0; + if (m.print_repo) { + repo = t->repo; + repolen = strlen(repo); + } else { + repo = t->path; + if (t->cachetype == CACHE_METADATA_MD5) + repolen = strlen(t->path) - (sizeof("/metadata/md5-cache") - 1); + else if (t->cachetype == CACHE_METADATA_PMS) + repolen = strlen(t->path) - (sizeof("/metadata/cache") - 1); + else if (t->cachetype == CACHE_EBUILD) + repolen = strlen(t->path); + else + repolen = 0; + } array_for_each(atoms, i, atom) { tmc = tree_match_atom(t, atom, TREE_MATCH_DEFAULT | @@ -162,17 +175,20 @@ int qwhich_main(int argc, char **argv) printf("%s\n", atom_format(m.fmt, tmcw->atom)); } else { if (t->cachetype == CACHE_METADATA_MD5 || - t->cachetype == CACHE_METADATA_PMS) + t->cachetype == CACHE_METADATA_PMS || + t->cachetype == CACHE_EBUILD) { if (m.print_path) - printf("%s%.*s/%s%s/%s%s%s\n", - GREEN, repolen, t->path, + printf("%s%.*s%s%s%s/%s%s%s\n", + GREEN, repolen, repo, + m.print_repo ? "::" : "/", BOLD, tmcw->atom->CATEGORY, DKBLUE, tmcw->atom->PN, NORM); else - printf("%s%.*s/%s%s/%s%s/%s%s%s.ebuild%s\n", - DKGREEN, repolen, t->path, + printf("%s%.*s%s%s%s/%s%s/%s%s%s.ebuild%s\n", + DKGREEN, repolen, repo, + m.print_repo ? "::" : "/", BOLD, tmcw->atom->CATEGORY, DKBLUE, tmcw->atom->PN, BLUE, tmcw->atom->P,