[ostree] libotutil: Allow no variant in ot_util_variant_builder_from_variant()



commit fdda36eb774c30ea43a622043259bce862a42de8
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Mar 2 14:55:01 2015 -0500

    libotutil: Allow no variant in ot_util_variant_builder_from_variant()
    
    For programming convenience in cases where we may or may not have a
    GVariant to initialize the builder with.

 src/libostree/ostree-repo-commit.c |   18 +++++-------------
 src/libotutil/ot-variant-utils.c   |   16 ++++++++++------
 2 files changed, 15 insertions(+), 19 deletions(-)
---
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 9d8bf8b..941b08f 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -369,14 +369,8 @@ add_size_index_to_metadata (OstreeRepo        *self,
   gboolean ret = FALSE;
   gs_unref_variant_builder GVariantBuilder *builder = NULL;
     
-  if (original_metadata)
-    {
-      builder = ot_util_variant_builder_from_variant (original_metadata, G_VARIANT_TYPE ("a{sv}"));
-    }
-  else
-    {
-      builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
-    }
+  /* original_metadata may be NULL */
+  builder = ot_util_variant_builder_from_variant (original_metadata, G_VARIANT_TYPE ("a{sv}"));
 
   if (self->object_sizes &&
       g_hash_table_size (self->object_sizes) > 0)
@@ -2189,11 +2183,9 @@ get_modified_xattrs (OstreeRepo                       *self,
         {
           GVariantBuilder *builder;
 
-          if (ret_xattrs)
-            builder = ot_util_variant_builder_from_variant (ret_xattrs,
-                                                            G_VARIANT_TYPE ("a(ayay)"));
-          else
-            builder = g_variant_builder_new (G_VARIANT_TYPE ("a(ayay)"));
+          /* ret_xattrs may be NULL */
+          builder = ot_util_variant_builder_from_variant (ret_xattrs,
+                                                          G_VARIANT_TYPE ("a(ayay)"));
 
           g_variant_builder_add_value (builder,
                                        g_variant_new ("(@ay ay)",
diff --git a/src/libotutil/ot-variant-utils.c b/src/libotutil/ot-variant-utils.c
index 5a8ca99..28fd49b 100644
--- a/src/libotutil/ot-variant-utils.c
+++ b/src/libotutil/ot-variant-utils.c
@@ -260,16 +260,20 @@ ot_util_variant_builder_from_variant (GVariant            *variant,
                                       const GVariantType  *type)
 {
   GVariantBuilder *builder = NULL;
-  gint i, n;
   
   builder = g_variant_builder_new (type);
   
-  n = g_variant_n_children (variant);
-  for (i = 0; i < n; i++)
+  if (variant != NULL)
     {
-      GVariant *child = g_variant_get_child_value (variant, i);
-      g_variant_builder_add_value (builder, child);
-      g_variant_unref (child);
+      gint i, n;
+
+      n = g_variant_n_children (variant);
+      for (i = 0; i < n; i++)
+        {
+          GVariant *child = g_variant_get_child_value (variant, i);
+          g_variant_builder_add_value (builder, child);
+          g_variant_unref (child);
+        }
     }
     
   return builder;


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