diff options
author | Nagy Gabor <ngaba@bibl.u-szeged.hu> | 2007-11-14 12:42:15 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-11-15 01:48:34 +0100 |
commit | 85b06f127600131e11afb3629e2609334dee00df (patch) | |
tree | e99ca85fa287d45a1b5c9822a5d100087c859ebc /lib | |
parent | 46ec9e3548b5b567c7eb18c360f54a77b6313b12 (diff) | |
download | pacman-85b06f127600131e11afb3629e2609334dee00df.tar.gz pacman-85b06f127600131e11afb3629e2609334dee00df.tar.xz |
alpm_list_add == alpm_list_add_last
It's time to define that alpm_list_add(list, foo) adds 'foo' to the end of
'list' and returns with 'list', because:
1. list is a list, not a set.
2. sortbydeps _needs_ an alpm_list_add definition to work properly.
As a first step, I used this definition in recursedeps.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
[Dan: punctuation cleanup in commit message and code comments, added comment
to alpm_list_add]
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/alpm_list.c | 2 | ||||
-rw-r--r-- | lib/libalpm/deps.c | 43 | ||||
-rw-r--r-- | lib/libalpm/deps.h | 2 | ||||
-rw-r--r-- | lib/libalpm/remove.c | 10 |
4 files changed, 24 insertions, 33 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index 465c1a8f..774d1dbe 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -98,7 +98,7 @@ void SYMEXPORT alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn) /* Mutators */ /** - * @brief Add a new item to the list. + * @brief Add a new item to the end of the list. * * @param list the list to add to * @param data the new item to be added to the list diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index b551681a..63775d20 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -596,12 +596,13 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, * @brief Adds unneeded dependencies to an existing list of packages. * By unneeded, we mean dependencies that are only required by packages in the * target list, so they can be safely removed. + * If the input list was topo sorted, the output list will be topo sorted too. * * @param db package database to do dependency tracing in * @param *targs pointer to a list of packages * @param include_explicit if 0, explicitly installed packages are not included */ -void _alpm_recursedeps(pmdb_t *db, alpm_list_t **targs, int include_explicit) +void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit) { alpm_list_t *i, *j, *k; @@ -611,34 +612,24 @@ void _alpm_recursedeps(pmdb_t *db, alpm_list_t **targs, int include_explicit) return; } - /* TODO: the while loop should be removed if we can assume - * that alpm_list_add (or another function) adds to the end of the list, - * and that the target list is topo sorted (by _alpm_sortbydeps()). - */ - int ready = 0; - while(!ready) { - ready = 1; - for(i = *targs; i; i = i->next) { - pmpkg_t *pkg = i->data; - for(j = alpm_pkg_get_depends(pkg); j; j = j->next) { - pmdepend_t *depend = alpm_splitdep(j->data); - if(depend == NULL) { - continue; - } - for(k = _alpm_db_get_pkgcache(db); k; k = k->next) { - pmpkg_t *deppkg = k->data; - if(alpm_depcmp(deppkg,depend) - && can_remove_package(db, deppkg, *targs, include_explicit)) { - _alpm_log(PM_LOG_DEBUG, "adding '%s' to the targets\n", - alpm_pkg_get_name(deppkg)); - + for(i = targs; i; i = i->next) { + pmpkg_t *pkg = i->data; + for(j = alpm_pkg_get_depends(pkg); j; j = j->next) { + pmdepend_t *depend = alpm_splitdep(j->data); + if(depend == NULL) { + continue; + } + for(k = _alpm_db_get_pkgcache(db); k; k = k->next) { + pmpkg_t *deppkg = k->data; + if(alpm_depcmp(deppkg,depend) + && can_remove_package(db, deppkg, targs, include_explicit)) { + _alpm_log(PM_LOG_DEBUG, "adding '%s' to the targets\n", + alpm_pkg_get_name(deppkg)); /* add it to the target list */ - *targs = alpm_list_add(*targs, _alpm_pkg_dup(deppkg)); - ready = 0; - } + targs = alpm_list_add(targs, _alpm_pkg_dup(deppkg)); } - FREE(depend); } + FREE(depend); } } } diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index 59b26307..f11a8d88 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -58,7 +58,7 @@ int _alpm_depmiss_isin(pmdepmissing_t *needle, alpm_list_t *haystack); alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode); alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op, alpm_list_t *packages); -void _alpm_recursedeps(pmdb_t *db, alpm_list_t **targs, int include_explicit); +void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit); int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg, alpm_list_t **list, pmtrans_t *trans, alpm_list_t **data); diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index c4e44398..86cfee68 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -137,11 +137,6 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data) } } - if(trans->flags & PM_TRANS_FLAG_RECURSE) { - _alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n"); - _alpm_recursedeps(db, &trans->packages, 0); - } - /* re-order w.r.t. dependencies */ _alpm_log(PM_LOG_DEBUG, "sorting by dependencies\n"); lp = _alpm_sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE); @@ -149,6 +144,11 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data) alpm_list_free(trans->packages); trans->packages = lp; + if(trans->flags & PM_TRANS_FLAG_RECURSE) { + _alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n"); + _alpm_recursedeps(db, trans->packages, 0); + } + EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL); return(0); |