From 85b06f127600131e11afb3629e2609334dee00df Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Wed, 14 Nov 2007 12:42:15 +0100 Subject: 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 [Dan: punctuation cleanup in commit message and code comments, added comment to alpm_list_add] Signed-off-by: Dan McGee --- lib/libalpm/deps.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'lib/libalpm/deps.c') 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); } } } -- cgit v1.2.3-24-g4f1b