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: /
Date: Sat, 11 May 2019 07:14:53
Message-Id: 1557512518.569ce6581ce8823e9a827d22a2326351017835c0.grobian@gentoo
1 commit: 569ce6581ce8823e9a827d22a2326351017835c0
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Fri May 10 18:21:58 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Fri May 10 18:21:58 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=569ce658
7
8 qlist: use tree_get_atom where possible
9
10 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
11
12 qlist.c | 52 ++++++++++++++--------------------------------------
13 1 file changed, 14 insertions(+), 38 deletions(-)
14
15 diff --git a/qlist.c b/qlist.c
16 index abefbcf..32c87b4 100644
17 --- a/qlist.c
18 +++ b/qlist.c
19 @@ -193,24 +193,19 @@ qlist_match(
20 const char *urepo;
21 size_t urepo_len = 0;
22 depend_atom *atom;
23 + depend_atom *_atom = NULL;
24
25 uslot = strchr(name, ':');
26 - if (uslot) {
27 + if (uslot != NULL) {
28 if (*++uslot == ':')
29 uslot = NULL;
30 else {
31 - if (!pkg_ctx->slot)
32 - tree_pkg_vdb_eat(pkg_ctx, "SLOT", &pkg_ctx->slot,
33 - &pkg_ctx->slot_len);
34 uslot_len = strlen(uslot);
35 }
36 }
37
38 urepo = strstr(name, "::");
39 - if (urepo) {
40 - if (!pkg_ctx->repo)
41 - tree_pkg_vdb_eat(pkg_ctx, "repository", &pkg_ctx->repo,
42 - &pkg_ctx->repo_len);
43 + if (urepo != NULL) {
44 urepo += 2;
45 urepo_len = strlen(urepo);
46
47 @@ -224,28 +219,18 @@ qlist_match(
48 case '>':
49 case '<':
50 case '~':
51 - snprintf(buf, sizeof(buf), "%s/%s%c%s%s%s", catname, pkgname,
52 - pkg_ctx->slot ? ':' : '\0', pkg_ctx->slot ? : "",
53 - pkg_ctx->repo ? "::" : "", pkg_ctx->repo ? : "");
54 - if ((atom = atom_explode(buf)) == NULL) {
55 - warn("invalid atom %s", buf);
56 - return false;
57 - }
58 + atom = tree_get_atom(pkg_ctx, uslot != NULL || urepo != NULL);
59
60 - depend_atom *_atom = NULL;
61 if (!name_atom)
62 name_atom = &_atom;
63 if (!*name_atom) {
64 if ((*name_atom = atom_explode(name)) == NULL) {
65 - atom_implode(atom);
66 warn("invalid atom %s", name);
67 return false;
68 }
69 }
70
71 - bool ret = atom_compare(atom, *name_atom) == EQUAL;
72 - atom_implode(atom);
73 - return ret;
74 + return atom_compare(atom, *name_atom) == EQUAL;
75 }
76
77 if (uslot) {
78 @@ -277,10 +262,7 @@ qlist_match(
79 return true;
80
81 /* let's try exact matching w/out the PV */
82 - if ((atom = atom_explode(buf)) == NULL) {
83 - warn("invalid atom %s", buf);
84 - return false;
85 - }
86 + atom = tree_get_atom(pkg_ctx, uslot != NULL || urepo != NULL);
87
88 i = snprintf(swap, sizeof(swap), "%s/%s", atom->CATEGORY, atom->PN);
89 if (uslot && i <= (int)sizeof(swap))
90 @@ -288,7 +270,6 @@ qlist_match(
91 if (urepo && i <= (int)sizeof(swap))
92 i += snprintf(swap + i, sizeof(swap) - i, "::%s", atom->REPO);
93
94 - atom_implode(atom);
95 /* exact match: CAT/PN[:SLOT][::REPO] */
96 if (strcmp(name, swap) == 0)
97 return true;
98 @@ -345,6 +326,7 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv)
99 FILE *fp;
100 const char *catname = pkg_ctx->cat_ctx->name;
101 const char *pkgname = pkg_ctx->name;
102 + depend_atom *atom;
103
104 /* see if this cat/pkg is requested */
105 for (i = optind; i < state->argc; ++i)
106 @@ -354,23 +336,19 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv)
107 if ((i == state->argc) && (state->argc != optind))
108 return 0;
109
110 + atom = tree_get_atom(pkg_ctx, false);
111 if (state->just_pkgname) {
112 - depend_atom *atom;
113 - atom = (verbose ? NULL : atom_explode(pkgname));
114 if ((state->all + state->just_pkgname) < 2) {
115 + atom = tree_get_atom(pkg_ctx,
116 + state->show_slots || state->show_repo);
117 if (state->show_slots && !pkg_ctx->slot) {
118 - tree_pkg_vdb_eat(pkg_ctx, "SLOT",
119 - &pkg_ctx->slot, &pkg_ctx->slot_len);
120 /* chop off the subslot if desired */
121 - if (state->show_slots == 1) {
122 + if (state->show_slots == 1 && pkg_ctx->slot != NULL) {
123 char *s = strchr(pkg_ctx->slot, '/');
124 if (s)
125 *s = '\0';
126 }
127 }
128 - if (state->show_repo && !pkg_ctx->repo)
129 - tree_pkg_vdb_eat(pkg_ctx, "repository",
130 - &pkg_ctx->repo, &pkg_ctx->repo_len);
131 /* display it */
132 printf("%s%s/%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
133 BOLD, catname, BLUE,
134 @@ -387,16 +365,14 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv)
135 NORM,
136 umapstr(state->show_umap, pkg_ctx));
137 }
138 - if (atom)
139 - atom_implode(atom);
140
141 if (!state->all)
142 return 1;
143 }
144
145 if (verbose)
146 - printf("%s%s/%s%s%s %sCONTENTS%s:\n",
147 - BOLD, catname, BLUE, pkgname, NORM, DKBLUE, NORM);
148 + printf("%s %sCONTENTS%s:\n",
149 + atom_format("%[CATEGORY]%[PF]", atom, 0), DKBLUE, NORM);
150
151 fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS");
152 if (fp == NULL)
153 @@ -423,7 +399,7 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv)
154 break;
155 case CONTENTS_OBJ:
156 if (state->show_obj)
157 - printf("%s%s%s\n", WHITE, e->name, NORM);
158 + printf("%s%s%s\n", DKGREEN, e->name, NORM);
159 break;
160 case CONTENTS_SYM:
161 if (state->show_sym) {