[pacman-dev] [PATCH v2 3/6] Only display uninstalled optdepends during install/upgrade

Benedikt Morbach benedikt.morbach at googlemail.com
Mon Jul 25 16:31:11 EDT 2011


Signed-off-by: Benedikt Morbach <benedikt.morbach at googlemail.com>
---
 src/pacman/util.c |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index ca1646c..dc21d30 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1008,19 +1008,39 @@ 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));
@@ -1033,15 +1053,11 @@ 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 *optdeps, *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(optdeps);
 
 	if(optstrings) {
 		printf(_("Optional dependencies for %s\n"), alpm_pkg_get_name(pkg));
-- 
1.7.6



More information about the pacman-dev mailing list