]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Separate list of all messages from top-level messages
authorAustin Clements <amdragon@MIT.EDU>
Sun, 25 Nov 2012 04:57:03 +0000 (23:57 -0500)
committerDavid Bremner <bremner@debian.org>
Tue, 19 Feb 2013 00:20:24 +0000 (20:20 -0400)
Previously, thread.cc built up a list of all messages, then
proceeded to tear it apart to transform it into a list of
top-level messages.  Now we simply build a new list of top-level
messages.

This simplifies the interface to _notmuch_message_add_reply,
eliminates the pointer acrobatics from
_resolve_thread_relationships, and will enable us to do things
with the list of all messages in the following patches.

lib/message.cc
lib/notmuch-private.h
lib/thread.cc

index 320901f77eb010a1cab4502c79db6faccbc6d49c..8720c1b542d839a24613991b4b425fe03f65e1e3 100644 (file)
@@ -462,9 +462,9 @@ notmuch_message_get_thread_id (notmuch_message_t *message)
 
 void
 _notmuch_message_add_reply (notmuch_message_t *message,
 
 void
 _notmuch_message_add_reply (notmuch_message_t *message,
-                           notmuch_message_node_t *reply)
+                           notmuch_message_t *reply)
 {
 {
-    _notmuch_message_list_append (message->replies, reply);
+    _notmuch_message_list_add_message (message->replies, reply);
 }
 
 notmuch_messages_t *
 }
 
 notmuch_messages_t *
index 7a409f54ca5a08b4de81b39cb652984c330ae758..c054a0e907b6ab0cfdb6d135d0b6a6a4c390507f 100644 (file)
@@ -462,7 +462,7 @@ _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids,
 
 void
 _notmuch_message_add_reply (notmuch_message_t *message,
 
 void
 _notmuch_message_add_reply (notmuch_message_t *message,
-                           notmuch_message_node_t *reply);
+                           notmuch_message_t *reply);
 
 /* sha1.c */
 
 
 /* sha1.c */
 
index aed87b1e61d009288b905dc2d872647e2b1f0b0a..45a7d1d023dcdb4b86395475e752760ca2c6a6eb 100644 (file)
@@ -35,7 +35,11 @@ struct visible _notmuch_thread {
     char *authors;
     GHashTable *tags;
 
     char *authors;
     GHashTable *tags;
 
+    /* All messages, oldest first. */
     notmuch_message_list_t *message_list;
     notmuch_message_list_t *message_list;
+    /* Top-level messages, oldest first. */
+    notmuch_message_list_t *toplevel_list;
+
     GHashTable *message_hash;
     int total_messages;
     int matched_messages;
     GHashTable *message_hash;
     int total_messages;
     int matched_messages;
@@ -345,29 +349,22 @@ _thread_add_matched_message (notmuch_thread_t *thread,
 }
 
 static void
 }
 
 static void
-_resolve_thread_relationships (unused (notmuch_thread_t *thread))
+_resolve_thread_relationships (notmuch_thread_t *thread)
 {
 {
-    notmuch_message_node_t **prev, *node;
+    notmuch_message_node_t *node;
     notmuch_message_t *message, *parent;
     const char *in_reply_to;
 
     notmuch_message_t *message, *parent;
     const char *in_reply_to;
 
-    prev = &thread->message_list->head;
-    while ((node = *prev)) {
+    for (node = thread->message_list->head; node; node = node->next) {
        message = node->message;
        in_reply_to = _notmuch_message_get_in_reply_to (message);
        if (in_reply_to && strlen (in_reply_to) &&
            g_hash_table_lookup_extended (thread->message_hash,
                                          in_reply_to, NULL,
                                          (void **) &parent))
        message = node->message;
        in_reply_to = _notmuch_message_get_in_reply_to (message);
        if (in_reply_to && strlen (in_reply_to) &&
            g_hash_table_lookup_extended (thread->message_hash,
                                          in_reply_to, NULL,
                                          (void **) &parent))
-       {
-           *prev = node->next;
-           if (thread->message_list->tail == &node->next)
-               thread->message_list->tail = prev;
-           node->next = NULL;
-           _notmuch_message_add_reply (parent, node);
-       } else {
-           prev = &((*prev)->next);
-       }
+           _notmuch_message_add_reply (parent, message);
+       else
+           _notmuch_message_list_add_message (thread->toplevel_list, message);
     }
 
     /* XXX: After scanning through the entire list looking for parents
     }
 
     /* XXX: After scanning through the entire list looking for parents
@@ -451,7 +448,9 @@ _notmuch_thread_create (void *ctx,
                                          free, NULL);
 
     thread->message_list = _notmuch_message_list_create (thread);
                                          free, NULL);
 
     thread->message_list = _notmuch_message_list_create (thread);
-    if (unlikely (thread->message_list == NULL)) {
+    thread->toplevel_list = _notmuch_message_list_create (thread);
+    if (unlikely (thread->message_list == NULL ||
+                 thread->toplevel_list == NULL)) {
        thread = NULL;
        goto DONE;
     }
        thread = NULL;
        goto DONE;
     }
@@ -506,7 +505,7 @@ _notmuch_thread_create (void *ctx,
 notmuch_messages_t *
 notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread)
 {
 notmuch_messages_t *
 notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread)
 {
-    return _notmuch_messages_create (thread->message_list);
+    return _notmuch_messages_create (thread->toplevel_list);
 }
 
 const char *
 }
 
 const char *