From 31a40ee106389223b0e96ee7d4dd1a77c850309f Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Sat, 2 Jun 2007 23:22:42 +0200 Subject: [PATCH] new query options : explicit (-Qe) and deps (-Qd). orphan option (-Qe) was renamed to -Qt -Qe lists all packages installed explictly, -Qd lists all packages installed as dependencies. Signed-off-by: Chantry Xavier --- src/pacman/conf.h | 2 ++ src/pacman/pacman.c | 20 +++++++++++++++----- src/pacman/query.c | 50 ++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 4fff0ab..bf3c143 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -39,6 +39,8 @@ typedef struct __config_t { unsigned short op_q_list; unsigned short op_q_foreign; unsigned short op_q_orphans; + unsigned short op_q_deps; + unsigned short op_q_explicit; unsigned short op_q_owns; unsigned short op_q_search; unsigned short op_q_changelog; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index f0ae328..eb23340 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -121,8 +121,10 @@ static void usage(int op, char *myname) printf("%s: %s {-Q --query} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); printf(_(" -c, --changelog view the changelog of a package\n")); - printf(_(" -e, --orphans list all packages installed as dependencies but no longer\n" + printf(_(" -t, --orphans list all packages installed as dependencies but no longer\n" " required by any package\n")); + printf(_(" -e, --explicit list all packages installed explicitly\n")); + printf(_(" -d, --deps list all packages installed as dependencies\n")); printf(_(" -g, --groups view all members of a package group\n")); printf(_(" -i, --info view package information\n")); printf(_(" -l, --list list the contents of the queried package\n")); @@ -272,7 +274,9 @@ static int parseargs(int argc, char *argv[]) {"clean", no_argument, 0, 'c'}, {"nodeps", no_argument, 0, 'd'}, {"dependsonly",no_argument, 0, 'e'}, - {"orphans", no_argument, 0, 'e'}, + {"orphans", no_argument, 0, 't'}, + {"deps", no_argument, 0, 'd'}, + {"explicit", no_argument, 0, 'e'}, {"force", no_argument, 0, 'f'}, {"groups", no_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, @@ -306,7 +310,7 @@ static int parseargs(int argc, char *argv[]) struct stat st; unsigned short logmask; - while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepiuwygz", opts, &option_index))) { + while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepituwygz", opts, &option_index))) { if(opt < 0) { break; } @@ -386,9 +390,12 @@ static int parseargs(int argc, char *argv[]) config->flags |= PM_TRANS_FLAG_CASCADE; config->op_q_changelog = 1; break; - case 'd': config->flags |= PM_TRANS_FLAG_NODEPS; break; + case 'd': + config->op_q_deps = 1; + config->flags |= PM_TRANS_FLAG_NODEPS; + break; case 'e': - config->op_q_orphans++; + config->op_q_explicit = 1; config->flags |= PM_TRANS_FLAG_DEPENDSONLY; break; case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break; @@ -417,6 +424,9 @@ static int parseargs(int argc, char *argv[]) config->op_q_search = 1; config->flags |= PM_TRANS_FLAG_RECURSE; break; + case 't': + config->op_q_orphans = 1; + break; case 'u': config->op_s_upgrade = 1; config->op_q_upgrade = 1; diff --git a/src/pacman/query.c b/src/pacman/query.c index 7df16b1..63d4b8d 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -274,7 +274,7 @@ int pacman_query(alpm_list_t *targets) display_targets(syncpkgs); return(0); } else { - printf(_("no upgrades found")); + printf(_("no upgrades found\n")); return(1); } } @@ -307,7 +307,19 @@ int pacman_query(alpm_list_t *targets) pkgname = alpm_pkg_get_name(tmpp); pkgver = alpm_pkg_get_version(tmpp); - if(config->op_q_list || config->op_q_orphans || config->op_q_foreign) { + int showonlydep = 0; + int showonlyexplicit = 0; + /* By default, only orphaned deps are displayed */ + if (config->op_q_orphans && !config->op_q_deps && !config->op_q_explicit) { + config->op_q_deps = 1; + } + if (config->op_q_deps != config->op_q_explicit) { + showonlydep = config->op_q_deps; + showonlyexplicit = config->op_q_explicit; + } + + if(config->op_q_list || config->op_q_orphans || config->op_q_foreign + || showonlydep || showonlyexplicit) { info = alpm_db_get_pkg(db_local, (char *)pkgname); if(info == NULL) { /* something weird happened */ @@ -316,6 +328,7 @@ int pacman_query(alpm_list_t *targets) continue; } } + int display = 1; if(config->op_q_foreign) { int match = 0; for(j = sync_dbs; j; j = alpm_list_next(j)) { @@ -327,20 +340,33 @@ int pacman_query(alpm_list_t *targets) } } } - if(match==0) { - printf("%s %s\n", pkgname, pkgver); + if(match==1) { + display = 0; } - } else if(config->op_q_list) { - dump_pkg_files(info); - } else if(config->op_q_orphans) { - if(alpm_pkg_get_requiredby(info) == NULL - && ((long)alpm_pkg_get_reason(info) == PM_PKG_REASON_DEPEND - || config->op_q_orphans > 1)) { + } + if(config->op_q_orphans && + alpm_pkg_get_requiredby(info) != NULL) { + display = 0; + } + if (showonlyexplicit) { + if ((long)alpm_pkg_get_reason(info) == PM_PKG_REASON_DEPEND) { + display = 0; + } + } + if (showonlydep) { + if ((long)alpm_pkg_get_reason(info) == PM_PKG_REASON_EXPLICIT) { + display = 0; + } + } + + if (display) { + if(config->op_q_list) { + dump_pkg_files(info); + } else { printf("%s %s\n", pkgname, pkgver); } - } else { - printf("%s %s\n", pkgname, pkgver); } + } } else { for(i = targets; i; i = alpm_list_next(i)) { -- 1.5.2