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 <[email protected]>
---

I went a different way to previous patches that altered this.  They
all did not display installed optdependencies, but I prefer showing
them by default.  Later there may be an option added to install all
optdepends by default and in that case the output can be removed.


Example output:

> sudo ./src/pacman/pacman -S git perl-term-readkey
Password: 
resolving dependencies...
looking for inter-conflicts...

Packages (2): git-1.7.11.4-1  perl-term-readkey-2.30.02-2

Total Installed Size:   16.79 MiB

Proceed with installation? [Y/n] 
(2/2) checking package integrity                   [######################] 100%
(2/2) loading package files                        [######################] 100%
(2/2) checking for file conflicts                  [######################] 100%
(1/2) installing git                               [######################] 100%
Optional dependencies for git
    tk: gitk and git gui [installed]
    perl-libwww: git svn
    perl-term-readkey: git svn [pending]
    perl-mime-tools: git send-email
    perl-net-smtp-ssl: git send-email TLS support
    perl-authen-sasl: git send-email TLS support
    python2: various helper scripts [installed]
    subversion: git svn [installed]
    cvsps: git cvsimport
(2/2) installing perl-term-readkey                 [######################] 100%


 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 995308c..4d8727f 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1192,6 +1192,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;
@@ -1203,7 +1219,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) {
@@ -1225,7 +1241,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) {
-- 
1.7.11.4


Reply via email to