Re: small change in "gconftool-2 --dump" behaviour



On Thu, 2004-04-01 at 15:47, Mark McLoughlin wrote:
> Hey,
> 	I've just committed (to gnome-2-6 and HEAD) the tiny patch below which
> changes the behaviour of --dump slightly.
> 
> 	With this change, if the value of the key is the schema default (i.e.
> its unset), we don't dump the actual value. Because the schema name is
> included in the dump of the key no information is lost and now dumping
> an unset key and then loading the dump should give you exactly what you
> had before.

	I changed my mind on this. In most cases you do actually want to the
schema default and the behaviour of all the other gconftool-2 options
uses the schema default. I've reverted the change.

	However, I've added a --ignore-schema-defaults argument which can be
used with any gconftool-2 option that gets the value of a key.

Cheers,
Mark.

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gconf/ChangeLog,v
retrieving revision 1.504
diff -u -p -r1.504 ChangeLog
--- ChangeLog	2 Apr 2004 18:02:13 -0000	1.504
+++ ChangeLog	5 Apr 2004 19:13:00 -0000
@@ -0,0 +1,15 @@
+2004-04-05  Mark McLoughlin  <mark skynet ie>
+
+	Revert the --dump behaviour change (not dumping schema defaults)
+	and add a --ignore-schema-defaults argument which applies to
+	all arguments which get the value of a key.
+
+	* gconf/gconftool.c:
+	(main): check that --ignore-schema-defaults is being used with
+	an option which gets a value.
+	(list_pairs_in_dir), (dump_entries_in_dir):
+	respect --ignore-schema-defaults.
+	(get_maybe_without_default): helper function.
+	(do_get), (do_get_type), (do_get_list_size), (do_get_list_element):
+	respect --ignore-schema-defaults.
+
Index: gconf/gconftool.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconftool.c,v
retrieving revision 1.90
diff -u -p -r1.90 gconftool.c
--- gconf/gconftool.c	2 Apr 2004 18:02:14 -0000	1.90
+++ gconf/gconftool.c	5 Apr 2004 19:13:02 -0000
@@ -70,6 +70,7 @@ static int long_docs_mode = FALSE;
 static int schema_name_mode = FALSE;
 static int associate_schema_mode = FALSE;
 static int dissociate_schema_mode = FALSE;
+static int ignore_schema_defaults = FALSE;
 static int default_source_mode = FALSE;
 static int recursive_unset_mode = FALSE;
 static int do_version = FALSE;
@@ -410,6 +411,15 @@ struct poptOption options[] = {
     NULL
   },
   {
+    "ignore-schema-defaults",
+    '\0',
+    POPT_ARG_NONE,
+    &ignore_schema_defaults,
+    0,
+    N_("Ignore schema defaults when reading values."),
+    NULL
+  },
+  {
     "get-default-source",
     '\0',
     POPT_ARG_NONE,
@@ -588,7 +598,7 @@ main (int argc, char** argv)
     {
       g_printerr (_("--set_schema should not be used with --get, --set, --unset, --all-entries, --all-dirs\n"));
       return 1;
-    }  
+    }
 
   if ((value_type != NULL) && !(set_mode || set_schema_mode))
     {
@@ -602,6 +612,14 @@ main (int argc, char** argv)
       return 1;
     }
 
+  if (ignore_schema_defaults && !(get_mode || all_entries_mode ||
+				  dump_values || recursive_list ||
+				  get_list_size_mode || get_list_element_mode))
+    {
+      g_printerr (_("--ignore-schema-defaults is only relevant with --get, --all-entries, --dump, --recursive-list, --get-list-size or --get-list-element\n"));
+      return 1;
+    }
+
   if (ping_gconfd && (shutdown_gconfd || set_mode || get_mode || unset_mode ||
                       all_subdirs_mode || all_entries_mode || recursive_list || 
                       get_type_mode || get_list_size_mode || get_list_element_mode ||
@@ -1226,7 +1244,8 @@ list_pairs_in_dir(GConfEngine* conf, con
           GConfEntry* pair = tmp->data;
           gchar* s;
 
-          if (gconf_entry_get_value (pair))
+          if (gconf_entry_get_value (pair) && 
+	      (!ignore_schema_defaults || !gconf_entry_get_is_default (pair)))
             s = gconf_value_to_string (gconf_entry_get_value (pair));
           else
             s = g_strdup(_("(no value set)"));
@@ -1497,8 +1516,8 @@ dump_entries_in_dir(GConfEngine* conf, c
         g_print ("      <schema_key>%s</schema_key>\n",
 		 get_key_relative(gconf_entry_get_schema_name(entry), base_dir));
 
-      /* don't print the value if its just the schema default */
-      if (entry->value && !gconf_entry_get_is_default(entry))
+      if (entry->value && 
+	  (!ignore_schema_defaults || !gconf_entry_get_is_default(entry)))
         print_value_in_xml(entry->value, 6);
 
       g_print ("    </entry>\n");
@@ -1542,6 +1561,21 @@ do_spawn_daemon(GConfEngine* conf)
     }
 }
 
+static inline GConfValue *
+get_maybe_without_default (GConfEngine  *conf,
+			   const gchar  *key,
+			   GError      **err)
+{
+  if (!ignore_schema_defaults)
+    {
+      return gconf_engine_get (conf, key, err);
+    }
+  else
+    {
+      return gconf_engine_get_without_default (conf, key, err);
+    }
+}
+
 static int
 do_get(GConfEngine* conf, const gchar** args)
 {
@@ -1560,7 +1594,7 @@ do_get(GConfEngine* conf, const gchar** 
 
       err = NULL;
 
-      value = gconf_engine_get (conf, *args, &err);
+      value = get_maybe_without_default (conf, *args, &err);
          
       if (value != NULL)
         {
@@ -1819,7 +1853,7 @@ do_get_type(GConfEngine* conf, const gch
 
       err = NULL;
 
-      value = gconf_engine_get (conf, *args, &err);
+      value = get_maybe_without_default (conf, *args, &err);
          
       if (value != NULL)
 	{
@@ -1857,7 +1891,7 @@ do_get_list_size(GConfEngine* conf, cons
       return 1;
     }
 
-  list = gconf_engine_get (conf, *args, &err);
+  list = get_maybe_without_default (conf, *args, &err);
 
   if (list == NULL)
     {
@@ -1902,7 +1936,7 @@ do_get_list_element(GConfEngine* conf, c
       return 1;
     }
 
-  list = gconf_engine_get (conf, *args, &err);
+  list = get_maybe_without_default (conf, *args, &err);
 
   if (list == NULL)
     {





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