[pacman-dev] [PATCH 12/15] Show status on optdepends that are part of transaction
Benedikt Morbach
benedikt.morbach at googlemail.com
Sun Sep 11 15:29:45 EDT 2011
Signed-off-by: Benedikt Morbach <benedikt.morbach at googlemail.com>
---
src/pacman/util.c | 40 ++++++++++++++++++++++++++--------------
1 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c
index afe6840..1f54f65 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1053,26 +1053,38 @@ alpm_list_t *optdep_string_list(const alpm_list_t *optlist, int include_installe
{
alpm_list_t *optstrings = NULL;
alpm_optdepend_t *optdep;
- alpm_db_t *db_local;
+ alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
- db_local = alpm_option_get_localdb(config->handle);
+ /* calculate these outside the loop. */
+ alpm_list_t *pkgcache = alpm_db_get_pkgcache(db_local);
+ alpm_list_t *remove = alpm_trans_get_remove(config->handle);
+ alpm_list_t *add = alpm_trans_get_add(config->handle);
- /* turn optdepends list into a text list */
+ /* turn optdepends list into a text list. */
for( ; optlist; optlist = alpm_list_next(optlist)) {
optdep = alpm_list_getdata(optlist);
- if(include_installed && alpm_db_get_pkg(db_local, optdep->depend->name)) {
- const char * const installed = _(" [installed]");
- char *str, *tmp;
- tmp = alpm_optdep_compute_string(optdep);
- if((str = realloc(tmp, strlen(tmp) + strlen(installed) + 1)) != NULL) {
- strcpy(str + strlen(str), installed);
- optstrings = alpm_list_add(optstrings, str);
- } else {
- free(tmp);
- }
+ char *depstr = alpm_dep_compute_string(optdep->depend);
+ char *tmp, *str = alpm_optdep_compute_string(optdep);
+ const char *state = NULL;
+
+ if(alpm_find_satisfier(pkgcache, depstr) && alpm_find_satisfier(remove, depstr) == NULL) {
+ state = include_installed ? _(" [installed]") : NULL;
+ } else if(alpm_find_satisfier(add, depstr)) {
+ state = include_installed ? _(" [installing]") : NULL;
+ } else if(alpm_find_satisfier(remove, depstr)) {
+ state = _(" [removing]");
} else {
- optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ optstrings = alpm_list_add(optstrings, str);
}
+
+ if(state) {
+ if((tmp = realloc(str, strlen(str) + strlen(state) + 1)) != NULL) {
+ strcpy(tmp + strlen(tmp), state);
+ str = tmp;
+ } /* if realloc fails, we only loose the state information, which is nonfatal. */
+ optstrings = alpm_list_add(optstrings, str);
+ }
+ free(depstr);
}
return optstrings;
}
--
1.7.6.1
More information about the pacman-dev
mailing list