[pacman-dev] [PATCH 03/14] Only display uninstalled optdepends during install/upgrade

Benedikt Morbach benedikt.morbach at googlemail.com
Wed Nov 23 10:51:17 EST 2011


Signed-off-by: Benedikt Morbach <benedikt.morbach at googlemail.com>
---
 src/pacman/util.c            |   40 ++++++++++++++++++++++++++--------------
 test/pacman/tests/sync060.py |   12 ++++++++++++
 test/pacman/tests/sync061.py |   15 +++++++++++++++
 3 files changed, 53 insertions(+), 14 deletions(-)
 create mode 100644 test/pacman/tests/sync060.py
 create mode 100644 test/pacman/tests/sync061.py

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 2363e6f..be4647a 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1173,19 +1173,37 @@ 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 = alpm_option_get_localdb(config->handle);
+
+	/* turn optdepends list into a text list. */
+	for( ; optlist; optlist = alpm_list_next(optlist)) {
+		optdep = optlist->data;
+		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 = i->data;
-		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));
@@ -1198,15 +1216,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 = i->data;
-		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));
diff --git a/test/pacman/tests/sync060.py b/test/pacman/tests/sync060.py
new file mode 100644
index 0000000..ec3d7ca
--- /dev/null
+++ b/test/pacman/tests/sync060.py
@@ -0,0 +1,12 @@
+self.description = "Install a package from a sync db with uninstalled optdepend and optdepend output"
+
+pkg = pmpkg("dummy")
+pkg.optdepends = ["dep: for foobar"]
+self.addpkg2db("sync1", pkg)
+
+self.args = "-S %s" % pkg.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_OUTPUT=dep: for foobar")
+self.addrule("PKG_EXISTS=dummy")
+self.addrule("PKG_OPTDEPENDS=dummy|dep: for foobar")
diff --git a/test/pacman/tests/sync061.py b/test/pacman/tests/sync061.py
new file mode 100644
index 0000000..cb5a892
--- /dev/null
+++ b/test/pacman/tests/sync061.py
@@ -0,0 +1,15 @@
+self.description = "Install a package from a sync db with installed optdepend and no optdepend output"
+
+p1 = pmpkg("dummy")
+p1.optdepends = ["dep: for foobar"]
+self.addpkg2db("sync1", p1)
+
+p2 = pmpkg("dep")
+self.addpkg2db("local", p2)
+
+self.args = "-S %s" % p1.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("!PACMAN_OUTPUT=dep: for foobar")
+self.addrule("PKG_EXISTS=dummy")
+self.addrule("PKG_OPTDEPENDS=dummy|dep: for foobar")
-- 
1.7.7.3



More information about the pacman-dev mailing list