Skip to content

Commit 7b50923

Browse files
committed
query: add %y and %Y for provides/requires
1 parent b4966fd commit 7b50923

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

docs/pkg-query.8

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ available, or
146146
otherwise.
147147
.It Cm \&%X
148148
Internal package checksum
149-
.It Cm \&%\&? Ns Op drCFODLUGBbA
149+
.It Cm \&%\&? Ns Op drCFODLUGBbAyY
150150
Returns 0 if the list is empty and 1 if the list has information to display.
151151
.Bl -tag -width indent
152152
.It Cm d
@@ -171,10 +171,14 @@ for groups
171171
for required shared libraries
172172
.It Cm b
173173
for provided shared libraries
174+
.It Cm y
175+
for provides
176+
.It Cm Y
177+
for requires
174178
.It Cm A
175179
for annotations
176180
.El
177-
.It Cm \&%# Ns Op drCFODLUGBbA
181+
.It Cm \&%# Ns Op drCFODLUGBbAyY
178182
Returns the number of elements in the list
179183
.Bl -tag -width indent
180184
.It Cm d
@@ -199,6 +203,10 @@ for groups
199203
for required shared libraries
200204
.It Cm b
201205
for provided shared libraries
206+
.It Cm y
207+
for provides
208+
.It Cm Y
209+
for requires
202210
.It Cm A
203211
for annotations
204212
.El
@@ -279,6 +287,10 @@ Expands to the list of groups needed by the matched package.
279287
Expands to the list of shared libraries used by programs from the matched package.
280288
.It Cm \&%b
281289
Expands to the list of shared libraries provided by the matched package.
290+
.It Cm \&%y
291+
Expands to the list of provides for the matched package.
292+
.It Cm \&%Y
293+
Expands to the list of requires for the matched package.
282294
.It Cm \&%A Ns Op tv
283295
Expands to the list of annotations for the matched package,
284296
where
@@ -330,7 +342,7 @@ Message of the package (type string)
330342
Timestamp that the package was installed (type integer)
331343
.It Cm \&%i
332344
Additional information about the package (type string)
333-
.It Cm \&%# Ns Op drCFODLUGBbA
345+
.It Cm \&%# Ns Op drCFODLUGBbAyY
334346
Number of elements in the list of information (type integer).
335347
See
336348
.Cm %?
@@ -362,6 +374,10 @@ License of the package (type string)
362374
Required shared library of the package (type string)
363375
.It Cm \&%b
364376
Provided shared library of the package (type string)
377+
.It Cm \&%y
378+
Provide of the package (type string)
379+
.It Cm \&%Y
380+
Require of the package (type string)
365381
.It Cm \&%A Ns Op tv
366382
Annotation of the package (type string)
367383
.El

