]> git.notmuchmail.org Git - notmuch/commitdiff
Merge branch from fixing up bugs after bisecting.
authorCarl Worth <cworth@cworth.org>
Thu, 22 Oct 2009 06:23:32 +0000 (23:23 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 22 Oct 2009 06:23:44 +0000 (23:23 -0700)
I'm glad that when I implemented "notmuch restore" I went through the
extra effort to take the code I had written in one sitting into over a
dozen commits. Sure enough, I hadn't tested well enough and had
totally broken "notmuch setup", (segfaults and bogus thread_id
values).

With the little commits I had made, git bisect saved the day, and I
went back to make the fixes right on top of the commits that
introduced the bugs. So now we octopus merge those in.

database.cc
message.cc

index 5049b47e9ef593d44b586bc67d37064f79dc0a84..6d62109e73c11e758987c5203839e2ef91aa8291 100644 (file)
@@ -133,6 +133,29 @@ find_message_by_docid (Xapian::Database *db, Xapian::docid docid)
     return db->get_document (docid);
 }
 
+static void
+insert_thread_id (GHashTable *thread_ids, Xapian::Document doc)
+{
+    string value_string;
+    const char *value, *id, *comma;
+
+    value_string = doc.get_value (NOTMUCH_VALUE_THREAD);
+    value = value_string.c_str();
+    if (strlen (value)) {
+       id = value;
+       while (*id) {
+           comma = strchr (id, ',');
+           if (comma == NULL)
+               comma = id + strlen (id);
+           g_hash_table_insert (thread_ids,
+                                strndup (id, comma - id), NULL);
+           id = comma;
+           if (*id)
+               id++;
+       }
+    }
+}
+
 notmuch_message_t *
 notmuch_database_find_message (notmuch_database_t *notmuch,
                               const char *message_id)
@@ -174,16 +197,8 @@ find_thread_ids (notmuch_database_t *notmuch,
 
     find_messages_by_term (db, "ref", message_id, &child, &children_end);
     for ( ; child != children_end; child++) {
-       const char *thread_id;
        doc = find_message_by_docid (db, *child);
-
-       thread_id = doc.get_value (NOTMUCH_VALUE_THREAD).c_str ();
-       if (strlen (thread_id) == 0) {
-           fprintf (stderr, "Database error: Message with doc_id %u has empty thread-id value (value index %d)\n",
-                    *child, NOTMUCH_VALUE_THREAD);
-       } else {
-           g_hash_table_insert (thread_ids, strdup (thread_id), NULL);
-       }
+       insert_thread_id (thread_ids, doc);
     }
 
     for (i = 0; i < parents->len; i++) {
index 338d953f2dfb744f8b98c677ab1cf5c711a1f823..dd73d13c97fe06332850798f24de7d2012bf80cb 100644 (file)
@@ -190,14 +190,14 @@ notmuch_thread_ids_t *
 notmuch_message_get_thread_ids (notmuch_message_t *message)
 {
     notmuch_thread_ids_t *thread_ids;
-    const char *id_str;
+    std::string id_str;
 
     thread_ids = talloc (message, notmuch_thread_ids_t);
     if (unlikely (thread_ids == NULL))
        return NULL;
 
-    id_str = message->doc.get_value (NOTMUCH_VALUE_THREAD).c_str ();
-    thread_ids->next = talloc_strdup (message, id_str);
+    id_str = message->doc.get_value (NOTMUCH_VALUE_THREAD);
+    thread_ids->next = talloc_strdup (message, id_str.c_str ());
 
     /* Initialize thread_ids->current and terminate first ID. */
     notmuch_thread_ids_advance (thread_ids);