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/, /
Date: Sun, 19 Jan 2020 09:49:48
Message-Id: 1579427330.16215c71c61da9cb44868d58b4c3ce0529c5d4ac.grobian@gentoo
1 commit: 16215c71c61da9cb44868d58b4c3ce0529c5d4ac
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jan 19 09:48:50 2020 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Sun Jan 19 09:48:50 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=16215c71
7
8 qatom: add -l option to match an atom against the tree
9
10 returns the latest available version of the atom requested, or nothing
11 when not found
12
13 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
14
15 man/qatom.1 | 5 ++++-
16 qatom.c | 33 +++++++++++++++++++++++++++------
17 2 files changed, 31 insertions(+), 7 deletions(-)
18
19 diff --git a/man/qatom.1 b/man/qatom.1
20 index 6254912..4f6ccf2 100644
21 --- a/man/qatom.1
22 +++ b/man/qatom.1
23 @@ -1,5 +1,5 @@
24 .\" generated by mkman.py, please do NOT edit!
25 -.TH qatom "1" "Nov 2019" "Gentoo Foundation" "qatom"
26 +.TH qatom "1" "Jan 2020" "Gentoo Foundation" "qatom"
27 .SH NAME
28 qatom \- split atom strings
29 .SH SYNOPSIS
30 @@ -70,6 +70,9 @@ Compare two atoms.
31 \fB\-p\fR, \fB\-\-print\fR
32 Print reconstructed atom.
33 .TP
34 +\fB\-l\fR, \fB\-\-lookup\fR
35 +Lookup atom in tree.
36 +.TP
37 \fB\-\-root\fR \fI<arg>\fR
38 Set the ROOT env var.
39 .TP
40
41 diff --git a/qatom.c b/qatom.c
42 index 23d10d8..59f7392 100644
43 --- a/qatom.c
44 +++ b/qatom.c
45 @@ -8,36 +8,37 @@
46 */
47
48 #include "main.h"
49 -
50 -#include <stdlib.h>
51 -#include <stdbool.h>
52 +#include "applets.h"
53
54 #include "atom.h"
55 -#include "applets.h"
56 +#include "tree.h"
57
58 #define QATOM_FORMAT "%{CATEGORY} %{PN} %{PV} %[PR] %[SLOT] %[pfx] %[sfx]"
59
60 -#define QATOM_FLAGS "F:cp" COMMON_FLAGS
61 +#define QATOM_FLAGS "F:cpl" COMMON_FLAGS
62 static struct option const qatom_long_opts[] = {
63 {"format", a_argument, NULL, 'F'},
64 {"compare", no_argument, NULL, 'c'},
65 {"print", no_argument, NULL, 'p'},
66 + {"lookup", no_argument, NULL, 'l'},
67 COMMON_LONG_OPTS
68 };
69 static const char * const qatom_opts_help[] = {
70 "Custom output format (default: " QATOM_FORMAT ")",
71 "Compare two atoms",
72 "Print reconstructed atom",
73 + "Lookup atom in tree",
74 COMMON_OPTS_HELP
75 };
76 #define qatom_usage(ret) usage(ret, QATOM_FLAGS, qatom_long_opts, qatom_opts_help, NULL, lookup_applet_idx("qatom"))
77
78 int qatom_main(int argc, char **argv)
79 {
80 - enum qatom_atom { _EXPLODE=0, _COMPARE, _PRINT } action = _EXPLODE;
81 + enum qatom_atom { _EXPLODE=0, _COMPARE, _PRINT, _LOOKUP } action = _EXPLODE;
82 const char *format = QATOM_FORMAT;
83 depend_atom *atom;
84 depend_atom *atomc;
85 + tree_ctx *tree = NULL;
86 int i;
87
88 while ((i = GETOPT_LONG(QATOM, qatom, "")) != -1) {
89 @@ -45,6 +46,7 @@ int qatom_main(int argc, char **argv)
90 case 'F': format = optarg; break;
91 case 'c': action = _COMPARE; break;
92 case 'p': action = _PRINT; break;
93 + case 'l': action = _LOOKUP; break;
94 COMMON_GETOPTS_CASES(qatom)
95 }
96 }
97 @@ -55,6 +57,12 @@ int qatom_main(int argc, char **argv)
98 if (action == _COMPARE && (argc - optind) % 2)
99 err("compare needs even number of arguments");
100
101 + if (action == _LOOKUP) {
102 + tree = tree_open(portroot, main_overlay);
103 + if (tree == NULL)
104 + err("failed to open tree");
105 + }
106 +
107 for (i = optind; i < argc; i++) {
108 atom = atom_explode(argv[i]);
109 if (atom == NULL) {
110 @@ -101,10 +109,23 @@ int qatom_main(int argc, char **argv)
111 case _PRINT:
112 printf("%s\n", atom_to_string(atom));
113 break;
114 + case _LOOKUP:
115 + {
116 + tree_pkg_ctx *pkg = tree_match_atom(tree, atom);
117 + if (pkg != NULL) {
118 + atomc = tree_get_atom(pkg, true);
119 + if (!quiet)
120 + printf("%s: ", atom_to_string(atom));
121 + printf("%s\n", atom_format(format, atomc));
122 + }
123 + }
124 }
125
126 atom_implode(atom);
127 }
128
129 + if (action == _LOOKUP)
130 + tree_close(tree);
131 +
132 return EXIT_SUCCESS;
133 }