src/query.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ static const struct query_flags accepted_query_flags[] = {
5454
{ 'G', "", 1, PKG_LOAD_GROUPS },
5555
{ 'B', "", 1, PKG_LOAD_SHLIBS_REQUIRED },
5656
{ 'b', "", 1, PKG_LOAD_SHLIBS_PROVIDED },
57+
{ 'y', "", 1, PKG_LOAD_PROVIDES },
58+
{ 'Y', "", 1, PKG_LOAD_REQUIRES },
5759
{ 'A', "tv", 1, PKG_LOAD_ANNOTATIONS },
58-
{ '?', "drCFODLUGBbA", 1, PKG_LOAD_BASIC }, /* dbflags handled in analyse_query_string() */
59-
{ '#', "drCFODLUGBbA", 1, PKG_LOAD_BASIC }, /* dbflags handled in analyse_query_string() */
60+
{ '?', "drCFODLUGBbAyY", 1, PKG_LOAD_BASIC }, /* dbflags handled in analyse_query_string() */
61+
{ '#', "drCFODLUGBbAyY", 1, PKG_LOAD_BASIC }, /* dbflags handled in analyse_query_string() */
6062
{ 's', "hb", 0, PKG_LOAD_BASIC },
6163
{ 'Q', "", 0, PKG_LOAD_BASIC },
6264
{ 'n', "", 0, PKG_LOAD_BASIC },
@@ -173,6 +175,12 @@ format_str(struct pkg *pkg, xstring *dest, const char *qstr, const void *data)
173175
case 'b':
174176
pkg_fprintf(dest->fp, "%?b", pkg);
175177
break;
178+
case 'y':
179+
pkg_fprintf(dest->fp, "%?y", pkg);
180+
break;
181+
case 'Y':
182+
pkg_fprintf(dest->fp, "%?Y", pkg);
183+
break;
176184
case 'A':
177185
pkg_fprintf(dest->fp, "%?A", pkg);
178186
break;
@@ -214,6 +222,12 @@ format_str(struct pkg *pkg, xstring *dest, const char *qstr, const void *data)
214222
case 'b':
215223
pkg_fprintf(dest->fp, "%#b", pkg);
216224
break;
225+
case 'y':
226+
pkg_fprintf(dest->fp, "%#y", pkg);
227+
break;
228+
case 'Y':
229+
pkg_fprintf(dest->fp, "%#Y", pkg);
230+
break;
217231
case 'A':
218232
pkg_fprintf(dest->fp, "%#A", pkg);
219233
break;
@@ -310,6 +324,12 @@ format_str(struct pkg *pkg, xstring *dest, const char *qstr, const void *data)
310324
case 'b':
311325
pkg_fprintf(dest->fp, "%bn", data);
312326
break;
327+
case 'y':
328+
fprintf(dest->fp, "%s", (const char *)data);
329+
break;
330+
case 'Y':
331+
fprintf(dest->fp, "%s", (const char *)data);
332+
break;
313333
case 'A':
314334
qstr++;
315335
if (qstr[0] == 't')
@@ -403,7 +423,9 @@ print_query(struct pkg *pkg, char *qstr, char multiline)
403423
case 'U':
404424
case 'G':
405425
case 'B':
406-
case 'b':;
426+
case 'b':
427+
case 'y':
428+
case 'Y':;
407429
int attr;
408430
switch (multiline) {
409431
case 'C': attr = PKG_ATTR_CATEGORIES; break;
@@ -412,6 +434,8 @@ print_query(struct pkg *pkg, char *qstr, char multiline)
412434
case 'G': attr = PKG_ATTR_GROUPS; break;
413435
case 'B': attr = PKG_ATTR_SHLIBS_REQUIRED; break;
414436
case 'b': attr = PKG_ATTR_SHLIBS_PROVIDED; break;
437+
case 'y': attr = PKG_ATTR_PROVIDES; break;
438+
case 'Y': attr = PKG_ATTR_REQUIRES; break;
415439
default: __unreachable();
416440
}
417441
pkg_get(pkg, attr, &sl);
@@ -612,6 +636,12 @@ format_sql_condition(const char *str, xstring *sqlcond, bool for_remote)
612636
case 'b':
613637
fprintf(sqlcond->fp, "(SELECT %s FROM pkg_shlibs_provided AS d WHERE d.package_id=p.id)", sqlop);
614638
break;
639+
case 'y':
640+
fprintf(sqlcond->fp, "(SELECT %s FROM pkg_provides AS d WHERE d.package_id=p.id)", sqlop);
641+
break;
642+
case 'Y':
643+
fprintf(sqlcond->fp, "(SELECT %s FROM pkg_requires AS d WHERE d.package_id=p.id)", sqlop);
644+
break;
615645
case 'A':
616646
fprintf(sqlcond->fp, "(SELECT %s FROM pkg_annotation AS d WHERE d.package_id=p.id)", sqlop);
617647
break;
@@ -662,6 +692,16 @@ format_sql_condition(const char *str, xstring *sqlcond, bool for_remote)
662692
multiline_subquery = true;
663693
state = OPERATOR_STRING;
664694
break;
695+
case 'y':
696+
pending_subquery = "SELECT * FROM provides AS s JOIN pkg_provides AS ps ON s.id=ps.provide_id WHERE ps.package_id=p.id AND s.provide";
697+
multiline_subquery = true;
698+
state = OPERATOR_STRING;
699+
break;
700+
case 'Y':
701+
pending_subquery = "SELECT * FROM requires AS s JOIN pkg_requires AS ps ON s.id=ps.require_id WHERE ps.package_id=p.id AND s.require";
702+
multiline_subquery = true;
703+
state = OPERATOR_STRING;
704+
break;
665705
case 'A':
666706
str++;
667707
if (str[0] == 't')

0 commit comments

Comments
 (0)