Blame SOURCES/0071-lib-use-user-friendly-order-in-make_description.patch

0c9110
From 15b4d3e8b516009bab878b7279f549fa61824c74 Mon Sep 17 00:00:00 2001
0c9110
From: Matej Habrnal <mhabrnal@redhat.com>
0c9110
Date: Tue, 16 Sep 2014 05:11:40 +0200
0c9110
Subject: [LIBREPORT PATCH 71/93] lib: use user-friendly order in
0c9110
 make_description()
0c9110
0c9110
The reason, time, cmd_line, package, uid, count are always sorted in this
0c9110
order. The other items are sorted alphabetically and added to the the end of
0c9110
the list.
0c9110
0c9110
Related to rhbz#1067440
0c9110
0c9110
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
0c9110
---
0c9110
 src/lib/make_descr.c | 28 +++++++++++++++++++++++++++-
0c9110
 1 file changed, 27 insertions(+), 1 deletion(-)
0c9110
0c9110
diff --git a/src/lib/make_descr.c b/src/lib/make_descr.c
0c9110
index 7f5c10b..dcf517e 100644
0c9110
--- a/src/lib/make_descr.c
0c9110
+++ b/src/lib/make_descr.c
0c9110
@@ -48,6 +48,32 @@ char *make_description_item_multiline(const char *name, const char *content)
0c9110
     return strbuf_free_nobuf(buf);
0c9110
 }
0c9110
 
0c9110
+static int list_cmp(const char *s1, const char *s2)
0c9110
+{
0c9110
+    static const char *const list_order[] = {
0c9110
+            FILENAME_REASON    ,
0c9110
+            FILENAME_TIME      ,
0c9110
+            FILENAME_CMDLINE   ,
0c9110
+            FILENAME_PACKAGE   ,
0c9110
+            FILENAME_UID       ,
0c9110
+            FILENAME_COUNT     ,
0c9110
+            NULL
0c9110
+    };
0c9110
+    int s1_index = index_of_string_in_list(s1, (char**) list_order);
0c9110
+    int s2_index = index_of_string_in_list(s2, (char**) list_order);
0c9110
+
0c9110
+    if(s1_index < 0 && s2_index < 0)
0c9110
+        return strcmp(s1, s2);
0c9110
+
0c9110
+    if(s1_index < 0)
0c9110
+        return 1;
0c9110
+
0c9110
+    if(s2_index < 0)
0c9110
+        return -1;
0c9110
+
0c9110
+    return s1_index - s2_index;
0c9110
+}
0c9110
+
0c9110
 char *make_description(problem_data_t *problem_data, char **names_to_skip,
0c9110
                        unsigned max_text_size, unsigned desc_flags)
0c9110
 {
0c9110
@@ -59,7 +85,7 @@ char *make_description(problem_data_t *problem_data, char **names_to_skip,
0c9110
                                                             FILENAME_ANALYZER);
0c9110
 
0c9110
     GList *list = g_hash_table_get_keys(problem_data);
0c9110
-    list = g_list_sort(list, (GCompareFunc)strcmp);
0c9110
+    list = g_list_sort(list, (GCompareFunc)list_cmp);
0c9110
     GList *l;
0c9110
 
0c9110
     /* Print one-liners. Format:
0c9110
-- 
0c9110
1.8.3.1
0c9110