[pacman-dev] [PATCH] Add new --print operation.

Xavier Chantry shiningxc at gmail.com
Sun Jul 19 06:15:23 EDT 2009


This implements FS#14208

-S --print    : print package name and version
-S --print -q : print package name

Signed-off-by: Xavier Chantry <shiningxc at gmail.com>
---
 doc/pacman.8.txt    |    7 ++++++-
 src/pacman/conf.h   |    2 +-
 src/pacman/pacman.c |    7 ++++++-
 src/pacman/sync.c   |   29 +++++++++++++++++++----------
 src/pacman/util.c   |    2 +-
 5 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt
index ccff167..c12280c 100644
--- a/doc/pacman.8.txt
+++ b/doc/pacman.8.txt
@@ -301,6 +301,10 @@ linkman:pacman.conf[5].
 	List all packages in the specified repositories. Multiple repositories
 	can be specified on the command line.
 
+*\--print*::
+	Print out name/version for each package that will be installed, including
+	any dependencies yet to be installed.
+
 *-p, \--print-uris*::
 	Print out URIs for each package that will be installed, including any
 	dependencies yet to be installed. These can be piped to a file and
@@ -311,7 +315,8 @@ linkman:pacman.conf[5].
 	pacman's output is processed in a script.) Search will only show package
 	names and not repo, version, group, and description information; list
 	will only show package names and omit databases and versions; group will
-	only show package names and omit group names.
+	only show package names and omit group names; '\--print' will only
+	show package names.
 
 *-s, \--search* <'regexp'>::
 	This will search each package in the sync databases for names or
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 6523d49..c50981c 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -59,7 +59,7 @@ typedef struct __config_t {
 	unsigned short op_s_sync;
 	unsigned short op_s_search;
 	unsigned short op_s_upgrade;
-	unsigned short op_s_printuris;
+	unsigned short op_s_print;
 
 	unsigned short group;
 	pmtransflag_t flags;
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 48d45ad..a5514ef 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -128,6 +128,7 @@ static void usage(int op, const char * const myname)
 			printf(_("  -g, --groups         view all members of a package group\n"));
 			printf(_("  -i, --info           view package information\n"));
 			printf(_("  -l, --list <repo>    view a list of packages in a repo\n"));
+			printf(_("      --print          print out name/version for given packages and their dependencies\n"));
 			printf(_("  -p, --print-uris     print out URIs for given packages and their dependencies\n"));
 			printf(_("  -s, --search <regex> search remote repositories for matching strings\n"));
 			printf(_("  -u, --sysupgrade     upgrade all packages that are out of date\n"));
@@ -376,6 +377,7 @@ static int parseargs(int argc, char *argv[])
 		{"ignoregroup", required_argument, 0, 1010},
 		{"needed",     no_argument,       0, 1011},
 		{"asexplicit",     no_argument,   0, 1012},
+		{"print",      no_argument,       0, 1013},
 		{0, 0, 0, 0}
 	};
 
@@ -450,6 +452,9 @@ static int parseargs(int argc, char *argv[])
 			case 1012:
 				config->flags |= PM_TRANS_FLAG_ALLEXPLICIT;
 				break;
+			case 1013:
+				config->op_s_print = 1;
+				break;
 			case 'Q': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break;
 			case 'R': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_REMOVE); break;
 			case 'S': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_SYNC); break;
@@ -485,7 +490,7 @@ static int parseargs(int argc, char *argv[])
 			case 'o': config->op_q_owns = 1; break;
 			case 'p':
 				config->op_q_isfile = 1;
-				config->op_s_printuris = 1;
+				config->op_s_print = 2;
 				config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
 				config->flags |= PM_TRANS_FLAG_NOLOCK;
 				break;
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index cb0b8b1..c96b26a 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -671,19 +671,28 @@ static int sync_trans(alpm_list_t *targets)
 	}
 
 	/* Step 3: actually perform the operation */
-	if(config->op_s_printuris) {
+	if(config->op_s_print) {
 		/* print uris */
 		alpm_list_t *i;
 		for(i = packages; i; i = alpm_list_next(i)) {
 			pmpkg_t *pkg = alpm_list_getdata(i);
-			pmdb_t *db = alpm_pkg_get_db(pkg);
-			const char *dburl = alpm_db_get_url(db);
-			if(dburl) {
-				printf("%s/%s\n", dburl, alpm_pkg_get_filename(pkg));
+			const char *pkgname = alpm_pkg_get_name(pkg);
+			if(config->op_s_print == 2) {
+				pmdb_t *db = alpm_pkg_get_db(pkg);
+				const char *dburl = alpm_db_get_url(db);
+				if(dburl) {
+					printf("%s/%s\n", dburl, alpm_pkg_get_filename(pkg));
+				} else {
+					/* can't use WARNING here, we don't show warnings in -Sp... */
+					pm_fprintf(stderr, PM_LOG_ERROR, _("no database for package: %s\n"),
+							pkgname);
+				}
 			} else {
-				/* can't use WARNING here, we don't show warnings in -Sp... */
-				pm_fprintf(stderr, PM_LOG_ERROR, _("no database for package: %s\n"),
-						alpm_pkg_get_name(pkg));
+				if(!config->quiet) {
+					printf("%s %s\n", pkgname, alpm_pkg_get_version(pkg));
+				} else {
+					printf("%s\n", pkgname);
+				}
 			}
 
 		}
@@ -760,7 +769,7 @@ int pacman_sync(alpm_list_t *targets)
 	alpm_list_t *sync_dbs = NULL;
 
 	/* Display only errors with -Sp and -Sw operations */
-	if((config->flags & PM_TRANS_FLAG_DOWNLOADONLY) || config->op_s_printuris) {
+	if((config->flags & PM_TRANS_FLAG_DOWNLOADONLY) || config->op_s_print) {
 		config->logmask &= ~PM_LOG_WARNING;
 	}
 
@@ -833,7 +842,7 @@ int pacman_sync(alpm_list_t *targets)
 	}
 
 	alpm_list_t *targs = alpm_list_strdup(targets);
-	if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY) && !config->op_s_printuris) {
+	if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY) && !config->op_s_print) {
 		/* check for newer versions of packages to be upgraded first */
 		alpm_list_t *packages = syncfirst();
 		if(packages) {
diff --git a/src/pacman/util.c b/src/pacman/util.c
index a02b43c..1922b4f 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -75,7 +75,7 @@ int needs_root(void)
 	if(config->op == PM_OP_UPGRADE || config->op == PM_OP_REMOVE || /* -U, -R */
 	   (config->op == PM_OP_SYNC && (config->op_s_clean || config->op_s_sync || /* -Sc, -Sy */
 	      (!config->group && !config->op_s_info && !config->op_q_list /* all other -S combinations, where */
-	        && !config->op_s_search && !config->op_s_printuris)))) {  /* -g, -i, -l, -s, -p is not set */
+	        && !config->op_s_search && !config->op_s_print)))) {  /* -g, -i, -l, -s, -p is not set */
 		return(1);
 	} else {
 		return(0);
-- 
1.6.3.3



More information about the pacman-dev mailing list