[pacman-dev] [PATCH] pacman: add -n/--native filter to -Q

Simon Gomizelj simongmzlj at gmail.com
Fri Nov 16 01:26:44 EST 2012


Signed-off-by: Simon Gomizelj <simongmzlj at gmail.com>
---
 doc/pacman.8.txt    | 4 ++++
 src/pacman/conf.h   | 1 +
 src/pacman/pacman.c | 3 +++
 src/pacman/query.c  | 4 ++++
 4 files changed, 12 insertions(+)

diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt
index 24c2243..de28b9c 100644
--- a/doc/pacman.8.txt
+++ b/doc/pacman.8.txt
@@ -273,6 +273,10 @@ Query Options[[QO]]
 	database(s).  Typically these are packages that were downloaded manually
 	and installed with '\--upgrade'.
 
+*-n, \--native*::
+	Restrict or filter output to packages that are found in the sync
+	database(s).  This is the inverse filter of '\--foreign'.
+
 *-o, \--owns* <file>::
 	Search for packages that own the specified file(s). The path can be
 	relative or absolute and one or more files can be specified.
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 69c955e..aee6859 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -51,6 +51,7 @@ typedef struct __config_t {
 	unsigned short op_q_info;
 	unsigned short op_q_list;
 	unsigned short op_q_foreign;
+	unsigned short op_q_native;
 	unsigned short op_q_unrequired;
 	unsigned short op_q_deps;
 	unsigned short op_q_explicit;
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 478196e..1ca746d 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -142,6 +142,7 @@ static void usage(int op, const char * const myname)
 			addlist(_("  -k, --check          check that the files owned by the package(s) are present\n"));
 			addlist(_("  -l, --list           list the contents of the queried package\n"));
 			addlist(_("  -m, --foreign        list installed packages not found in sync db(s) [filter]\n"));
+			addlist(_("  -n, --native         list installed packages only found in sync db(s) [filter]\n"));
 			addlist(_("  -o, --owns <file>    query the package that owns <file>\n"));
 			addlist(_("  -p, --file <package> query a package file instead of the database\n"));
 			addlist(_("  -q, --quiet          show less information for query and search\n"));
@@ -462,6 +463,7 @@ static int parsearg_query(int opt)
 		case 'k': config->op_q_check = 1; break;
 		case 'l': config->op_q_list = 1; break;
 		case 'm': config->op_q_foreign = 1; break;
+		case 'n': config->op_q_native = 1; break;
 		case 'o': config->op_q_owns = 1; break;
 		case 'p': config->op_q_isfile = 1; break;
 		case 'q': config->quiet = 1; break;
@@ -594,6 +596,7 @@ static int parseargs(int argc, char *argv[])
 		{"check",      no_argument,       0, 'k'},
 		{"list",       no_argument,       0, 'l'},
 		{"foreign",    no_argument,       0, 'm'},
+		{"native",     no_argument,       0, 'n'},
 		{"nosave",     no_argument,       0, 'n'},
 		{"owns",       no_argument,       0, 'o'},
 		{"file",       no_argument,       0, 'p'},
diff --git a/src/pacman/query.c b/src/pacman/query.c
index fc2c90c..059a078 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -380,6 +380,10 @@ static int filter(alpm_pkg_t *pkg)
 			alpm_pkg_get_reason(pkg) != ALPM_PKG_REASON_DEPEND) {
 		return 0;
 	}
+	/* check if this pkg is in a sync DB */
+	if(config->op_q_native && is_foreign(pkg)) {
+		return 0;
+	}
 	/* check if this pkg isn't in a sync DB */
 	if(config->op_q_foreign && !is_foreign(pkg)) {
 		return 0;
-- 
1.8.0



More information about the pacman-dev mailing list