[pacman-dev] [PATCH] query_group: allow package filters

Lukas Fleischer archlinux at cryptocrack.de
Wed Jun 19 07:42:57 EDT 2013


On Wed, Jun 19, 2013 at 09:14:31PM +1000, Allan McRae wrote:
> On 19/06/13 15:23, Andrew Gregory wrote:
> > Relocated query_group() to allow calling filter().
> > 
> > Fixes FS#19716
> > 
> > Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
> 
> Signed-off-by: Me
> 
> Aside:
> I have just noticed how weird pacman -Qg is.  I'd expect "pacman -Qg
> base" to show output like pacman -Q but only for packages in base.  i.e.
> not have the "base" prefix and have a version.  I wonder if these could
> be unified more...

I think the idea is that you can list all grouped packages and the
corresponding groups with `pacman -Qg`. The main problem probably is
that "-Qg" tries to do two things: Add group information to each package
and filter by group (although only the latter is documented in the man
page). If one of these functions could be moved somewhere else (or
dropped), it might be easier to unify stuff.

Also note that "-Qg" is the counterpart to "-Sgg" and "-Sg" does
something else...

> 
> > ---
> > 
> > The only actual changes are the two added:
> >  if(!filter(...)) {
> >  	continue;
> >  }
> > 
> >  src/pacman/query.c | 88 +++++++++++++++++++++++++++++-------------------------
> >  1 file changed, 47 insertions(+), 41 deletions(-)
> > 
> > diff --git a/src/pacman/query.c b/src/pacman/query.c
> > index f5862a2..4f5d80e 100644
> > --- a/src/pacman/query.c
> > +++ b/src/pacman/query.c
> > @@ -257,47 +257,6 @@ static int query_search(alpm_list_t *targets)
> >  	return dump_pkg_search(db_local, targets, 0);
> >  }
> >  
> > -static int query_group(alpm_list_t *targets)
> > -{
> > -	alpm_list_t *i, *j;
> > -	const char *grpname = NULL;
> > -	int ret = 0;
> > -	alpm_db_t *db_local = alpm_get_localdb(config->handle);
> > -
> > -	if(targets == NULL) {
> > -		for(j = alpm_db_get_groupcache(db_local); j; j = alpm_list_next(j)) {
> > -			alpm_group_t *grp = j->data;
> > -			const alpm_list_t *p;
> > -
> > -			for(p = grp->packages; p; p = alpm_list_next(p)) {
> > -				alpm_pkg_t *pkg = p->data;
> > -				printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg));
> > -			}
> > -		}
> > -	} else {
> > -		for(i = targets; i; i = alpm_list_next(i)) {
> > -			alpm_group_t *grp;
> > -			grpname = i->data;
> > -			grp = alpm_db_get_group(db_local, grpname);
> > -			if(grp) {
> > -				const alpm_list_t *p;
> > -				for(p = grp->packages; p; p = alpm_list_next(p)) {
> > -					if(!config->quiet) {
> > -						printf("%s %s\n", grpname,
> > -								alpm_pkg_get_name(p->data));
> > -					} else {
> > -						printf("%s\n", alpm_pkg_get_name(p->data));
> > -					}
> > -				}
> > -			} else {
> > -				pm_printf(ALPM_LOG_ERROR, _("group '%s' was not found\n"), grpname);
> > -				ret++;
> > -			}
> > -		}
> > -	}
> > -	return ret;
> > -}
> > -
> >  static unsigned short pkg_get_locality(alpm_pkg_t *pkg)
> >  {
> >  	const char *pkgname = alpm_pkg_get_name(pkg);
> > @@ -387,6 +346,53 @@ static int display(alpm_pkg_t *pkg)
> >  	return ret;
> >  }
> >  
> > +static int query_group(alpm_list_t *targets)
> > +{
> > +	alpm_list_t *i, *j;
> > +	const char *grpname = NULL;
> > +	int ret = 0;
> > +	alpm_db_t *db_local = alpm_get_localdb(config->handle);
> > +
> > +	if(targets == NULL) {
> > +		for(j = alpm_db_get_groupcache(db_local); j; j = alpm_list_next(j)) {
> > +			alpm_group_t *grp = j->data;
> > +			const alpm_list_t *p;
> > +
> > +			for(p = grp->packages; p; p = alpm_list_next(p)) {
> > +				alpm_pkg_t *pkg = p->data;
> > +				if(!filter(pkg)) {
> > +					continue;
> > +				}
> > +				printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg));
> > +			}
> > +		}
> > +	} else {
> > +		for(i = targets; i; i = alpm_list_next(i)) {
> > +			alpm_group_t *grp;
> > +			grpname = i->data;
> > +			grp = alpm_db_get_group(db_local, grpname);
> > +			if(grp) {
> > +				const alpm_list_t *p;
> > +				for(p = grp->packages; p; p = alpm_list_next(p)) {
> > +					if(!filter(p->data)) {
> > +						continue;
> > +					}
> > +					if(!config->quiet) {
> > +						printf("%s %s\n", grpname,
> > +								alpm_pkg_get_name(p->data));
> > +					} else {
> > +						printf("%s\n", alpm_pkg_get_name(p->data));
> > +					}
> > +				}
> > +			} else {
> > +				pm_printf(ALPM_LOG_ERROR, _("group '%s' was not found\n"), grpname);
> > +				ret++;
> > +			}
> > +		}
> > +	}
> > +	return ret;
> > +}
> > +
> >  int pacman_query(alpm_list_t *targets)
> >  {
> >  	int ret = 0;
> > 
> 
> 


More information about the pacman-dev mailing list