[pacman-dev] [PATCH] Mark already installed optional dependencies

Arokux B. arokux at gmail.com
Thu Apr 5 19:49:54 EDT 2012


This patch adds "[installed]" prefix to already installed optional dependency.

Signed-off-by: Arokux arokux at gmail.com
---
 src/pacman/util.c |   43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index a5242ae..d0a049e 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1189,19 +1189,40 @@ static int depend_cmp(const void *d1, const void *d2)
 	return ret;
 }

+alpm_list_t *optdeps_to_strings(alpm_list_t *optdeps)
+{
+	alpm_list_t *i, *optstrings = NULL;
+  alpm_db_t *localdb = alpm_get_localdb(config->handle);
+
+	/* turn optdepends list into a text list */
+	for(i = optdeps; i; i = alpm_list_next(i)) {
+		alpm_depend_t *optdep = i->data;
+		char *optdepstring = alpm_dep_compute_string(optdep);
+
+		if(alpm_find_satisfier(alpm_db_get_pkgcache(localdb), optdepstring)) {
+			char *optdepstring_in;
+			pm_asprintf(&optdepstring_in, _("[installed] %s"), optdepstring);
+			free(optdepstring);
+
+			optdepstring = optdepstring_in;
+			optdepstring_in = NULL;
+		}
+
+		optstrings = alpm_list_add(optstrings, optdepstring);	
+	}
+
+	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 = NULL;

 	old = alpm_pkg_get_optdepends(oldpkg);
 	new = alpm_pkg_get_optdepends(newpkg);
 	optdeps = alpm_list_diff(new, old, depend_cmp);

-	/* 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 = optdeps_to_strings(optdeps);

 	if(optstrings) {
 		printf(_("New optional dependencies for %s\n"), alpm_pkg_get_name(newpkg));
@@ -1214,15 +1235,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 = NULL;

-	optdeps = alpm_pkg_get_optdepends(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 = optdeps_to_strings(alpm_pkg_get_optdepends(pkg));

 	if(optstrings) {
 		printf(_("Optional dependencies for %s\n"), alpm_pkg_get_name(pkg));


More information about the pacman-dev mailing list