[pacman-dev] [PATCH 03/15] Only display uninstalled optdepends during install/upgrade
Benedikt Morbach
benedikt.morbach at googlemail.com
Sun Sep 11 15:29:36 EDT 2011
Signed-off-by: Benedikt Morbach <benedikt.morbach at googlemail.com>
---
src/pacman/util.c | 42 ++++++++++++++++++++++++++++--------------
1 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c
index e8dd326..27121d3 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1030,19 +1030,39 @@ static int opt_cmp(const void *o1, const void *o2)
return ret;
}
+/** Creates a newly-allocated list of optdepend strings from a list of optdepends.
+ * The list must be freed!
+ * @param optlist an alpm_list_t of optdepends to turn into a strings
+ * @return an alpm_list_t of optdepend formatted strings with description
+ */
+alpm_list_t *optdep_string_list(const alpm_list_t *optlist)
+{
+ alpm_list_t *optstrings = NULL;
+ alpm_optdepend_t *optdep;
+ alpm_db_t *db_local;
+
+ db_local = alpm_option_get_localdb(config->handle);
+
+ /* turn optdepends list into a text list */
+ for( ; optlist; optlist = alpm_list_next(optlist)) {
+ optdep = alpm_list_getdata(optlist);
+ if(alpm_db_get_pkg(db_local, optdep->depend->name) == NULL) {
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+ }
+
+ return optstrings;
+}
+
void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
{
- alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
+ alpm_list_t *old, *new, *optdeps, *optstrings;
old = alpm_pkg_get_optdepends(oldpkg);
new = alpm_pkg_get_optdepends(newpkg);
optdeps = alpm_list_diff(new, old, opt_cmp);
- /* turn optdepends list into a text list */
- for(i = optdeps; i; i = alpm_list_next(i)) {
- alpm_optdepend_t *optdep = alpm_list_getdata(i);
- optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
- }
+ optstrings = optdep_string_list(optdeps);
if(optstrings) {
printf(_("New optional dependencies for %s\n"), alpm_pkg_get_name(newpkg));
@@ -1055,15 +1075,9 @@ void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
void display_optdepends(alpm_pkg_t *pkg)
{
- alpm_list_t *i, *optdeps, *optstrings = NULL;
+ alpm_list_t *optstrings;
- optdeps = alpm_pkg_get_optdepends(pkg);
-
- /* turn optdepends list into a text list */
- for(i = optdeps; i; i = alpm_list_next(i)) {
- alpm_optdepend_t *optdep = alpm_list_getdata(i);
- optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
- }
+ optstrings = optdep_string_list(alpm_pkg_get_optdepends(pkg));
if(optstrings) {
printf(_("Optional dependencies for %s\n"), alpm_pkg_get_name(pkg));
--
1.7.6.1
More information about the pacman-dev
mailing list