From owner-svn-soc-all@FreeBSD.ORG Thu Jul 11 03:59:03 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 9B452D18 for ; Thu, 11 Jul 2013 03:59:03 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 7F48B1E8E for ; Thu, 11 Jul 2013 03:59:03 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r6B3x3CE025240 for ; Thu, 11 Jul 2013 03:59:03 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r6B3x39R025236 for svn-soc-all@FreeBSD.org; Thu, 11 Jul 2013 03:59:03 GMT (envelope-from mattbw@FreeBSD.org) Date: Thu, 11 Jul 2013 03:59:03 GMT Message-Id: <201307110359.r6B3x39R025236@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254592 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jul 2013 03:59:03 -0000 Author: mattbw Date: Thu Jul 11 03:59:02 2013 New Revision: 254592 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254592 Log: attempt to use first category instead of port directory for package groups Modified: soc2013/mattbw/backend/actions/get_details.c soc2013/mattbw/backend/group.c soc2013/mattbw/backend/group.h Modified: soc2013/mattbw/backend/actions/get_details.c ============================================================================== --- soc2013/mattbw/backend/actions/get_details.c Thu Jul 11 02:10:23 2013 (r254591) +++ soc2013/mattbw/backend/actions/get_details.c Thu Jul 11 03:59:02 2013 (r254592) @@ -55,7 +55,6 @@ { bool success; const char *description; - const char *origin; const char *www; int64_t flatsize; guint flatsize_u; @@ -63,12 +62,11 @@ query_set_percentage(q, 0); /* Information not already part of the PackageID */ - description = origin = www = NULL; + description = www = NULL; flatsize = 0; pkg_get(pkg, PKG_DESC, &description, PKG_FLATSIZE, &flatsize, - PKG_ORIGIN, &origin, PKG_WWW, &www); flatsize_u = (guint)CLAMP(flatsize, 0, G_MAXUINT); @@ -76,7 +74,7 @@ success = pk_backend_details(query_backend(q), id, license_name_from_pkg(pkg), - group_from_origin(origin), + group_of_pkg(pkg), description, www, flatsize_u) == TRUE; Modified: soc2013/mattbw/backend/group.c ============================================================================== --- soc2013/mattbw/backend/group.c Thu Jul 11 02:10:23 2013 (r254591) +++ soc2013/mattbw/backend/group.c Thu Jul 11 03:59:02 2013 (r254592) @@ -21,11 +21,11 @@ #include /* assert */ #include /* bool, true, false */ #include /* NULL */ -#include /* strchr, strdup */ +#include /* strchr, strcmp, strdup */ #include /* struct sbuf, sbuf_... */ -#include "glib.h" /* g_strcmp0 */ #include "pk-backend.h" /* PkGroupEnum, PK_... */ +#include "pkg.h" /* pkg_... */ #include "group_map.h" /* group_mappings */ #include "group.h" /* group_... */ @@ -66,7 +66,7 @@ /* * Is this a valid origin (did it have a separator)? If not, we want - * the default group. If so, then the number of chars between the + * the default group. If so, then the number of chars between the * origin start and the separator mark the port directory name we * want to use. */ @@ -79,6 +79,42 @@ } /* + * Maps from packages to PackageKit groups. PKG_LOAD_CATEGORIES must have been + * set whilst loading the package for this to work properly. + */ +PkGroupEnum +group_of_pkg(struct pkg *pkg) +{ + PkGroupEnum group; + struct pkg_category *category; + + assert(pkg != NULL); + + /* Default failure state group. */ + group = PK_GROUP_ENUM_UNKNOWN; + + /* Take the first category only. */ + category = NULL; + if (pkg_categories(pkg, &category) == EPKG_OK) { + assert(category != NULL); + + group = group_from_port_dir(pkg_category_name(category)); + } else { + const char *origin; + + /* Fallback to checking the origin. */ + origin = NULL; + if (pkg_get(pkg, PKG_ORIGIN, &origin) == EPKG_OK) { + assert(origin != NULL); + + group = group_from_origin(origin); + } + } + + return group; +} + +/* * Constructs an Extended Regular Expression matching any package origins * that lie within the given group. The regex should be freed using free(3). */ Modified: soc2013/mattbw/backend/group.h ============================================================================== --- soc2013/mattbw/backend/group.h Thu Jul 11 02:10:23 2013 (r254591) +++ soc2013/mattbw/backend/group.h Thu Jul 11 03:59:02 2013 (r254592) @@ -22,9 +22,11 @@ #define _PKGNG_BACKEND_GROUPS_H_ #include "pk-backend.h" +#include "pkg.h" PkBitfield group_bitfield(void); PkGroupEnum group_from_origin(const char *origin); +PkGroupEnum group_of_pkg(struct pkg *pkg); char * group_list_to_origin_regex(unsigned int groupc, PkGroupEnum *groupv); #endif /* _PKGNG_BACKEND_GROUPS_H_ */