Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Jul 2013 00:59:33 GMT
From:      mattbw@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r254434 - in soc2013/mattbw/backend: . actions query
Message-ID:  <201307090059.r690xXRZ071275@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mattbw
Date: Tue Jul  9 00:59:33 2013
New Revision: 254434
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254434

Log:
  remove some unnecessary bloat in queries, also apparently I forgot to commit my search work

Modified:
  soc2013/mattbw/backend/Makefile
  soc2013/mattbw/backend/actions.h
  soc2013/mattbw/backend/actions/get_details.c
  soc2013/mattbw/backend/actions/resolve.c
  soc2013/mattbw/backend/pk-backend-pkgng.c
  soc2013/mattbw/backend/pkgutils.c
  soc2013/mattbw/backend/pkgutils.h
  soc2013/mattbw/backend/query/core.c
  soc2013/mattbw/backend/query/match.c

Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/Makefile	Tue Jul  9 00:59:33 2013	(r254434)
@@ -15,7 +15,8 @@
 		actions/get_repo_list.c		\
 		actions/install_files.c		\
 		actions/install_packages.c	\
-		actions/resolve.c
+		actions/resolve.c		\
+		actions/search_names.c
 
 SRCS+=						\
 		query/core.c			\

Modified: soc2013/mattbw/backend/actions.h
==============================================================================
--- soc2013/mattbw/backend/actions.h	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/actions.h	Tue Jul  9 00:59:33 2013	(r254434)
@@ -34,6 +34,7 @@
 gboolean	install_files_thread(PkBackend *backend);
 gboolean	install_packages_thread(PkBackend *backend);
 gboolean	resolve_thread(PkBackend *backend);
+gboolean	search_names_thread(PkBackend *backend);
 gboolean	simulate_install_files_thread(PkBackend *backend);
 gboolean	simulate_install_packages_thread(PkBackend *backend);
 

Modified: soc2013/mattbw/backend/actions/get_details.c
==============================================================================
--- soc2013/mattbw/backend/actions/get_details.c	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/actions/get_details.c	Tue Jul  9 00:59:33 2013	(r254434)
@@ -25,7 +25,6 @@
 #include "../groups.h"		/* group_from_origin */
 #include "../licenses.h"	/* license_from_pkg */
 #include "../query.h"		/* query_... */
-
 #include "../actions.h"		/* get_details_thread prototype */
 
 static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES;

Modified: soc2013/mattbw/backend/actions/resolve.c
==============================================================================
--- soc2013/mattbw/backend/actions/resolve.c	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/actions/resolve.c	Tue Jul  9 00:59:33 2013	(r254434)
@@ -25,7 +25,7 @@
 #include "../pkgutils.h"	/* pkgutils_* */
 #include "../query.h"		/* query_* */
 #include "../utils.h"		/* INTENTIONALLY_IGNORE */
-#include "../actions.h"		/* Prototype */
+#include "../actions.h"		/* resolve_thread prototype */
 
 static gboolean emit(struct pkg *pkg, const gchar *id, struct query *q);
 

Modified: soc2013/mattbw/backend/pk-backend-pkgng.c
==============================================================================
--- soc2013/mattbw/backend/pk-backend-pkgng.c	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/pk-backend-pkgng.c	Tue Jul  9 00:59:33 2013	(r254434)
@@ -181,6 +181,16 @@
 }
 
 void
+pk_backend_search_names(PkBackend *backend, PkBitfield filters, gchar **values)
+{
+
+	INTENTIONALLY_IGNORE(filters);		/* retrieved from backend */
+	pk_backend_set_strv(backend, "values", values);
+	pk_backend_thread_create(backend, search_names_thread);
+}
+
+
+void
 pk_backend_simulate_install_files(PkBackend *backend, gchar **full_paths)
 {
 

Modified: soc2013/mattbw/backend/pkgutils.c
==============================================================================
--- soc2013/mattbw/backend/pkgutils.c	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/pkgutils.c	Tue Jul  9 00:59:33 2013	(r254434)
@@ -102,23 +102,6 @@
 }
 
 /*
- * Emits a package through the backend with the given info enum.
- */
-void
-pkgutils_emit(struct pkg *pkg, PkBackend *backend, PkInfoEnum info)
-{
-	char           *comment;
-	gchar          *id;
-
-	comment = id = NULL;
-
-	pkg_get(pkg, PKG_COMMENT, &comment);
-	id = pkgutils_pkg_to_id(pkg);
-	pk_backend_package(backend, info, id, comment);
-	g_free(id);
-}
-
-/*
  * Converts a package to a PackageID.
  */
 gchar          *
