>From 16591c99329e0d0e83d45f148f82a471934e670d Mon Sep 17 00:00:00 2001
From: Justin Lampley <jrlampley@gmail.com>
Date: Tue, 13 Nov 2007 23:52:27 -0500
Subject: [PATCH] Add a configuration option to allow displaying of
 the old package version number during --sync and
 --query modes.

Signed-off-by: Justin Lampley <jrlampley@gmail.com>
---
 doc/pacman.conf.5.txt |    3 +++
 src/pacman/conf.h     |    1 +
 src/pacman/pacman.c   |    3 +++
 src/pacman/util.c     |   36 +++++++++++++++++++++++++-----------
 4 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index 2a0f88a..2e69055 100644
--- a/doc/pacman.conf.5.txt
+++ b/doc/pacman.conf.5.txt
@@ -118,6 +118,9 @@ Options
 	and completed percentage of the entire download list list rather
 	than the percent of each individual download target. The progress
 	bar is still based solely on the current file download.
+	
+*ShowOldVersion*::
+	Display the old package version number for '\--sync' and '\--query' modes.
 
 Repository Sections
 -------------------
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index b7844d7..5600305 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -68,6 +68,7 @@ typedef struct __config_t {
 	unsigned short totaldownload; /* When downloading, display the amount
 	                                 downloaded, rate, ETA, and percent
 	                                 downloaded of the total download list */
+	unsigned short showoldversion; /* when upgrading, show old package version */
 } config_t;
 
 /* Operations */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 31d31da..82e5b93 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -586,6 +586,9 @@ static int _parseconfig(const char *file, const char *givensection,
 				} else if(strcmp(key, "ShowSize") == 0 || strcmp(upperkey, "SHOWSIZE") == 0) {
 					config->showsize = 1;
 					pm_printf(PM_LOG_DEBUG, "config: showsize\n");
+				} else if(strcmp(key, "ShowOldVersion") == 0 || strcmp(upperkey, "SHOWOLDVERSION") == 0) {
+					config->showoldversion = 1;
+					pm_printf(PM_LOG_DEBUG, "config: showoldversion\n");
 				} else if(strcmp(key, "UseDelta") == 0 || strcmp(upperkey, "USEDELTA") == 0) {
 					alpm_option_set_usedelta(1);
 					pm_printf(PM_LOG_DEBUG, "config: usedelta\n");
diff --git a/src/pacman/util.c b/src/pacman/util.c
index a0402ab..6ab85d7 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -364,7 +364,7 @@ void list_display(const char *title, const alpm_list_t *list)
 /* TODO move to output.c? or just combine util and output */
 void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local)
 {
-	char *str;
+	char *str, *tmpstr, *version;
 	const alpm_list_t *i, *j;
 	alpm_list_t *targets = NULL, *to_remove = NULL;
 	/* TODO these are some messy variable names */
@@ -374,7 +374,8 @@ void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local)
 	for(i = syncpkgs; i; i = alpm_list_next(i)) {
 		pmsyncpkg_t *sync = alpm_list_getdata(i);
 		pmpkg_t *pkg = alpm_sync_get_pkg(sync);
-
+		pmpkg_t *oldpkg = alpm_sync_get_data(sync);
+		
 		/* If this sync record is a replacement, the data member contains
 		 * a list of packages to be removed due to the package that is being
 		 * installed. */
@@ -396,17 +397,30 @@ void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local)
 		dlsize += alpm_pkg_download_size(pkg, db_local);
 		isize += alpm_pkg_get_isize(pkg);
 
-		/* print the package size with the output if ShowSize option set */
-		if(config->showsize) {
-			/* Convert byte size to MB */
-			mbdispsize = dispsize / (1024.0 * 1024.0);
+		asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
 
-			asprintf(&str, "%s-%s [%.2f MB]", alpm_pkg_get_name(pkg),
-					alpm_pkg_get_version(pkg), mbdispsize);
-		} else {
-			asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg),
-					alpm_pkg_get_version(pkg));
+		/* print the old packages version number */
+		if(config->showoldversion) {
+			version = alpm_pkg_get_version(oldpkg);
+			/* we assume it is a new package if the old package is null or ""*/
+			if (version == NULL || strcmp(version,"") == 0)
+				asprintf(&tmpstr, " [%s]","New");
+			else
+				asprintf(&tmpstr, " [%s]",version);
+			
+			_strnadd(&str, tmpstr, strlen(tmpstr));
+			free(tmpstr);
 		}
+ 		/* print the package size with the output if ShowSize option set */
+ 		if(config->showsize) {
+ 			/* Convert byte size to MB */
+ 			mbdispsize = dispsize / (1024.0 * 1024.0);
+ 
+			asprintf(&tmpstr, " [%.2f MB]", mbdispsize);
+			_strnadd(&str, tmpstr, strlen(tmpstr));
+			free(tmpstr);
+ 		} 
+ 		
 		targets = alpm_list_add(targets, str);
 	}
 
-- 
1.5.3.5

