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-14 18:48:34 -0600 |
commit | 85b06f127600131e11afb3629e2609334dee00df (patch) | |
tree | e99ca85fa287d45a1b5c9822a5d100087c859ebc /lib/libalpm/deps.c | |
parent | 46ec9e3548b5b567c7eb18c360f54a77b6313b12 (diff) | |
download | 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/libalpm/deps.c')
-rw-r--r-- | lib/libalpm/deps.c | 43 |
1 files changed, 17 insertions, 26 deletions
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); } } } |