]> git.notmuchmail.org Git - notmuch/blobdiff - lib/query.cc
notmuch search: Print the number of matched/total messages for each thread.
[notmuch] / lib / query.cc
index 1777e47dc044daa339c7ec0988e3d0fbef3de5a9..e853d4ec8e46b55b260fc0264b1756bf59eb26a1 100644 (file)
@@ -200,7 +200,7 @@ notmuch_query_search_threads (notmuch_query_t *query,
     seen = g_hash_table_new_full (g_str_hash, g_str_equal,
                                  free, NULL);
 
     seen = g_hash_table_new_full (g_str_hash, g_str_equal,
                                  free, NULL);
 
-    while (threads_seen < first + max_threads)
+    while (max_threads < 0 || threads_seen < first + max_threads)
     {
        int messages_seen_previously = messages_seen;
 
     {
        int messages_seen_previously = messages_seen;
 
@@ -218,9 +218,10 @@ notmuch_query_search_threads (notmuch_query_t *query,
                                                thread_id, NULL,
                                                (void **) &thread))
            {
                                                thread_id, NULL,
                                                (void **) &thread))
            {
-               if (threads_seen > first) {
+               if (threads_seen >= first) {
                    thread = _notmuch_thread_create (query, query->notmuch,
                    thread = _notmuch_thread_create (query, query->notmuch,
-                                                    thread_id);
+                                                    thread_id,
+                                                    query->query_string);
                    g_ptr_array_add (threads->threads, thread);
                } else {
                    thread = NULL;
                    g_ptr_array_add (threads->threads, thread);
                } else {
                    thread = NULL;
@@ -231,12 +232,12 @@ notmuch_query_search_threads (notmuch_query_t *query,
                threads_seen++;
            }
 
                threads_seen++;
            }
 
-           if (thread)
-               _notmuch_thread_add_message (thread, message);
-
            notmuch_message_destroy (message);
 
            messages_seen++;
            notmuch_message_destroy (message);
 
            messages_seen++;
+
+           if (max_threads >= 0 && threads_seen >= first + max_threads)
+               break;
        }
 
        /* Stop if we're not seeing any more messages. */
        }
 
        /* Stop if we're not seeing any more messages. */