summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2015-02-21 10:55:00 -0800
committerDan Nicholson <dbn.lists@gmail.com>2015-02-21 10:55:00 -0800
commit818aeace3b08d731d104d5ef9b1d5e3c34dd4192 (patch)
tree2faa8b082e038eae4808694f0808077a22de502c
parenta6e8749ada5af1737b27f1eca1babe83e82af38c (diff)
Sort --print-variables output
Makes the output consistent regardless of how glib puts together the variables hash table. https://bugs.freedesktop.org/show_bug.cgi?id=66939
-rwxr-xr-xcheck/check-print-options6
-rw-r--r--main.c17
2 files changed, 13 insertions, 10 deletions
diff --git a/check/check-print-options b/check/check-print-options
index bf18eac..198e5a1 100755
--- a/check/check-print-options
+++ b/check/check-print-options
@@ -16,10 +16,10 @@ RESULT="pcfiledir"
run_test --print-variables no-variables
RESULT="exec_prefix
-prefix
-libdir
includedir
-pcfiledir"
+libdir
+pcfiledir
+prefix"
run_test --print-variables simple
# --print-provides
diff --git a/main.c b/main.c
index 8d37644..227ed35 100644
--- a/main.c
+++ b/main.c
@@ -281,11 +281,10 @@ pkg_uninstalled (Package *pkg)
}
void
-print_hashtable_key (gpointer key,
- gpointer value,
- gpointer user_data)
+print_list_data (gpointer data,
+ gpointer user_data)
{
- printf("%s\n", (gchar*)key);
+ g_print ("%s\n", (gchar *)data);
}
static void
@@ -700,9 +699,13 @@ main (int argc, char **argv)
{
Package *pkg = tmp->data;
if (pkg->vars != NULL)
- g_hash_table_foreach(pkg->vars,
- &print_hashtable_key,
- NULL);
+ {
+ /* Sort variables for consistent output */
+ GList *keys = g_hash_table_get_keys (pkg->vars);
+ keys = g_list_sort (keys, (GCompareFunc)g_strcmp0);
+ g_list_foreach (keys, print_list_data, NULL);
+ g_list_free (keys);
+ }
tmp = g_list_next (tmp);
if (tmp) printf ("\n");
}