gstinfo: fix debug levels being applied in the wrong order

Remove unneeded reapplication of patterns. Besides being
superfluous (gst_debug_reset_threshold already applies
patterns) it was also wrong and didn't stop checking patterns
after the first match (broken in 67e9d139).

Also fix up unit test which checked for the wrong order.

https://bugzilla.gnome.org/show_bug.cgi?id=794717
diff --git a/gst/gstinfo.c b/gst/gstinfo.c
index 8bb1a2a..9b51167 100644
--- a/gst/gstinfo.c
+++ b/gst/gstinfo.c
@@ -1689,18 +1689,6 @@
   gst_debug_reset_all_thresholds ();
 }
 
-static void
-gst_debug_apply_patterns_to_category (GstDebugCategory * cat)
-{
-  GSList *l;
-
-  g_mutex_lock (&__level_name_mutex);
-  for (l = __level_name; l != NULL; l = l->next) {
-    for_each_threshold_by_entry (cat, (LevelNameEntry *) l->data);
-  }
-  g_mutex_unlock (&__level_name_mutex);
-}
-
 GstDebugCategory *
 _gst_debug_category_new (const gchar * name, guint color,
     const gchar * description)
@@ -1733,9 +1721,6 @@
   }
   g_mutex_unlock (&__cat_mutex);
 
-  /* ensure the filter is applied to categories registered after _debug_init */
-  gst_debug_apply_patterns_to_category (cat);
-
   return cat;
 }
 
diff --git a/tests/check/gst/gstinfo.c b/tests/check/gst/gstinfo.c
index 7ebd967..78f8b5a 100644
--- a/tests/check/gst/gstinfo.c
+++ b/tests/check/gst/gstinfo.c
@@ -440,7 +440,8 @@
   /* Note: before the fixes this wouldn't work to trigger the problem because
    * only a pattern set via GST_DEBUG before gst_init would be picked up
    * (another bug) */
-  gst_debug_set_threshold_from_string ("*a*b:6,*c:3,d*:2,xyz*:9,ax:1", TRUE);
+  gst_debug_set_threshold_from_string ("*a*b:6,*b*0:6,*c:3,d*:2,xyz*:9,ax:1",
+      TRUE);
 
   fail_unless_equals_int (GST_LEVEL_DEFAULT,
       gst_debug_get_default_threshold ());
@@ -471,8 +472,12 @@
     /* *c:3 */
     fail_unless_equals_int (gst_debug_category_get_threshold (cats[0x4c]),
         GST_LEVEL_FIXME);
-    /* *a*b:6 */
+    /* *a*b:6 and d*:2, but d*:2 takes priority here as cat name is "dog-a1b"
+     * and order matters: items listed later override earlier ones. */
     fail_unless_equals_int (gst_debug_category_get_threshold (cats[0xa1b]),
+        GST_LEVEL_WARNING);
+    /* *a*0:6 */
+    fail_unless_equals_int (gst_debug_category_get_threshold (cats[0xb10]),
         GST_LEVEL_LOG);
   }