@@ -165,6 +148,47 @@
 }
 
 /*
+ * Emits a package through the backend with the given info enum.
+ */
+void
+pkgutils_emit(struct pkg *pkg, PkBackend *backend, PkInfoEnum info)
+{
+	char           *comment;
+	gchar          *id;
+
+	comment = id = NULL;
+
+	pkg_get(pkg, PKG_COMMENT, &comment);
+	id = pkgutils_pkg_to_id(pkg);
+	pk_backend_package(backend, info, id, comment);
+	g_free(id);
+}
+
+/*
+ * Emits a package if it satisfies the given filter set.
+ */
+void
+pkgutils_emit_filtered(struct pkg *pkg, PkBackend *backend, PkBitfield filters,
+    PkInfoEnum info)
+{
+	gboolean should_emit;
+
+	should_emit = TRUE;
+
+	if (pkg_type(pkg) == PKG_INSTALLED)
+		should_emit = pk_bitfield_contain(filters,
+		    PK_FILTER_ENUM_NOT_INSTALLED) ? FALSE : should_emit;
+	else
+		should_emit = pk_bitfield_contain(filters,
+		    PK_FILTER_ENUM_INSTALLED) ? FALSE : should_emit;
+	
+	/* TODO: more filters? */
+
+	if (should_emit)
+		pkgutils_emit(pkg, backend, info);
+}
+
+/*
  * Gets the PackageKit repository name for the (remote) package.
  * 
  * Currently this is actually the pkgng repository ident.  This might change.

Modified: soc2013/mattbw/backend/pkgutils.h
==============================================================================
--- soc2013/mattbw/backend/pkgutils.h	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/pkgutils.h	Tue Jul  9 00:59:33 2013	(r254434)
@@ -31,5 +31,6 @@
 gchar          *pkgutils_pkg_to_id(struct pkg *pkg);
 gchar          *pkgutils_pkg_to_id_through(struct pkg *pkg, const gchar **strv);
 void		pkgutils_emit(struct pkg *pkg, PkBackend *backend, PkInfoEnum info);
+void		pkgutils_emit_filtered(struct pkg *pkg, PkBackend *backend, PkBitfield filters, PkInfoEnum info);
 
 #endif				/* !_PKGNG_BACKEND_PKGUTILS_H_ */

Modified: soc2013/mattbw/backend/query/core.c
==============================================================================
--- soc2013/mattbw/backend/query/core.c	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/query/core.c	Tue Jul  9 00:59:33 2013	(r254434)
@@ -37,20 +37,11 @@
 	REPO_REMOTE
 };
 
