[pacman-dev] attempt of reworking pacman_query function
looking at the current code in src/query.c , I found it could be more flexible, and that some parts could be refactored a bit. I think there should be a distinction in the code between "filter" options, like --orphans or --foreign, and display options, like -Qi, -Qii or -Ql. The code for displaying the output (depending on i, l options) was at 3 different places of query.c , so I moved all in a display(pmpkg_t *) function. I also merged the query_isfile function in the main loop of pacman_query. Also, the orphans and foreign functions had their own loop walking through the list of targets, besides the one in pacman_query(). So I made new functions : filter(pkg), is_orphan(pkg) and is_foreign(pkg) that determine if a package should be displayed or not when these options are used. After this, it should be easier to add --explicit and --depend options for displaying only explictly installed packages, or only packages installed as dependencies. Also, it would be much easier and cleaner if the orphans option displayed all packages not required by any other by default, and then you could get dependencies only by using another flag. That's done by my patch, and if it's ok, I'll be able to very easily add the two new options above. That would allow to keep the code as clean as possible, while still getting as much configurabily as we want without any confusion. Some examples : pacman -Qe : lists all explictly installed packages pacman -Qd : list all packages installed as dependencies pacman -Qt : list all orphans (package not required by any others) pacman -Qtd : list real orphans (package installed as dependencies, but not required by any others anymore) (that is the current orphan option) pacman -Qte : list package explicitly installed and not required by any others (pacman2 orphan option). So the following patch does not add e and d options yet, it just prepare for them :)
From 31d6c53de9d680046c2c610fe5382173e11c7950 Mon Sep 17 00:00:00 2001 From: Chantry Xavier
Date: Sat, 14 Jul 2007 20:45:30 +0200 Subject: [PATCH] libalpm/query.c : makes orphans and foreign options as filters.
The --foreign and --orphans functions now behave as a filter
for the other options. This cleans the code a bit, and will
make easier the adding of new filter options, like
explicit (show only explictly installed packages) or depends
(show only packages installed as dependencies).
Signed-off-by: Chantry Xavier
On Sat, Jul 14, 2007 at 09:20:45PM +0200, Xavier wrote:
Some examples : pacman -Qe : lists all explictly installed packages pacman -Qd : list all packages installed as dependencies pacman -Qt : list all orphans (package not required by any others) pacman -Qtd : list real orphans (package installed as dependencies, but not required by any others anymore) (that is the current orphan option) pacman -Qte : list package explicitly installed and not required by any others (pacman2 orphan option).
So the following patch does not add e and d options yet, it just prepare for them :)
here is the missing bit :
From 027f0977451406cdc8e430b1b9b7b234c091ff07 Mon Sep 17 00:00:00 2001 From: Chantry Xavier
Date: Sun, 15 Jul 2007 00:44:06 +0200 Subject: [PATCH] new query options : explicit (-Qe) and deps (-Qd).
The t shortcut for --test was removed,
the orphan option (previously -Qe) was renamed to -Qt,
-Qe lists all packages installed explictly,
and -Qd lists all packages installed as dependencies.
Besides, t can be combined with either e or d.
Signed-off-by: Chantry Xavier
participants (1)
-
Xavier