Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
query: add %y and %Y for provides/requires
Baptiste Daroussin committed 1 month ago
commit 7b50923b44a44116b8db96181462e6d53acec88a
parent b4966fd
2 files changed +62 -6
modified docs/pkg-query.8
@@ -146,7 +146,7 @@ available, or
otherwise.
.It Cm \&%X
Internal package checksum
-
.It Cm \&%\&? Ns Op drCFODLUGBbA
+
.It Cm \&%\&? Ns Op drCFODLUGBbAyY
Returns 0 if the list is empty and 1 if the list has information to display.
.Bl -tag -width indent
.It Cm d
@@ -171,10 +171,14 @@ for groups
for required shared libraries
.It Cm b
for provided shared libraries
+
.It Cm y
+
for provides
+
.It Cm Y
+
for requires
.It Cm A
for annotations
.El
-
.It Cm \&%# Ns Op drCFODLUGBbA
+
.It Cm \&%# Ns Op drCFODLUGBbAyY
Returns the number of elements in the list
.Bl -tag -width indent
.It Cm d
@@ -199,6 +203,10 @@ for groups
for required shared libraries
.It Cm b
for provided shared libraries
+
.It Cm y
+
for provides
+
.It Cm Y
+
for requires
.It Cm A
for annotations
.El
@@ -279,6 +287,10 @@ Expands to the list of groups needed by the matched package.
Expands to the list of shared libraries used by programs from the matched package.
.It Cm \&%b
Expands to the list of shared libraries provided by the matched package.
+
.It Cm \&%y
+
Expands to the list of provides for the matched package.
+
.It Cm \&%Y
+
Expands to the list of requires for the matched package.
.It Cm \&%A Ns Op tv
Expands to the list of annotations for the matched package,
where
@@ -330,7 +342,7 @@ Message of the package (type string)
Timestamp that the package was installed (type integer)
.It Cm \&%i
Additional information about the package (type string)
-
.It Cm \&%# Ns Op drCFODLUGBbA
+
.It Cm \&%# Ns Op drCFODLUGBbAyY
Number of elements in the list of information (type integer).
See
.Cm %?
@@ -362,6 +374,10 @@ License of the package (type string)
Required shared library of the package (type string)
.It Cm \&%b
Provided shared library of the package (type string)
+
.It Cm \&%y
+
Provide of the package (type string)
+
.It Cm \&%Y
+
Require of the package (type string)
.It Cm \&%A Ns Op tv
Annotation of the package (type string)
.El
modified src/query.c
@@ -54,9 +54,11 @@ static const struct query_flags accepted_query_flags[] = {
	{ 'G', "",		1, PKG_LOAD_GROUPS },
	{ 'B', "",		1, PKG_LOAD_SHLIBS_REQUIRED },
	{ 'b', "",		1, PKG_LOAD_SHLIBS_PROVIDED },
+
	{ 'y', "",		1, PKG_LOAD_PROVIDES },
+
	{ 'Y', "",		1, PKG_LOAD_REQUIRES },
	{ 'A', "tv",            1, PKG_LOAD_ANNOTATIONS },
-
	{ '?', "drCFODLUGBbA",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
-
	{ '#', "drCFODLUGBbA",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
+
	{ '?', "drCFODLUGBbAyY",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
+
	{ '#', "drCFODLUGBbAyY",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
	{ 's', "hb",		0, PKG_LOAD_BASIC },
	{ 'Q', "",		0, PKG_LOAD_BASIC },
	{ 'n', "",		0, PKG_LOAD_BASIC },
@@ -173,6 +175,12 @@ format_str(struct pkg *pkg, xstring *dest, const char *qstr, const void *data)
				case 'b':
					pkg_fprintf(dest->fp, "%?b", pkg);
					break;
+
				case 'y':
+
					pkg_fprintf(dest->fp, "%?y", pkg);
+
					break;
+
				case 'Y':
+
					pkg_fprintf(dest->fp, "%?Y", pkg);
+
					break;
				case 'A':
					pkg_fprintf(dest->fp, "%?A", pkg);
					break;
@@ -214,6 +222,12 @@ format_str(struct pkg *pkg, xstring *dest, const char *qstr, const void *data)
				case 'b':
					pkg_fprintf(dest->fp, "%#b", pkg);
					break;
+
				case 'y':
+
					pkg_fprintf(dest->fp, "%#y", pkg);
+
					break;
+
				case 'Y':
+
					pkg_fprintf(dest->fp, "%#Y", pkg);
+
					break;
				case 'A':
					pkg_fprintf(dest->fp, "%#A", pkg);
					break;
@@ -310,6 +324,12 @@ format_str(struct pkg *pkg, xstring *dest, const char *qstr, const void *data)
			case 'b':
				pkg_fprintf(dest->fp, "%bn", data);
				break;
+
			case 'y':
+
				fprintf(dest->fp, "%s", (const char *)data);
+
				break;
+
			case 'Y':
+
				fprintf(dest->fp, "%s", (const char *)data);
+
				break;
			case 'A':
				qstr++;
				if (qstr[0] == 't')
@@ -403,7 +423,9 @@ print_query(struct pkg *pkg, char *qstr, char multiline)
	case 'U':
	case 'G':
	case 'B':
-
	case 'b':;
+
	case 'b':
+
	case 'y':
+
	case 'Y':;
		int attr;
		switch (multiline) {
		case 'C': attr = PKG_ATTR_CATEGORIES; break;
@@ -412,6 +434,8 @@ print_query(struct pkg *pkg, char *qstr, char multiline)
		case 'G': attr = PKG_ATTR_GROUPS; break;
		case 'B': attr = PKG_ATTR_SHLIBS_REQUIRED; break;
		case 'b': attr = PKG_ATTR_SHLIBS_PROVIDED; break;
+
		case 'y': attr = PKG_ATTR_PROVIDES; break;
+
		case 'Y': attr = PKG_ATTR_REQUIRES; break;
		default: __unreachable();
		}
		pkg_get(pkg, attr, &sl);
@@ -612,6 +636,12 @@ format_sql_condition(const char *str, xstring *sqlcond, bool for_remote)
						case 'b':
							fprintf(sqlcond->fp, "(SELECT %s FROM pkg_shlibs_provided AS d WHERE d.package_id=p.id)", sqlop);
							break;
+
						case 'y':
+
							fprintf(sqlcond->fp, "(SELECT %s FROM pkg_provides AS d WHERE d.package_id=p.id)", sqlop);
+
							break;
+
						case 'Y':
+
							fprintf(sqlcond->fp, "(SELECT %s FROM pkg_requires AS d WHERE d.package_id=p.id)", sqlop);
+
							break;
						case 'A':
							fprintf(sqlcond->fp, "(SELECT %s FROM pkg_annotation AS d WHERE d.package_id=p.id)", sqlop);
							break;
@@ -662,6 +692,16 @@ format_sql_condition(const char *str, xstring *sqlcond, bool for_remote)
					multiline_subquery = true;
					state = OPERATOR_STRING;
					break;
+
				case 'y':
+
					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";
+
					multiline_subquery = true;
+
					state = OPERATOR_STRING;
+
					break;
+
				case 'Y':
+
					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";
+
					multiline_subquery = true;
+
					state = OPERATOR_STRING;
+
					break;
				case 'A':
					str++;
					if (str[0] == 't')