socsvn commit: r257007 - in soc2013/mattbw/backend: . query
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Fri Sep 6 12:08:31 UTC 2013
Author: mattbw
Date: Fri Sep 6 12:08:31 2013
New Revision: 257007
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257007
Log:
Split repository functions into another file.
This is for consistency and also so the ones that were originally in utils
can be unit tested.
Added:
soc2013/mattbw/backend/repo.c
soc2013/mattbw/backend/repo.h
Modified:
soc2013/mattbw/backend/Makefile
soc2013/mattbw/backend/jobs.c
soc2013/mattbw/backend/pkgutils.c
soc2013/mattbw/backend/query/match.c
soc2013/mattbw/backend/utils.c
soc2013/mattbw/backend/utils.h
Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile Fri Sep 6 10:40:38 2013 (r257006)
+++ soc2013/mattbw/backend/Makefile Fri Sep 6 12:08:31 2013 (r257007)
@@ -32,6 +32,7 @@
licenses.c \
namever.c \
pkgutils.c \
+ repo.c \
search.c \
utils.c
SRCS+= \
Modified: soc2013/mattbw/backend/jobs.c
==============================================================================
--- soc2013/mattbw/backend/jobs.c Fri Sep 6 10:40:38 2013 (r257006)
+++ soc2013/mattbw/backend/jobs.c Fri Sep 6 12:08:31 2013 (r257007)
@@ -34,7 +34,8 @@
#include "jobs/check.h" /* jobs_check_... */
#include "namever.h" /* namever_* */
#include "pkgutils.h" /* pkgutils_... */
-#include "utils.h" /* ERR, type_of_repo_name */
+#include "repo.h" /* repo_... */
+#include "utils.h" /* ERR */
static const char *APPLY_ERRORS[] = {
"This shouldn't occur and is a bug.", /* EPKG_OK */
@@ -95,7 +96,7 @@
success = true;
- type = type_of_repo_name(reponame);
+ type = repo_type(reponame);
if (type == REPO_INVALID) {
success = false;
} else if (type == REPO_REMOTE) {
Modified: soc2013/mattbw/backend/pkgutils.c
==============================================================================
--- soc2013/mattbw/backend/pkgutils.c Fri Sep 6 10:40:38 2013 (r257006)
+++ soc2013/mattbw/backend/pkgutils.c Fri Sep 6 12:08:31 2013 (r257007)
@@ -28,9 +28,6 @@
#include "pkgutils.h" /* Prototypes */
#include "utils.h" /* INTENTIONALLY_IGNORE */
-
-static const char *repo_of_remote_package(struct pkg *pkg);
-
/*
* Package utility functions.
*
@@ -195,61 +192,3 @@
return matches_filters;
}
-/*
- * Gets the PackageKit repository name for the package.
- */
-const char *
-pkgutils_pkg_to_pk_repo(struct pkg *pkg)
-{
- const char *repo;
-
- assert(pkg != NULL);
-
- /*
- * clang complains about this redundant assignment, but
- * gcc complains if it doesn't exist.
- */
-#ifndef __clang__
- repo = "";
-#endif /* __clang */
-
- switch (pkg_type(pkg)) {
- case PKG_OLD_FILE:
- case PKG_FILE:
- repo = "local";
- break;
- case PKG_INSTALLED:
- repo = "installed";
- break;
- case PKG_REMOTE:
- repo = repo_of_remote_package(pkg);
- break;
- case PKG_NONE:
- repo = "unknown";
- break;
- }
-
- assert(repo != NULL);
- return repo;
-}
-
-/*
- * Gets the PackageKit repository name for the (remote) package.
- *
- * Currently this is the pkgng repository name (not the ident as was previously
- * the case).
- *
- * This does not need to be freed (possibly, TODO: check).
- */
-static const char *
-repo_of_remote_package(struct pkg *pkg)
-{
- const char *repo_name;
-
- assert(pkg != NULL);
- assert(pkg_type(pkg) == PKG_REMOTE);
-
- repo_name = NULL;
- pkg_get(pkg, PKG_REPONAME, &repo_name);
- return repo_name;
-}
Modified: soc2013/mattbw/backend/query/match.c
==============================================================================
--- soc2013/mattbw/backend/query/match.c Fri Sep 6 10:40:38 2013 (r257006)
+++ soc2013/mattbw/backend/query/match.c Fri Sep 6 12:08:31 2013 (r257007)
@@ -24,6 +24,7 @@
#include "pkg.h" /* struct pkg... */
#include "../namever.h" /* namever_... */
+#include "../repo.h" /* repo_... */
#include "../utils.h" /* type_of_repo_name, enum repo_type */
#include "check.h" /* query_check... */
#include "find.h" /* query_find_... */
@@ -79,7 +80,7 @@
{
bool try_local;
bool try_remote;
- enum repo_type repo_type;
+ enum repo_type type;
struct pkg *package;
assert(query_id != NULL);
@@ -90,9 +91,9 @@
* to try searching locally first and then remotely; otherwise which
* database we query depends on the repository we have been given.
*/
- repo_type = type_of_repo_name(query_id->repo);
- try_local = (repo_type != REPO_REMOTE);
- try_remote = (repo_type != REPO_LOCAL);
+ type = repo_type(query_id->repo);
+ try_local = (type != REPO_REMOTE);
+ try_remote = (type != REPO_LOCAL);
package = NULL;
if (try_local) {
Added: soc2013/mattbw/backend/repo.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/repo.c Fri Sep 6 12:08:31 2013 (r257007)
@@ -0,0 +1,111 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* Functions for dealing with PackageKit repositories. */
+
+#include <assert.h>
+#include <string.h>
+
+#include "pkg.h" /* pkg_..., struct pkg */
+#include "repo.h" /* repo_... */
+
+static const char *repo_of_remote_package(struct pkg *pkg);
+
+/*
+ * Finds the type of the given PackageKit repository name.
+ */
+enum repo_type
+repo_type(const char *name)
+{
+ enum repo_type rtype;
+
+ /* 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;
+ } else if (pkg_repo_find_ident(pkg_repo_ident_from_name(name))
+ != NULL) {
+ rtype = REPO_REMOTE;
+ } else {
+ rtype = REPO_INVALID;
+ }
+
+ return rtype;
+}
+
+/*
+ * Gets the PackageKit repository name for the package.
+ */
+const char *
+repo_of_package(struct pkg *package)
+{
+ const char *repo;
+
+ assert(package != NULL);
+
+ /*
+ * clang complains about this redundant assignment, but
+ * gcc complains if it doesn't exist.
+ */
+#ifndef __clang__
+ repo = "";
+#endif /* __clang */
+
+ switch (pkg_type(package)) {
+ case PKG_OLD_FILE:
+ case PKG_FILE:
+ repo = "local";
+ break;
+ case PKG_INSTALLED:
+ repo = "installed";
+ break;
+ case PKG_REMOTE:
+ repo = repo_of_remote_package(package);
+ break;
+ case PKG_NONE:
+ repo = "unknown";
+ break;
+ }
+
+ assert(repo != NULL);
+ return repo;
+}
+
+/*
+ * Gets the PackageKit repository name for the (remote) package.
+ *
+ * Currently this is the pkgng repository name (not the ident as was previously
+ * the case).
+ *
+ * This does not need to be freed (possibly, TODO: check).
+ */
+static const char *
+repo_of_remote_package(struct pkg *pkg)
+{
+ const char *repo_name;
+
+ assert(pkg != NULL);
+ assert(pkg_type(pkg) == PKG_REMOTE);
+
+ repo_name = NULL;
+ pkg_get(pkg, PKG_REPONAME, &repo_name);
+ return repo_name;
+}
Added: soc2013/mattbw/backend/repo.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/repo.h Fri Sep 6 12:08:31 2013 (r257007)
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _PKGNG_BACKEND_REPO_H_
+#define _PKGNG_BACKEND_REPO_H_
+
+#include "pkg.h"
+
+enum repo_type {
+ REPO_INVALID,
+ REPO_ANY,
+ REPO_LOCAL,
+ REPO_REMOTE
+};
+
+enum repo_type repo_type(const char *name);
+const char *repo_of_package(struct pkg *package);
+
+#endif /* !_PKGNG_BACKEND_REPO_H_ */
Modified: soc2013/mattbw/backend/utils.c
==============================================================================
--- soc2013/mattbw/backend/utils.c Fri Sep 6 10:40:38 2013 (r257006)
+++ soc2013/mattbw/backend/utils.c Fri Sep 6 12:08:31 2013 (r257007)
@@ -30,29 +30,6 @@
#include "utils.h" /* prototypes */
/*
- * Finds the type of the given PackageKit repository name.
- */
-enum repo_type
-type_of_repo_name(const char *name)
-{
- enum repo_type rtype;
-
- /* 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;
- } else if (pkg_repo_find_ident(pkg_repo_ident_from_name(name))
- != NULL) {
- rtype = REPO_REMOTE;
- } else {
- rtype = REPO_INVALID;
- }
-
- return rtype;
-}
-
-/*
* Retrieves PackageIDs from the backend, as well as the total number of them.
*/
gchar **
Modified: soc2013/mattbw/backend/utils.h
==============================================================================
--- soc2013/mattbw/backend/utils.h Fri Sep 6 10:40:38 2013 (r257006)
+++ soc2013/mattbw/backend/utils.h Fri Sep 6 12:08:31 2013 (r257007)
@@ -25,20 +25,12 @@
#include <glib.h> /* gchar, guint */
#include "pk-backend.h" /* PkBackend */
-enum repo_type {
- REPO_INVALID,
- REPO_ANY,
- REPO_LOCAL,
- REPO_REMOTE
-};
-
#define INTENTIONALLY_IGNORE(x) (void)(x)
#define STATUS(backend, status) \
(void)pk_backend_set_status((backend), (status))
#define ERR(backend, type, msg) \
(void)pk_backend_error_code((backend), (type), (msg))
-enum repo_type type_of_repo_name(const char *name);
gchar **get_package_ids(PkBackend *backend, guint *count_p);
gchar **get_strv_and_length(PkBackend *backend, const char *name, guint *count_p);
More information about the svn-soc-all
mailing list