From 7edeb276b63efeea7e8f266dfee792e2709ba412 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 29 Jul 2011 15:35:59 -0500 Subject: Keep track of explicitly added and removed packages This allows us to sort the output list by showing all pulled dependencies first, followed by the explicitly specified targets. Signed-off-by: Dan McGee --- src/pacman/util.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/pacman/util.c') diff --git a/src/pacman/util.c b/src/pacman/util.c index 2c02d963..aa93357e 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -892,6 +892,10 @@ static int target_cmp(const void *p1, const void *p2) { const pm_target_t *targ1 = p1; const pm_target_t *targ2 = p2; + /* explicit are always sorted after implicit (e.g. deps, pulled targets) */ + if(targ1->is_explicit != targ2->is_explicit) { + return targ1->is_explicit > targ2->is_explicit; + } const char *name1 = targ1->install ? alpm_pkg_get_name(targ1->install) : alpm_pkg_get_name(targ1->remove); const char *name2 = targ2->install ? @@ -899,6 +903,14 @@ static int target_cmp(const void *p1, const void *p2) return strcmp(name1, name2); } +static int pkg_cmp(const void *p1, const void *p2) +{ + /* explicit cast due to (un)necessary removal of const */ + alpm_pkg_t *pkg1 = (alpm_pkg_t *)p1; + alpm_pkg_t *pkg2 = (alpm_pkg_t *)p2; + return strcmp(alpm_pkg_get_name(pkg1), alpm_pkg_get_name(pkg2)); +} + void display_targets(void) { alpm_list_t *i, *targets = NULL; @@ -910,6 +922,9 @@ void display_targets(void) if(!targ) return; targ->install = pkg; targ->remove = alpm_db_get_pkg(db_local, alpm_pkg_get_name(pkg)); + if(alpm_list_find(config->explicit_adds, pkg, pkg_cmp)) { + targ->is_explicit = 1; + } targets = alpm_list_add(targets, targ); } for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) { @@ -917,6 +932,9 @@ void display_targets(void) pm_target_t *targ = calloc(1, sizeof(pm_target_t)); if(!targ) return; targ->remove = pkg; + if(alpm_list_find(config->explicit_removes, pkg, pkg_cmp)) { + targ->is_explicit = 1; + } targets = alpm_list_add(targets, targ); } -- cgit v1.2.3