[pacman-dev] [PATCH] New _alpm_find_first_satisfier function.
Dan McGee
dpmcgee at gmail.com
Tue May 20 16:40:30 EDT 2008
On Sun, May 18, 2008 at 7:08 AM, Xavier Chantry <shiningxc at gmail.com> wrote:
> Address two concerns brought up by Nagy about the _alpm_find_dep_satisfier
> function by adding the following new function :
> pmpkg_t *_alpm_find_first_satisfier(alpm_list_t *pkgs, pmdepend_t *dep)
>
> This function just returns the first satisfier, so this takes care of the
> performance problem by restoring the old behavior. The memleak was also
> fixed.
>
> Ref: http://www.archlinux.org/pipermail/pacman-dev/2008-May/011779.html
>
> Signed-off-by: Xavier Chantry <shiningxc at gmail.com>
Untested on my end but if you did:
Acked-by: Dan McGee <dan at archlinux.org>
> ---
> lib/libalpm/deps.c | 37 ++++++++++++++++++++++++++++++-------
> lib/libalpm/deps.h | 1 +
> 2 files changed, 31 insertions(+), 7 deletions(-)
>
> diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
> index 37e9916..383f02d 100644
> --- a/lib/libalpm/deps.c
> +++ b/lib/libalpm/deps.c
> @@ -194,7 +194,10 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
> return(newtargs);
> }
>
> -alpm_list_t *_alpm_find_dep_satisfiers(alpm_list_t *pkgs, pmdepend_t *dep)
> +/* if full > 0, return the full list of satisfiers
> + * if full == 0, return the first satisfier
> + */
> +static alpm_list_t *find_dep_satisfiers(alpm_list_t *pkgs, pmdepend_t *dep, int full)
> {
> alpm_list_t *i, *ret = NULL;
>
> @@ -202,11 +205,31 @@ alpm_list_t *_alpm_find_dep_satisfiers(alpm_list_t *pkgs, pmdepend_t *dep)
> pmpkg_t *pkg = i->data;
> if(alpm_depcmp(pkg, dep)) {
> ret = alpm_list_add(ret, pkg);
> + if(!full) {
> + break;
> + }
> }
> }
> return(ret);
> }
>
> +alpm_list_t *_alpm_find_dep_satisfiers(alpm_list_t *pkgs, pmdepend_t *dep)
> +{
> + return(find_dep_satisfiers(pkgs, dep, 1));
> +}
> +
> +pmpkg_t *_alpm_find_first_satisfier(alpm_list_t *pkgs, pmdepend_t *dep)
> +{
> + pmpkg_t *pkg = NULL;
> + alpm_list_t *list = find_dep_satisfiers(pkgs, dep, 0);
> + if(list) {
> + pkg = list->data;
> + alpm_list_free(list);
> + }
> + return(pkg);
> +}
> +
> +
> /** 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
> @@ -237,7 +260,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_find_dep_satisfiers(_alpm_db_get_pkgcache(db), dep)) {
> + if(!_alpm_find_first_satisfier(_alpm_db_get_pkgcache(db), dep)) {
> ret = alpm_list_add(ret, target);
> }
> _alpm_dep_free(dep);
> @@ -288,8 +311,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_find_dep_satisfiers(upgrade, depend) &&
> - !_alpm_find_dep_satisfiers(dblist, depend)) {
> + if(!_alpm_find_first_satisfier(upgrade, depend) &&
> + !_alpm_find_first_satisfier(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",
> @@ -308,13 +331,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_getdata(_alpm_find_dep_satisfiers(modified, depend));
> + pmpkg_t *causingpkg = _alpm_find_first_satisfier(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_find_dep_satisfiers(upgrade, depend) &&
> - !_alpm_find_dep_satisfiers(dblist, depend)) {
> + !_alpm_find_first_satisfier(upgrade, depend) &&
> + !_alpm_find_first_satisfier(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));
> diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
> index 70badfd..5c7da87 100644
> --- a/lib/libalpm/deps.h
> +++ b/lib/libalpm/deps.h
> @@ -52,6 +52,7 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
> **data);
> pmdepend_t *_alpm_splitdep(const char *depstring);
> alpm_list_t *_alpm_find_dep_satisfiers(alpm_list_t *pkgs, pmdepend_t *dep);
> +pmpkg_t *_alpm_find_first_satisfier(alpm_list_t *pkgs, pmdepend_t *dep);
>
> #endif /* _ALPM_DEPS_H */
>
> --
> 1.5.5.1
>
>
> _______________________________________________
> pacman-dev mailing list
> pacman-dev at archlinux.org
> http://archlinux.org/mailman/listinfo/pacman-dev
>
More information about the pacman-dev
mailing list