Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add remote repo support to pkg-version
Bryan Drewery committed 13 years ago
commit 3ad1dd63c3eb1c4620c79139f5533a4515b573d3
parent 0967c552196f18f19bf84c0d4623a27432ed0e81
3 files changed +38 -9
modified pkg/pkg-version.8
@@ -23,7 +23,7 @@
.Nd summarize installed versions of packages
.Sh SYNOPSIS
.Nm
-
.Op Fl IP
+
.Op Fl IPR
.Op Fl hoqv
.Op Fl l Ar limchar
.Op Fl L Ar limchar
@@ -51,6 +51,8 @@ Use INDEX file for determining if a package is out of date.
.It Fl P
Use ports for determining if a package is out of date.
This is the default.
+
.It Fl R
+
Use repository catalogue for determining if a package is out of date.
.It Fl o
Display package origin, instead of package name.
.It Fl q
modified pkg/pkgcli.h
@@ -138,6 +138,7 @@ void usage_shell(void);
#define VERSION_TESTVERSION	(1<<8)
#define VERSION_TESTPATTERN	(1<<9)
#define VERSION_SOURCE_PORTS	(1<<10)
+
#define VERSION_SOURCE_REMOTE	(1<<11)

int exec_version(int, char **);
void usage_version(void);
modified pkg/version.c
@@ -55,7 +55,7 @@ struct index_entry {
void
usage_version(void)
{
-
	fprintf(stderr, "usage: pkg version [-IP] [-hoqv] [-l limchar] [-L limchar] [[-X] -s string]\n");
+
	fprintf(stderr, "usage: pkg version [-IPR] [-hoqv] [-l limchar] [-L limchar] [[-X] -s string]\n");
	fprintf(stderr, "                   [-O origin] [index]\n");
	fprintf(stderr, "       pkg version -t <version1> <version2>\n");
	fprintf(stderr, "       pkg version -T <pkgname> <pattern>\n\n");
@@ -149,20 +149,22 @@ exec_version(int argc, char **argv)
	char *version;
	struct index_entry *entry;
	struct pkgdb *db = NULL;
-
	struct pkg *pkg = NULL;
-
	struct pkgdb_it *it = NULL;
+
	struct pkg *pkg = NULL, *pkg_remote = NULL;
+
	struct pkgdb_it *it = NULL, *it_remote = NULL;
	char limchar = '-';
	struct sbuf *cmd;
	struct sbuf *res;
	const char *portsdir;
-
	const char *origin;
+
	const char *origin, *origin_remote;
	const char *matchorigin = NULL;
+
	const char *reponame = NULL;
+
	const char *version_remote = NULL;
	match_t match = MATCH_ALL;
	char *pattern=NULL;

	SLIST_INIT(&indexhead);

-
	while ((ch = getopt(argc, argv, "hIPoqvl:L:X:x:g:e:O:tT")) != -1) {
+
	while ((ch = getopt(argc, argv, "hIPRoqvl:L:X:x:g:e:O:tT")) != -1) {
		switch (ch) {
		case 'h':
			usage_version();
@@ -170,6 +172,9 @@ exec_version(int argc, char **argv)
		case 'I':
			opt |= VERSION_SOURCE_INDEX;
			break;
+
		case 'R':
+
			opt |= VERSION_SOURCE_REMOTE;
+
			break;
		case 'P':
			opt |= VERSION_SOURCE_PORTS;
			break;
@@ -283,9 +288,15 @@ exec_version(int argc, char **argv)
		
		return (retval);
		
-
	} else if ((opt & (VERSION_SOURCE_INDEX|VERSION_SOURCE_PORTS)) != 0) {
-
		if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
-
			return (EX_IOERR);
+
	} else if ((opt & (VERSION_SOURCE_INDEX|VERSION_SOURCE_REMOTE|VERSION_SOURCE_PORTS)) != 0) {
+
		/* Only force remote mode if looking up remote, otherwise
+
		   user is forced to have a repo.sqlite */
+
		if (opt & VERSION_SOURCE_REMOTE) {
+
			if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK)
+
				return (EX_IOERR);
+
		} else
+
			if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
+
				return (EX_IOERR);

		if ((it = pkgdb_query(db, pattern, match)) == NULL)
			goto cleanup;
@@ -324,6 +335,9 @@ exec_version(int argc, char **argv)
			}
			free(line);
			fclose(indexfile);
+
		} else if (opt & VERSION_SOURCE_REMOTE) {
+
			if ((it_remote = pkgdb_rquery(db, pattern, match, reponame)) == NULL)
+
				return (EX_IOERR);
		}

		while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) {
@@ -360,6 +374,16 @@ exec_version(int argc, char **argv)
					print_version(pkg, NULL, NULL, limchar, opt);
				}
				sbuf_delete(cmd);
+
			} else if (opt & VERSION_SOURCE_REMOTE) {
+
				while ((pkgdb_it_next(it_remote, &pkg_remote, PKG_LOAD_BASIC)) == EPKG_OK) {
+
					pkg_get(pkg_remote, PKG_ORIGIN, &origin_remote);
+

+
					if (strcmp(origin_remote, origin) == 0) {
+
						pkg_get(pkg_remote, PKG_VERSION, &version_remote);
+
						print_version(pkg, "remote", version_remote, limchar, opt);
+
						break;
+
					}
+
				}
			}
		}
	}
@@ -374,7 +398,9 @@ cleanup:
	}

	pkg_free(pkg);
+
	pkg_free(pkg_remote);
	pkgdb_it_free(it);
+
	pkgdb_it_free(it_remote);
	pkgdb_close(db);

	return (EX_OK);