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 <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-07-29 15:35:59 -05:00
parent bd83c8e756
commit 7edeb276b6
7 changed files with 33 additions and 5 deletions

View file

@ -68,6 +68,9 @@ int config_free(config_t *oldconfig)
return -1; return -1;
} }
alpm_list_free(oldconfig->explicit_adds);
alpm_list_free(oldconfig->explicit_removes);
FREELIST(oldconfig->holdpkg); FREELIST(oldconfig->holdpkg);
FREELIST(oldconfig->syncfirst); FREELIST(oldconfig->syncfirst);
FREELIST(oldconfig->ignorepkg); FREELIST(oldconfig->ignorepkg);
@ -84,7 +87,6 @@ int config_free(config_t *oldconfig)
free(oldconfig->print_format); free(oldconfig->print_format);
free(oldconfig->arch); free(oldconfig->arch);
free(oldconfig); free(oldconfig);
oldconfig = NULL;
return 0; return 0;
} }

View file

@ -93,6 +93,9 @@ typedef struct __config_t {
/* our connection to libalpm */ /* our connection to libalpm */
alpm_handle_t *handle; alpm_handle_t *handle;
alpm_list_t *explicit_adds;
alpm_list_t *explicit_removes;
} config_t; } config_t;
/* Operations */ /* Operations */

View file

@ -33,16 +33,17 @@
static int remove_target(const char *target) static int remove_target(const char *target)
{ {
alpm_pkg_t *info; alpm_pkg_t *pkg;
alpm_db_t *db_local = alpm_option_get_localdb(config->handle); alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
alpm_list_t *p; alpm_list_t *p;
if((info = alpm_db_get_pkg(db_local, target)) != NULL) { if((pkg = alpm_db_get_pkg(db_local, target)) != NULL) {
if(alpm_remove_pkg(config->handle, info) == -1) { if(alpm_remove_pkg(config->handle, pkg) == -1) {
pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", target, pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", target,
alpm_strerror(alpm_errno(config->handle))); alpm_strerror(alpm_errno(config->handle)));
return -1; return -1;
} }
config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
return 0; return 0;
} }
@ -53,12 +54,13 @@ static int remove_target(const char *target)
return -1; return -1;
} }
for(p = grp->packages; p; p = alpm_list_next(p)) { for(p = grp->packages; p; p = alpm_list_next(p)) {
alpm_pkg_t *pkg = alpm_list_getdata(p); pkg = alpm_list_getdata(p);
if(alpm_remove_pkg(config->handle, pkg) == -1) { if(alpm_remove_pkg(config->handle, pkg) == -1) {
pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", target, pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", target,
alpm_strerror(alpm_errno(config->handle))); alpm_strerror(alpm_errno(config->handle)));
return -1; return -1;
} }
config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
} }
return 0; return 0;
} }

View file

@ -612,6 +612,7 @@ static int process_pkg(alpm_pkg_t *pkg)
return 1; return 1;
} }
} }
config->explicit_adds = alpm_list_add(config->explicit_adds, pkg);
return 0; return 0;
} }

View file

@ -89,6 +89,7 @@ int pacman_upgrade(alpm_list_t *targets)
trans_release(); trans_release();
return 1; return 1;
} }
config->explicit_adds = alpm_list_add(config->explicit_adds, pkg);
} }
/* now that targets are resolved, we can hand it all off to the sync code */ /* now that targets are resolved, we can hand it all off to the sync code */

View file

@ -892,6 +892,10 @@ static int target_cmp(const void *p1, const void *p2)
{ {
const pm_target_t *targ1 = p1; const pm_target_t *targ1 = p1;
const pm_target_t *targ2 = p2; 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 ? const char *name1 = targ1->install ?
alpm_pkg_get_name(targ1->install) : alpm_pkg_get_name(targ1->remove); alpm_pkg_get_name(targ1->install) : alpm_pkg_get_name(targ1->remove);
const char *name2 = targ2->install ? const char *name2 = targ2->install ?
@ -899,6 +903,14 @@ static int target_cmp(const void *p1, const void *p2)
return strcmp(name1, name2); 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) void display_targets(void)
{ {
alpm_list_t *i, *targets = NULL; alpm_list_t *i, *targets = NULL;
@ -910,6 +922,9 @@ void display_targets(void)
if(!targ) return; if(!targ) return;
targ->install = pkg; targ->install = pkg;
targ->remove = alpm_db_get_pkg(db_local, alpm_pkg_get_name(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); targets = alpm_list_add(targets, targ);
} }
for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) { 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)); pm_target_t *targ = calloc(1, sizeof(pm_target_t));
if(!targ) return; if(!targ) return;
targ->remove = pkg; targ->remove = pkg;
if(alpm_list_find(config->explicit_removes, pkg, pkg_cmp)) {
targ->is_explicit = 1;
}
targets = alpm_list_add(targets, targ); targets = alpm_list_add(targets, targ);
} }

View file

@ -42,6 +42,7 @@
typedef struct _pm_target_t { typedef struct _pm_target_t {
alpm_pkg_t *remove; alpm_pkg_t *remove;
alpm_pkg_t *install; alpm_pkg_t *install;
int is_explicit;
} pm_target_t; } pm_target_t;
void trans_init_error(void); void trans_init_error(void);