[gnome-builder] libide/tweaks: sort param specs for reproducibility



commit c38243631d5c338db7f915a161722330ebe9f663
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jul 31 12:19:23 2022 -0700

    libide/tweaks: sort param specs for reproducibility

 src/libide/tweaks/ide-tweaks-item.c        | 15 +++++++++++++++
 src/libide/tweaks/tests/test1/expected.xml | 14 +++++++-------
 src/libide/tweaks/tests/test2/expected.xml | 12 ++++++------
 3 files changed, 28 insertions(+), 13 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
index 02cd35df2..74c1206b4 100644
--- a/src/libide/tweaks/ide-tweaks-item.c
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -500,6 +500,16 @@ buildable_iface_init (GtkBuildableIface *iface)
   iface->set_id = ide_tweaks_item_set_buildable_id;
 }
 
+static int
+compare_pspec (gconstpointer a,
+               gconstpointer b)
+{
+  const GParamSpec * const *pspec_a = a;
+  const GParamSpec * const *pspec_b = b;
+
+  return g_strcmp0 ((*pspec_a)->name, (*pspec_b)->name);
+}
+
 void
 _ide_tweaks_item_printf (IdeTweaksItem *self,
                          GString       *string,
@@ -519,10 +529,15 @@ _ide_tweaks_item_printf (IdeTweaksItem *self,
 
   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (self), &n_pspecs);
 
+  qsort (pspecs, n_pspecs, sizeof (pspecs[0]), compare_pspec);
+
   for (guint i = 0; i < n_pspecs; i++)
     {
       GParamSpec *pspec = pspecs[i];
 
+      if (ide_str_equal0 (pspec->name, "id"))
+        continue;
+
       if (pspec->flags & G_PARAM_READABLE)
         {
           if (g_value_type_transformable (pspec->value_type, G_TYPE_STRING))
diff --git a/src/libide/tweaks/tests/test1/expected.xml b/src/libide/tweaks/tests/test1/expected.xml
index f291ef6e9..5edac498a 100644
--- a/src/libide/tweaks/tests/test1/expected.xml
+++ b/src/libide/tweaks/tests/test1/expected.xml
@@ -1,11 +1,11 @@
-<IdeTweaks id="IdeTweaks" id="IdeTweaks" sort-key="">
-  <IdeTweaksSection id="visual_section" id="visual_section" sort-key="">
-    <IdeTweaksPage id="appearance_page" id="appearance_page" sort-key="" icon-name="" title="Appearance">
-      <IdeTweaksGroup id="appearance_group" id="appearance_group" sort-key="" title="Appearance"/>
+<IdeTweaks id="IdeTweaks" sort-key="">
+  <IdeTweaksSection id="visual_section" sort-key="">
+    <IdeTweaksPage id="appearance_page" icon-name="" sort-key="" title="Appearance">
+      <IdeTweaksGroup id="appearance_group" sort-key="" title="Appearance"/>
     </IdeTweaksPage>
   </IdeTweaksSection>
-  <IdeTweaksSection id="foundry_section" id="foundry_section" sort-key="">
-    <IdeTweaksPage id="build_page" id="build_page" sort-key="" icon-name="" title="Build"/>
-    <IdeTweaksPage id="debugger_page" id="debugger_page" sort-key="" icon-name="builder-debugger-symbolic" 
title="Debugger"/>
+  <IdeTweaksSection id="foundry_section" sort-key="">
+    <IdeTweaksPage id="build_page" icon-name="" sort-key="" title="Build"/>
+    <IdeTweaksPage id="debugger_page" icon-name="builder-debugger-symbolic" sort-key="" title="Debugger"/>
   </IdeTweaksSection>
 </IdeTweaks>
diff --git a/src/libide/tweaks/tests/test2/expected.xml b/src/libide/tweaks/tests/test2/expected.xml
index 2cbba4cbe..e9a950440 100644
--- a/src/libide/tweaks/tests/test2/expected.xml
+++ b/src/libide/tweaks/tests/test2/expected.xml
@@ -1,9 +1,9 @@
-<IdeTweaks id="IdeTweaks" id="IdeTweaks" sort-key="">
-  <IdeTweaksSection id="programming_section" id="programming_section" sort-key="">
-    <IdeTweaksPage id="languages_page" id="languages_page" sort-key="" icon-name="" title="">
-      <IdeTweaksSubpageFactory id="language_subpage_factory" id="language_subpage_factory" sort-key="" 
model="GListStore<GtkSourceLanguage>">
-        <IdeTweaksSubpage id="language_subpage" id="language_subpage" sort-key="" title="">
-          <IdeTweaksGroup id="language_general_group" id="language_general_group" sort-key="test-key" 
title="General"/>
+<IdeTweaks id="IdeTweaks" sort-key="">
+  <IdeTweaksSection id="programming_section" sort-key="">
+    <IdeTweaksPage id="languages_page" icon-name="" sort-key="" title="">
+      <IdeTweaksSubpageFactory id="language_subpage_factory" model="GListStore<GtkSourceLanguage>" 
sort-key="">
+        <IdeTweaksSubpage id="language_subpage" icon-name="" sort-key="" title="">
+          <IdeTweaksGroup id="language_general_group" sort-key="test-key" title="General"/>
         </IdeTweaksSubpage>
       </IdeTweaksSubpageFactory>
     </IdeTweaksPage>


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