[pacman-dev] [PATCH] Show 'Required By' in -Si output

Allan McRae allan at archlinux.org
Wed Oct 7 23:14:02 EDT 2009


Dan McGee wrote:
> Just as we do in -Qi, we can compute required by information for sync
> database packages. The behavior seems sane; for a given package, the -Si
> required by will show all packages in *any* sync database that require it.
>
> Implements FS#16244.
>
> Signed-off-by: Dan McGee <dan at archlinux.org>
> ---
>  lib/libalpm/package.c |   46 ++++++++++++++++++++++++++++++++++++----------
>  src/pacman/package.c  |   13 ++++---------
>  2 files changed, 40 insertions(+), 19 deletions(-)
>
> diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
> index de17166..b0b6480 100644
> --- a/lib/libalpm/package.c
> +++ b/lib/libalpm/package.c
> @@ -556,6 +556,21 @@ unsigned short SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg)
>  	return pkg->scriptlet;
>  }
>  
> +static void find_requiredby(pmpkg_t *pkg, pmdb_t *db, alpm_list_t **reqs)
> +{
> +	const alpm_list_t *i;
> +	for(i = _alpm_db_get_pkgcache(db); i; i = i->next) {
> +		if(!i->data) {
> +			continue;
> +		}
> +		pmpkg_t *cachepkg = i->data;
> +		if(_alpm_dep_edge(cachepkg, pkg)) {
> +			const char *cachepkgname = alpm_pkg_get_name(cachepkg);
> +			*reqs = alpm_list_add(*reqs, strdup(cachepkgname));
> +		}
> +	}
> +}
> +
>  /**
>   * @brief Compute the packages requiring a given package.
>   * @param pkg a package
> @@ -565,18 +580,29 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
>  {
>  	const alpm_list_t *i;
>  	alpm_list_t *reqs = NULL;
> +	pmdb_t *db;
>  
> -	pmdb_t *localdb = alpm_option_get_localdb();
> -	for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) {
> -		if(!i->data) {
> -			continue;
> -		}
> -		pmpkg_t *cachepkg = i->data;
> -		if(_alpm_dep_edge(cachepkg, pkg)) {
> -			const char *cachepkgname = alpm_pkg_get_name(cachepkg);
> -			reqs = alpm_list_add(reqs, strdup(cachepkgname));
> +	if(pkg->origin == PKG_FROM_FILE) {
> +		/* The sane option; search locally for things that require this. */
> +		db = alpm_option_get_localdb();
> +		fprintf(stderr, "db name: %s\n", db->treename);
> +		find_requiredby(pkg, db, &reqs);
> +	} else {
> +		/* We have a DB package. if it is a local package, then we should
> +		 * only search the local DB; else search all known sync databases. */
> +		db = pkg->origin_data.db;
> +		if(db->is_local) {
> +			fprintf(stderr, "db name: %s\n", db->treename);
> +			find_requiredby(pkg, db, &reqs);
> +		} else {
> +			for(i = handle->dbs_sync; i; i = i->next) {
> +				db = i->data;
> +				fprintf(stderr, "db name: %s\n", db->treename);
> +				find_requiredby(pkg, db, &reqs);
> +			}
>  		}
>  	}
> +
>  	return(reqs);
>  }
>  
> diff --git a/src/pacman/package.c b/src/pacman/package.c
> index 3b14516..e7e2552 100644
> --- a/src/pacman/package.c
> +++ b/src/pacman/package.c
> @@ -83,10 +83,8 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
>  		depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep));
>  	}
>  
> -	if(level>0) {
> -		/* compute this here so we don't get a pause in the middle of output */
> -		requiredby = alpm_pkg_compute_requiredby(pkg);
> -	}
> +	/* compute this here so we don't get a pause in the middle of output */
> +	requiredby = alpm_pkg_compute_requiredby(pkg);
>  
>  	/* actual output */
>  	string_display(_("Name           :"), alpm_pkg_get_name(pkg));
> @@ -97,11 +95,7 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
>  	list_display(_("Provides       :"), alpm_pkg_get_provides(pkg));
>  	list_display(_("Depends On     :"), depstrings);
>  	list_display_linebreak(_("Optional Deps  :"), alpm_pkg_get_optdepends(pkg));
> -	/* Only applicable if installed */
> -	if(level > 0) {
> -		list_display(_("Required By    :"), requiredby);
> -		FREELIST(requiredby);
> -	}
> +	list_display(_("Required By    :"), requiredby);
>  	list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
>  	list_display(_("Replaces       :"), alpm_pkg_get_replaces(pkg));
>  	if(level < 0) {
> @@ -142,6 +136,7 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
>  	printf("\n");
>  
>  	FREELIST(depstrings);
> +	FREELIST(requiredby);
>  }
>  
>  /* Display the content of a sync package
>   

Looking at this, I can not see a way of turning it off.  I might be 
missing something....

 > cd /var/abs
 > grep -R "depends" {core,extra}/* | grep glibc | wc -l
365
 > grep -R "depends" {core,extra}/* | grep perl | wc -l
237

How many lines of output will that result in?


More information about the pacman-dev mailing list