[pacman-dev] [PATCH v3 1/3] deps.c: split _alpm_depcmp into _alpm_depcmp_provides

Andrew Gregory andrew.gregory.8 at gmail.com
Wed Sep 17 10:30:19 EDT 2014


On 09/17/14 at 01:02am, Florian Pritz wrote:
> This allows to reuse the provision checker for a simple list of
> provisions without a package.
> 
> Signed-off-by: Florian Pritz <bluewind at xinu.at>
> ---
> 
> v3: no changes here
> 
>  lib/libalpm/deps.c | 27 +++++++++++++++++++--------
>  lib/libalpm/deps.h |  1 +
>  2 files changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
> index c5acfc9..920753b 100644
> --- a/lib/libalpm/deps.c
> +++ b/lib/libalpm/deps.c
> @@ -416,17 +416,17 @@ int _alpm_depcmp_literal(alpm_pkg_t *pkg, alpm_depend_t *dep)
>  	return dep_vercmp(pkg->version, dep->mod, dep->version);
>  }
>  
> -int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep)
> +/**
> + * @param dep dependency to check agains the provision list
> + * @param provisions provision list
> + * @return 1 if provider is found, 0 otherwise
> + */
> +int _alpm_depcmp_provides(alpm_depend_t *dep, alpm_list_t *provisions)
>  {
> -	alpm_list_t *i;
> -	int satisfy = _alpm_depcmp_literal(pkg, dep);
> -
> -	if(satisfy) {
> -		return satisfy;
> -	}
> +	int satisfy = 0;
>  
>  	/* check provisions, name and version if available */
> -	for(i = alpm_pkg_get_provides(pkg); i && !satisfy; i = i->next) {
> +	for(alpm_list_t *i = provisions; i && !satisfy; i = i->next) {

i should be declared at the top of the block.

>  		alpm_depend_t *provision = i->data;
>  
>  		if(dep->mod == ALPM_DEP_MOD_ANY) {
> @@ -444,6 +444,17 @@ int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep)
>  	return satisfy;
>  }
>  
> +int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep)
> +{
> +	int satisfy = _alpm_depcmp_literal(pkg, dep);
> +
> +	if(satisfy) {
> +		return satisfy;
> +	}
> +
> +	return _alpm_depcmp_provides(dep, alpm_pkg_get_provides(pkg));
> +}

This returns a boolean, is there any reason to keep around satisfy
instead of simplifying this to:
 return _alpm_depcmp_literal(...)
     || _alpm_depcmp_provides(...)

> +
>  alpm_depend_t *_alpm_splitdep(const char *depstring)
>  {
>  	alpm_depend_t *depend;
> diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
> index e36bbb3..f4eadba 100644
> --- a/lib/libalpm/deps.h
> +++ b/lib/libalpm/deps.h
> @@ -37,6 +37,7 @@ int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs, alpm_pkg_t
>  		alpm_list_t **data);
>  alpm_depend_t *_alpm_splitdep(const char *depstring);
>  int _alpm_depcmp_literal(alpm_pkg_t *pkg, alpm_depend_t *dep);
> +int _alpm_depcmp_provides(alpm_depend_t *dep, alpm_list_t *provisions);
>  int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep);
>  
>  #endif /* _ALPM_DEPS_H */
> -- 
> 2.1.0


More information about the pacman-dev mailing list