From f43805d875ad5c672afbbfff48bded2087204773 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Sat, 10 May 2008 18:47:42 +0200 Subject: Cleanup usages of alpm_list_find and alpm_list_remove. * remove obsolete and unused *_cmp helper functions like deppkg_cmp and _alpm_grp_cmp * new alpm_list_remove_str function, used 6 times in handle.c * remove _alpm_prov_cmp / _alpm_db_whatprovides and replace them by a more general alpm_find_pkg_satisfiers with a cleaner implementation. before: alpm_db_whatprovides(db, targ) after: alpm_find_pkg_satisfiers(alpm_db_getpkgcache(db), targ) * remove satisfycmp and replace alpm_list_find + satisfycmp usage by _alpm_find_dep_satisfiers. before : alpm_list_find(_alpm_db_get_pkgcache(db), dep, satisfycmp) after : _alpm_find_dep_satisfiers(_alpm_db_get_pkgcache(db), dep) * remove _alpm_pkgname_pkg_cmp, which was used with alpm_list_remove, and use _alpm_pkg_find + alpm_list_remove with _alpm_pkg_cmp instead. This commit actually get rids of all complicated and asymmetric _cmp functions. I first thought these functions were worth it, be caused it allowed us to reuse list_find and list_remove. But this was at the detriment of the clarity and also the ease of use of these functions, dangerous because of their asymmetricity. Signed-off-by: Chantry Xavier Signed-off-by: Dan McGee --- lib/libalpm/deps.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'lib/libalpm/deps.c') diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 9cae0e2a..818418e2 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -194,10 +194,30 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse) return(newtargs); } -/* Little helper function for alpm_list_find */ -static int satisfycmp(const void *pkg, const void *depend) +alpm_list_t *_alpm_find_dep_satisfiers(alpm_list_t *pkgs, pmdepend_t *dep) { - return(!alpm_depcmp((pmpkg_t*) pkg, (pmdepend_t*) depend)); + alpm_list_t *i, *ret = NULL; + + for(i = pkgs; i; i = alpm_list_next(i)) { + pmpkg_t *pkg = i->data; + if(alpm_depcmp(pkg, dep)) { + ret = alpm_list_add(ret, pkg); + } + } + return(ret); +} + +/** Find packages in a list that provide a given package. + * @param pkgs an alpm_list_t* of package to search + * @param pkgname the name of the package + * @return an alpm_list_t* of packages that provide pkgname + */ +alpm_list_t SYMEXPORT *alpm_find_pkg_satisfiers(alpm_list_t *pkgs, const char *pkgname) +{ + pmdepend_t *dep = _alpm_splitdep(pkgname); + alpm_list_t *res = _alpm_find_dep_satisfiers(pkgs, dep); + _alpm_dep_free(dep); + return(res); } /** Checks dependencies and returns missing ones in a list. @@ -217,7 +237,7 @@ alpm_list_t SYMEXPORT *alpm_deptest(pmdb_t *db, alpm_list_t *targets) target = alpm_list_getdata(i); dep = _alpm_splitdep(target); - if(!alpm_list_find(_alpm_db_get_pkgcache(db), dep, satisfycmp)) { + if(!_alpm_find_dep_satisfiers(_alpm_db_get_pkgcache(db), dep)) { ret = alpm_list_add(ret, target); } _alpm_dep_free(dep); @@ -268,8 +288,8 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps, pmdepend_t *depend = j->data; /* 1. we check the upgrade list */ /* 2. we check database for untouched satisfying packages */ - if(!alpm_list_find(upgrade, depend, satisfycmp) && - !alpm_list_find(dblist, depend, satisfycmp)) { + if(!_alpm_find_dep_satisfiers(upgrade, depend) && + !_alpm_find_dep_satisfiers(dblist, depend)) { /* Unsatisfied dependency in the upgrade list */ char *missdepstring = alpm_dep_get_string(depend); _alpm_log(PM_LOG_DEBUG, "checkdeps: missing dependency '%s' for package '%s'\n", @@ -288,13 +308,13 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps, pmpkg_t *lp = i->data; for(j = alpm_pkg_get_depends(lp); j; j = j->next) { pmdepend_t *depend = j->data; - pmpkg_t *causingpkg = alpm_list_find(modified, depend, satisfycmp); + pmpkg_t *causingpkg = alpm_list_getdata(_alpm_find_dep_satisfiers(modified, depend)); /* we won't break this depend, if it is already broken, we ignore it */ /* 1. check upgrade list for satisfiers */ /* 2. check dblist for satisfiers */ if(causingpkg && - !alpm_list_find(upgrade, depend, satisfycmp) && - !alpm_list_find(dblist, depend, satisfycmp)) { + !_alpm_find_dep_satisfiers(upgrade, depend) && + !_alpm_find_dep_satisfiers(dblist, depend)) { char *missdepstring = alpm_dep_get_string(depend); _alpm_log(PM_LOG_DEBUG, "checkdeps: transaction would break '%s' dependency of '%s'\n", missdepstring, alpm_pkg_get_name(lp)); -- cgit v1.2.3-2-g168b