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

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