[gnome-software] Move the duplicate filter out of GsPluginLoader so that it can be tested
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Move the duplicate filter out of GsPluginLoader so that it can be tested
- Date: Tue, 8 Oct 2013 17:05:19 +0000 (UTC)
commit 4bf8608377396973a7eb88aa5ade95d76cf93bfd
Author: Richard Hughes <richard hughsie com>
Date: Tue Oct 8 17:26:25 2013 +0100
Move the duplicate filter out of GsPluginLoader so that it can be tested
src/gs-plugin-loader.c | 52 +++++------------------------------------------
src/gs-plugin.c | 40 ++++++++++++++++++++++++++++++++++++
src/gs-plugin.h | 1 +
src/gs-self-test.c | 11 ++++++++++
4 files changed, 58 insertions(+), 46 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index ced2116..3fdb222 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -149,42 +149,6 @@ out:
}
/**
- * gs_plugin_loader_list_uniq:
- **/
-static GList *
-gs_plugin_loader_list_uniq (GsPluginLoader *plugin_loader, GList *list)
-{
- const gchar *id;
- GHashTable *hash;
- GList *l;
- GList *list_new = NULL;
- GsApp *app;
- GsApp *found;
-
- /* create a new list with just the unique items */
- hash = g_hash_table_new (g_str_hash, g_str_equal);
- for (l = list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- id = gs_app_get_id (app);
- if (id == NULL) {
- gs_plugin_add_app (&list_new, app);
- continue;
- }
- found = g_hash_table_lookup (hash, id);
- if (found == NULL) {
- gs_plugin_add_app (&list_new, app);
- g_hash_table_insert (hash, (gpointer) id, GUINT_TO_POINTER (1));
- continue;
- }
- g_debug ("ignoring duplicate %s", id);
- }
-
- gs_plugin_list_free (list);
- g_hash_table_unref (hash);
- return list_new;
-}
-
-/**
* gs_plugin_loader_list_dedupe:
**/
static void
@@ -307,8 +271,8 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
if (!ret)
goto out;
- /* remove duplicates */
- list = gs_plugin_loader_list_uniq (plugin_loader, list);
+ /* filter package list */
+ gs_plugin_list_filter_duplicates (&list);
/* profile */
gs_profile_stop (plugin_loader->priv->profile, profile_id_parent);
@@ -566,8 +530,8 @@ gs_plugin_loader_get_updates_thread_cb (GSimpleAsyncResult *res,
goto out;
}
- /* remove duplicates */
- state->list = gs_plugin_loader_list_uniq (plugin_loader, state->list);
+ /* filter package list */
+ gs_plugin_list_filter_duplicates (&state->list);
/* dedupe applications we already know about */
gs_plugin_loader_list_dedupe (plugin_loader, state->list);
@@ -1095,10 +1059,8 @@ gs_plugin_loader_search_thread_cb (GSimpleAsyncResult *res,
goto out;
}
- /* remove duplicates */
- state->list = gs_plugin_loader_list_uniq (plugin_loader, state->list);
-
/* filter package list */
+ gs_plugin_list_filter_duplicates (&state->list);
gs_plugin_list_filter (&state->list, gs_plugin_loader_app_is_valid, NULL);
gs_plugin_list_filter (&state->list, gs_plugin_loader_get_app_is_compatible, plugin_loader);
if (state->list == NULL) {
@@ -1414,10 +1376,8 @@ gs_plugin_loader_get_category_apps_thread_cb (GSimpleAsyncResult *res,
goto out;
}
- /* remove duplicates */
- state->list = gs_plugin_loader_list_uniq (plugin_loader, state->list);
-
/* filter package list */
+ gs_plugin_list_filter_duplicates (&state->list);
gs_plugin_list_filter (&state->list, gs_plugin_loader_app_is_non_system, NULL);
gs_plugin_list_filter (&state->list, gs_plugin_loader_app_is_valid, NULL);
gs_plugin_list_filter (&state->list, gs_plugin_loader_get_app_is_compatible, plugin_loader);
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 0754902..0157078 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -94,6 +94,46 @@ gs_plugin_list_filter (GList **list, GsPluginListFilter func, gpointer user_data
/**
* gs_plugin_list_copy:
**/
+void
+gs_plugin_list_filter_duplicates (GList **list)
+{
+ GHashTable *hash;
+ GList *l;
+ GList *new = NULL;
+ GsApp *app;
+ GsApp *found;
+ const gchar *id;
+
+ g_return_if_fail (list != NULL);
+
+ /* create a new list with just the unique items */
+ hash = g_hash_table_new (g_str_hash, g_str_equal);
+ for (l = *list; l != NULL; l = l->next) {
+ app = GS_APP (l->data);
+ id = gs_app_get_id (app);
+ if (id == NULL) {
+ gs_plugin_add_app (&new, app);
+ continue;
+ }
+ found = g_hash_table_lookup (hash, id);
+ if (found == NULL) {
+ gs_plugin_add_app (&new, app);
+ g_hash_table_insert (hash, (gpointer) id,
+ GUINT_TO_POINTER (1));
+ continue;
+ }
+ g_debug ("ignoring duplicate %s", id);
+ }
+ g_hash_table_unref (hash);
+
+ /* replace the list */
+ gs_plugin_list_free (*list);
+ *list = new;
+}
+
+/**
+ * gs_plugin_list_copy:
+ **/
GList *
gs_plugin_list_copy (GList *list)
{
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index bd88347..0a10934 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -113,6 +113,7 @@ GList *gs_plugin_list_copy (GList *list);
void gs_plugin_list_filter (GList **list,
GsPluginListFilter func,
gpointer user_data);
+void gs_plugin_list_filter_duplicates (GList **list);
void gs_plugin_status_update (GsPlugin *plugin,
GsApp *app,
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index f3a4483..a8c9e1a 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -75,6 +75,17 @@ gs_plugin_func (void)
gs_plugin_list_filter (&list_remove, gs_plugin_list_filter_cb, NULL);
g_assert_cmpint (g_list_length (list_remove), ==, 1);
g_assert_cmpstr (gs_app_get_id (GS_APP (list_remove->data)), ==, "b");
+
+ /* test removing duplicates */
+ app = gs_app_new ("b");
+ gs_plugin_add_app (&list_remove, app);
+ g_object_unref (app);
+ app = gs_app_new ("b");
+ gs_plugin_add_app (&list_remove, app);
+ g_object_unref (app);
+ gs_plugin_list_filter_duplicates (&list_remove);
+ g_assert_cmpint (g_list_length (list_remove), ==, 1);
+ g_assert_cmpstr (gs_app_get_id (GS_APP (list_remove->data)), ==, "b");
gs_plugin_list_free (list_remove);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]