summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-07-29 15:35:59 -0500
committerDan McGee <dan@archlinux.org>2011-09-28 04:52:37 -0500
commit7edeb276b63efeea7e8f266dfee792e2709ba412 (patch)
tree2f4b52b2c12b564b99825c99ec9ad874d8ed945a /src
parentbd83c8e7562a2d6794d4322845c23cc21985979a (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/conf.c4
-rw-r--r--src/pacman/conf.h3
-rw-r--r--src/pacman/remove.c10
-rw-r--r--src/pacman/sync.c1
-rw-r--r--src/pacman/upgrade.c1
-rw-r--r--src/pacman/util.c18
-rw-r--r--src/pacman/util.h1
7 files changed, 33 insertions, 5 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 337522b8..fe2ebb3e 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -68,6 +68,9 @@ int config_free(config_t *oldconfig)
return -1;
}
+ alpm_list_free(oldconfig->explicit_adds);
+ alpm_list_free(oldconfig->explicit_removes);
+
FREELIST(oldconfig->holdpkg);
FREELIST(oldconfig->syncfirst);
FREELIST(oldconfig->ignorepkg);
@@ -84,7 +87,6 @@ int config_free(config_t *oldconfig)
free(oldconfig->print_format);
free(oldconfig->arch);
free(oldconfig);
- oldconfig = NULL;
return 0;
}
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 396cde5a..9e14925a 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -93,6 +93,9 @@ typedef struct __config_t {
/* our connection to libalpm */
alpm_handle_t *handle;
+
+ alpm_list_t *explicit_adds;
+ alpm_list_t *explicit_removes;
} config_t;
/* Operations */
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 95a728ee..3fc8279c 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -33,16 +33,17 @@
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_list_t *p;
- if((info = alpm_db_get_pkg(db_local, target)) != NULL) {
- if(alpm_remove_pkg(config->handle, info) == -1) {
+ if((pkg = alpm_db_get_pkg(db_local, target)) != NULL) {
+ if(alpm_remove_pkg(config->handle, pkg) == -1) {
pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", target,
alpm_strerror(alpm_errno(config->handle)));
return -1;
}
+ config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
return 0;
}
@@ -53,12 +54,13 @@ static int remove_target(const char *target)
return -1;
}
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) {
pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", target,
alpm_strerror(alpm_errno(config->handle)));
return -1;
}
+ config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
}
return 0;
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 20a83b23..48ae30cf 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -612,6 +612,7 @@ static int process_pkg(alpm_pkg_t *pkg)
return 1;
}
}
+ config->explicit_adds = alpm_list_add(config->explicit_adds, pkg);
return 0;
}
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 565fb922..3d4e34c1 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -89,6 +89,7 @@ int pacman_upgrade(alpm_list_t *targets)
trans_release();
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 */
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);
}
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 95b0d991..275f9913 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -42,6 +42,7 @@
typedef struct _pm_target_t {
alpm_pkg_t *remove;
alpm_pkg_t *install;
+ int is_explicit;
} pm_target_t;
void trans_init_error(void);