From 8e736e1c9a4fb4ba375fe1f02be9e956f5f472d9 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Sun, 12 Aug 2012 21:03:04 +1000 Subject: Display install status of optdependencies When a packages (new) optdepends are printed in install (update), add a note of their current installation status. Packages currently installed are labelled with [installed] and packages to be installed in this transaction are labelled [pending]. Signed-off-by: Allan McRae --- src/pacman/util.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 5ed450ec..78cdf264 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1200,6 +1200,22 @@ static int depend_cmp(const void *d1, const void *d2) return ret; } +static char *make_optstring(alpm_depend_t *optdep) +{ + char *optstring = alpm_dep_compute_string(optdep); + char *status = NULL; + if(alpm_db_get_pkg(alpm_get_localdb(config->handle), optdep->name)) { + status = _(" [installed]"); + } else if(alpm_pkg_find(alpm_trans_get_add(config->handle), optdep->name)) { + status = _(" [pending]"); + } + if(status) { + optstring = realloc(optstring, strlen(optstring) + strlen(status) + 1); + strcpy(optstring + strlen(optstring), status); + } + return optstring; +} + void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg) { alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL; @@ -1211,7 +1227,7 @@ void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg) /* turn optdepends list into a text list */ for(i = optdeps; i; i = alpm_list_next(i)) { alpm_depend_t *optdep = i->data; - optstrings = alpm_list_add(optstrings, alpm_dep_compute_string(optdep)); + optstrings = alpm_list_add(optstrings, make_optstring(optdep)); } if(optstrings) { @@ -1233,7 +1249,7 @@ void display_optdepends(alpm_pkg_t *pkg) /* turn optdepends list into a text list */ for(i = optdeps; i; i = alpm_list_next(i)) { alpm_depend_t *optdep = i->data; - optstrings = alpm_list_add(optstrings, alpm_dep_compute_string(optdep)); + optstrings = alpm_list_add(optstrings, make_optstring(optdep)); } if(optstrings) { -- cgit v1.2.3