[dconf/patch/engine-check: 2/5] common: factor out dconf_gvdb_utils_changeset_from_table



commit 1038c86cb6f9ccc3e0e1542670ea45682655daf0
Author: Daniel Playfair Cal <daniel playfair cal gmail com>
Date:   Mon Jan 6 12:10:58 2020 +1100

    common: factor out dconf_gvdb_utils_changeset_from_table

 common/dconf-gvdb-utils.c | 64 +++++++++++++++++++++++++----------------------
 common/dconf-gvdb-utils.h |  2 ++
 2 files changed, 36 insertions(+), 30 deletions(-)
---
diff --git a/common/dconf-gvdb-utils.c b/common/dconf-gvdb-utils.c
index e70e2dc..a325507 100644
--- a/common/dconf-gvdb-utils.c
+++ b/common/dconf-gvdb-utils.c
@@ -31,6 +31,37 @@
 #include <glib/gstdio.h>
 #include <string.h>
 
+DConfChangeset *
+dconf_gvdb_utils_changeset_from_table (GvdbTable *table)
+{
+  DConfChangeset *database = dconf_changeset_new_database (NULL);
+  gchar **names;
+  gsize n_names;
+  gsize i;
+
+  names = gvdb_table_get_names (table, &n_names);
+  for (i = 0; i < n_names; i++)
+    {
+      if (dconf_is_key (names[i], NULL))
+        {
+          GVariant *value;
+
+          value = gvdb_table_get_value (table, names[i]);
+
+          if (value != NULL)
+            {
+              dconf_changeset_set (database, names[i], value);
+              g_variant_unref (value);
+            }
+        }
+
+      g_free (names[i]);
+    }
+
+  g_free (names);
+  return database;
+}
+
 DConfChangeset *
 dconf_gvdb_utils_read_and_back_up_file (const gchar  *filename,
                                         gboolean     *file_missing,
@@ -95,38 +126,11 @@ dconf_gvdb_utils_read_and_back_up_file (const gchar  *filename,
       return NULL;
     }
 
-  /* Only allocate once we know we are in a non-error situation */
-  database = dconf_changeset_new_database (NULL);
-
   /* Fill the table up with the initial state */
   if (table != NULL)
-    {
-      gchar **names;
-      gsize n_names;
-      gsize i;
-
-      names = gvdb_table_get_names (table, &n_names);
-      for (i = 0; i < n_names; i++)
-        {
-          if (dconf_is_key (names[i], NULL))
-            {
-              GVariant *value;
-
-              value = gvdb_table_get_value (table, names[i]);
-
-              if (value != NULL)
-                {
-                  dconf_changeset_set (database, names[i], value);
-                  g_variant_unref (value);
-                }
-            }
-
-          g_free (names[i]);
-        }
-
-      gvdb_table_free (table);
-      g_free (names);
-    }
+    database = dconf_gvdb_utils_changeset_from_table (table);
+  else
+    database = dconf_changeset_new_database (NULL);
 
   if (file_missing)
     *file_missing = (table == NULL);
diff --git a/common/dconf-gvdb-utils.h b/common/dconf-gvdb-utils.h
index 8d73133..4bd4cd9 100644
--- a/common/dconf-gvdb-utils.h
+++ b/common/dconf-gvdb-utils.h
@@ -21,8 +21,10 @@
 #ifndef __dconf_gvdb_utils_h__
 #define __dconf_gvdb_utils_h__
 
+#include "../gvdb/gvdb-reader.h"
 #include "./dconf-changeset.h"
 
+DConfChangeset *                dconf_gvdb_utils_changeset_from_table   (GvdbTable       *table);
 DConfChangeset *                dconf_gvdb_utils_read_and_back_up_file  (const gchar     *filename,
                                                                          gboolean        *file_missing,
                                                                          GError         **error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]