-struct query_unpacked_source {
-	gboolean	skip_id_match;
-	const gchar    *name;
-	const gchar    *version;
-	const gchar    *arch;
-	const gchar    *data;
-	gchar         **strv;
-};
-
 struct query {
 	PkBackend      *backend;
 	struct pkgdb   *db;
 
-	struct query_unpacked_source *su;
+	gchar 	       **id_strv;
 
 	enum repo_type	rtype;
 
@@ -61,11 +52,11 @@
 static enum repo_type type_of_repo_name(const char *name);
 static gboolean	can_remote_iterate(struct query *q);
 static gchar   *match_pkg(struct pkg *pkg, struct query *q);
+static const gchar *query_repo(struct query *q);
+static gchar  **init_unpack_source(PkBackend *backend, struct query_source *s);
 static int	jobs_add_pkg(struct pkg_jobs *jobs, match_t type, struct pkg *pkg);
 static int	jobs_repo_from_query(struct pkg_jobs *jobs, struct query *q);
 static struct pkg *match_iterator(struct pkgdb_it *it, struct query *q, gchar **match_id_p);
-static struct query_unpacked_source *init_unpacked_source(PkBackend *backend, struct query_source *s);
-static void	free_unpacked_source(struct query_unpacked_source **su_p);
 
 /* Returns the backend stored inside the struct query. */
 PkBackend      *
@@ -132,6 +123,7 @@
 	int		match;
 	PkBitfield	filters;
 	const char     *name;
+	const char     *repo;
 	gchar          *match_id;
 	struct pkg     *pkg;
 	struct pkgdb   *db;
@@ -142,7 +134,8 @@
 	match_id = NULL;
 	pkg = NULL;
 	db = q->db;
-	name = q->su->name;
+	name = q->id_strv[PK_PACKAGE_ID_NAME];
+	repo = query_repo(q);
 
 	/*
 	 * If we're not given a specific repository in the PackageID, we want
@@ -170,7 +163,7 @@
 		try_remote = FALSE;
 
 	/* Next, try a remote search, again only if applicable. */
-	it = (try_remote ? pkgdb_rquery(db, name, match, q->su->data) : NULL);
+	it = (try_remote ? pkgdb_rquery(db, name, match, repo) : NULL);
 	if (it != NULL && can_remote_iterate(q))
 		pkg = match_iterator(it, q, &match_id);
 	pkgdb_it_free(it);
@@ -218,11 +211,11 @@
 	q->s = s;
 	q->t = t;
 
-	q->su = init_unpacked_source(backend, s);
-	if (q->su == NULL)
+	q->id_strv = init_unpack_source(backend, s);
+	if (q->id_strv == NULL)
 		goto cleanup;
 
-	q->rtype = type_of_repo_name(q->su->data);
+	q->rtype = type_of_repo_name(q->id_strv[PK_PACKAGE_ID_DATA]);
 	if (q->rtype == REPO_INVALID) {
 		ERR(backend, PK_ERROR_ENUM_REPO_NOT_FOUND, "no such repo");
 		goto cleanup;
@@ -250,8 +243,8 @@
 		 * the creator and not freed here.
 		 */
 
-		if (q->su != NULL)
-			free_unpacked_source(&(q->su));
+		if (q->id_strv != NULL)
+			g_strfreev(q->id_strv);
 
 		free(q);
 		*q_p = NULL;
@@ -287,7 +280,8 @@
 {
 	enum repo_type	rtype;
 
-	if (name == NULL)
+	/* Null or empty implies no specific repository */
+	if (name == NULL || name[0] == '\0')
 		rtype = REPO_ANY;
 	else if (strcmp(name, "installed") == 0)
 		rtype = REPO_LOCAL;
@@ -315,16 +309,12 @@
 	 * Stop pkg from catching fire if we try to load files from
 	 * non-installed packages.
 	 */
-	if (q->t->type == QUERY_EMIT) {
-		int		loading_files;
-
-		loading_files = (q->t->data.emit.load_flags & PKG_LOAD_FILES);
-		if (loading_files) {
-			ERR(q->backend,
-			    PK_ERROR_ENUM_CANNOT_GET_FILELIST,
-			    "cannot get files for remote package");
-			sane = FALSE;
-		}
+	if (q->t->type == QUERY_EMIT &&
+	    (q->t->data.emit.load_flags & PKG_LOAD_FILES)) {
+		ERR(q->backend,
+		    PK_ERROR_ENUM_CANNOT_GET_FILELIST,
+		    "cannot get files for remote package");
+		sane = FALSE;
 	}
 	return sane;
 }
@@ -345,7 +335,8 @@
 
 	match_id = pkgutils_pkg_to_id_through(pkg, pkg_id_bits);
 
-	if (q->su->skip_id_match == TRUE)
+	/* No need to do a PackageID match if we're looking for a name. */
+	if (q->s->type == QUERY_SINGLE_NAME)
 		matches = TRUE;
 	else {
 		/*
@@ -358,7 +349,7 @@
 		for (matches = TRUE, i = PK_PACKAGE_ID_NAME;
 		    matches == TRUE && i <= PK_PACKAGE_ID_DATA;
 		    i++)
-			matches = string_match((q->su->strv)[i],
+			matches = string_match((q->id_strv)[i],
 			    pkg_id_bits[i]);
 	}
 
@@ -371,6 +362,16 @@
 	return match_id;
 }
 
+/* Retrieves the repository for the query, or NULL if none is specified. */
+static const gchar *
+query_repo(struct query *q)
+{
+	const gchar       *repo;
+
+	repo = q->id_strv[PK_PACKAGE_ID_DATA];
+	return ((repo == NULL || repo[0] == '\0') ? NULL : repo);
+}
+
 /* Adds a single package to a jobs structure. */
 static int
 jobs_add_pkg(struct pkg_jobs *jobs, match_t type, struct pkg *pkg)
@@ -387,11 +388,13 @@
 jobs_repo_from_query(struct pkg_jobs *jobs, struct query *q)
 {
 	int		err;
+	gchar	       *repo;
 
-	if (q->su->data == NULL)
+	repo = q->id_strv[PK_PACKAGE_ID_DATA];
+	if (repo == NULL || repo[0] == '\0')
 		err = EPKG_OK;
 	else
-		err = pkg_jobs_set_repository(jobs, q->su->data);
+		err = pkg_jobs_set_repository(jobs, repo);
 
 	return err;
 }
@@ -432,65 +435,34 @@
 }
 
 /* Unpacks a query source into name/version/arch/data pointers. */
-static struct query_unpacked_source *
-init_unpacked_source(PkBackend *backend, struct query_source *s)
+static gchar **
+init_unpack_source(PkBackend *backend, struct query_source *s)
 {
-	struct query_unpacked_source *su;
-	gboolean	success;
-
-	success = FALSE;
+	gchar  **id_strv;
 
-	su = calloc(1, sizeof(struct query_unpacked_source));
-	if (su == NULL)
-		(void)pk_backend_error_code(backend,
-		    PK_ERROR_ENUM_OOM,
-		    "couldn't allocate unpacked source");
-	else if (s->type == QUERY_SINGLE_NAME) {
+	id_strv = NULL;
+	if (s->type == QUERY_SINGLE_NAME) {
 		/*
-		 * Expecting the string to be of the form "name" or
-		 * "name-version", no way to check which yet.
+		 * Make a snake-oil ID vector; we won't be doing rigid checking
+		 * against it so it doesn't matter that the version might be in
+		 * the name column etc.
 		 */
-		su->skip_id_match = TRUE;
-		su->name = s->data.single;
+		id_strv = g_new0(gchar *, 5);
 
-		success = TRUE;
+		id_strv[PK_PACKAGE_ID_NAME] = g_strdup(s->data.single);
+		id_strv[PK_PACKAGE_ID_VERSION] = g_strdup("");
+		id_strv[PK_PACKAGE_ID_ARCH] = g_strdup("");
+		id_strv[PK_PACKAGE_ID_DATA] = g_strdup("");
 	} else if (s->type == QUERY_SINGLE_ID) {
-		su->skip_id_match = FALSE;
-
-		success = split_id(s->data.single,
-		    &(su->strv),
-		    &(su->name),
-		    &(su->version),
-		    &(su->arch),
-		    &(su->data));
-		if (success == FALSE)
+		id_strv = pk_package_id_split(s->data.single);
+		if (id_strv == NULL)
 			(void)pk_backend_error_code(backend,
 			    PK_ERROR_ENUM_PACKAGE_ID_INVALID,
 			    "invalid package id");
 	} else
 		(void)pk_backend_error_code(backend,
 		    PK_ERROR_ENUM_INTERNAL_ERROR,
-		    "query_init_unpack_source given silly source type");
-
-	if (success == FALSE)
-		free_unpacked_source(&su);
-
-	return su;
-}
-
-/* Frees an unpacked source and all its owned contents. */
-static void
-free_unpacked_source(struct query_unpacked_source **su_p)
-{
-	struct query_unpacked_source *su;
+		    "init_unpack_source given silly source type");
 
-	su = (su_p == NULL ? NULL : *su_p);
-	if (su != NULL) {
-		/* This should free the other split ID pointer targets. */
-		if (su->strv != NULL)
-			g_strfreev(su->strv);
-
-		free(su);
-		*su_p = NULL;
-	}
+	return id_strv;
 }

Modified: soc2013/mattbw/backend/query/match.c
==============================================================================
--- soc2013/mattbw/backend/query/match.c	Mon Jul  8 21:25:12 2013	(r254433)
+++ soc2013/mattbw/backend/query/match.c	Tue Jul  9 00:59:33 2013	(r254434)
@@ -18,15 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include <string.h>
-#include <glib.h>
 #include "../pk-backend.h"
-#include "pkg.h"
-
-#include "../db.h"		/* open_remote_db */
-#include "../hash_traverse.h"	/* HASH_FOR */
-#include "../utils.h"		/* string_match */
-#include "../pkgutils.h"	/* pkgutils_... */
 
 #include "core.h"		/* query_... */
 #include "do.h"			/* query_do... */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307090059.r690xXRZ071275>