From: Austin Clements Date: Mon, 6 Oct 2014 23:17:06 +0000 (+1800) Subject: [PATCH 00/12] Add ghost messages and fix thread linking X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cd8ae8c1001d8bba139927819f582fecce14a79f;p=notmuch-archives.git [PATCH 00/12] Add ghost messages and fix thread linking --- diff --git a/94/544259f4cc2796d71c8a7d8b3cafe285783bdf b/94/544259f4cc2796d71c8a7d8b3cafe285783bdf new file mode 100644 index 000000000..172169138 --- /dev/null +++ b/94/544259f4cc2796d71c8a7d8b3cafe285783bdf @@ -0,0 +1,181 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 1B883431FBF + for ; Mon, 6 Oct 2014 16:17:30 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id kqGYkVidWxFZ for ; + Mon, 6 Oct 2014 16:17:26 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id B04A2431FAE + for ; Mon, 6 Oct 2014 16:17:26 -0700 (PDT) +X-AuditID: 1209190e-f79d46d000003643-42-5433230508c4 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 99.5D.13891.50323345; Mon, 6 Oct 2014 19:17:25 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s96NHPVd025203; + Mon, 6 Oct 2014 19:17:25 -0400 +Received: from drake.dyndns.org ([12.185.136.2]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s96NHMsj014457 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Mon, 6 Oct 2014 19:17:24 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1XbHWr-0001JF-ED; Mon, 06 Oct 2014 17:17:21 -0600 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 00/12] Add ghost messages and fix thread linking +Date: Mon, 6 Oct 2014 17:17:06 -0600 +Message-Id: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFlrKIsWRmVeSWpSXmKPExsUixG6nosuqbBxi0DXT0OJGazejxfWbM5kd + mDyerbrF7LHl0HvmAKYoLpuU1JzMstQifbsErowzy9+xFmxSqJg57R9jA+M8qS5GTg4JAROJ + yce3MkLYYhIX7q1n62Lk4hASmM0ksfvqXEYIZwOjRMOpJlYIZymTxM3Xe9hBWoQEljBK3LkI + ZrMJ6EusWDuJFcQWEZCW2Hl3NpjNLCAqMef/PTBbWMBB4lVjIxOIzSKgKvHk6x8wm1fATWL9 + /MUsEGfISWzY/Z9xAiPvAkaGVYyyKblVurmJmTnFqcm6xcmJeXmpRbrGermZJXqpKaWbGEGh + wSnJt4Px60GlQ4wCHIxKPLwROwxDhFgTy4orcw8xSnIwKYnyzmE3DhHiS8pPqcxILM6ILyrN + SS0+xCjBwawkwsv12yhEiDclsbIqtSgfJiXNwaIkzrvpB1+IkEB6YklqdmpqQWoRTFaGg0NJ + gveQItBQwaLU9NSKtMycEoQ0EwcnyHAeoOH/QGp4iwsSc4sz0yHypxgVpcR5k5WAEgIgiYzS + PLheWOy+YhQHekWY9yZIOw8w7uG6XwENZgIabDpHH2RwSSJCSqqBcVHIKUb/T+UXP7Rm+Ean + 6l73bGH8b3fhJvei3Gbe/u+b6vwP3j/KlrL8jVGpWGHBOsX604eOxdhJfpzcs3n2omTO6ZwM + s77rL39lNmF+bENgaurtEmX/+KX7sm/ve7PpJnNMq/7TX1Wt+lt92R7lpFmK3wn6rDWt5mJZ + vsGunSnTguVi7hpPVGIpzkg01GIuKk4EAJjvj4S4AgAA +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 06 Oct 2014 23:17:30 -0000 + +This is v2 of the +id:1412345958-8278-1-git-send-email-aclements@csail.mit.edu. This +adds some comments and clarifies some code as suggested by David. +Patch 6 is new in v2 and adds some bit-twiddling macros for clarity +and robustness in later patches. + +The diff from v1 is below. + +diff --git a/lib/database.cc b/lib/database.cc +index 4655f59..6e51a72 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -1277,6 +1277,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + ++total; + } + if (new_features & NOTMUCH_FEATURE_GHOSTS) { ++ /* The ghost message upgrade converts all thread_id_* ++ * metadata values into ghost message documents. */ + t_end = db->metadata_keys_end ("thread_id_"); + for (t = db->metadata_keys_begin ("thread_id_"); t != t_end; ++t) + ++total; +diff --git a/lib/message.cc b/lib/message.cc +index ad832cf..a7a13cc 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -344,15 +344,17 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message) + + /* Get document type */ + assert (strcmp (id_prefix, type_prefix) < 0); +- if (! (message->lazy_flags & (1 << NOTMUCH_MESSAGE_FLAG_GHOST))) { ++ if (! NOTMUCH_TEST_BIT (message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST)) { + i.skip_to (type_prefix); ++ /* "T" is the prefix "type" fields. See ++ * BOOLEAN_PREFIX_INTERNAL. */ + if (*i == "Tmail") +- message->flags &= ~(1 << NOTMUCH_MESSAGE_FLAG_GHOST); ++ NOTMUCH_CLEAR_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); + else if (*i == "Tghost") +- message->flags |= (1 << NOTMUCH_MESSAGE_FLAG_GHOST); ++ NOTMUCH_SET_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); + else + INTERNAL_ERROR ("Message without type term"); +- message->lazy_flags |= (1 << NOTMUCH_MESSAGE_FLAG_GHOST); ++ NOTMUCH_SET_BIT (&message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST); + } + + /* Get filename list. Here we get only the terms. We lazily +@@ -390,8 +392,8 @@ _notmuch_message_invalidate_metadata (notmuch_message_t *message, + } + + if (strcmp ("type", prefix_name) == 0) { +- message->flags &= ~(1 << NOTMUCH_MESSAGE_FLAG_GHOST); +- message->lazy_flags &= ~(1 << NOTMUCH_MESSAGE_FLAG_GHOST); ++ NOTMUCH_CLEAR_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); ++ NOTMUCH_CLEAR_BIT (&message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST); + } + + if (strcmp ("file-direntry", prefix_name) == 0) { +@@ -893,10 +895,10 @@ notmuch_message_get_flag (notmuch_message_t *message, + notmuch_message_flag_t flag) + { + if (flag == NOTMUCH_MESSAGE_FLAG_GHOST && +- ! (message->lazy_flags & (1 << flag))) ++ ! NOTMUCH_TEST_BIT (message->lazy_flags, flag)) + _notmuch_message_ensure_metadata (message); + +- return message->flags & (1 << flag); ++ return NOTMUCH_TEST_BIT (message->flags, flag); + } + + void +@@ -904,10 +906,10 @@ notmuch_message_set_flag (notmuch_message_t *message, + notmuch_message_flag_t flag, notmuch_bool_t enable) + { + if (enable) +- message->flags |= (1 << flag); ++ NOTMUCH_SET_BIT (&message->flags, flag); + else +- message->flags &= ~(1 << flag); +- message->lazy_flags |= (1 << flag); ++ NOTMUCH_CLEAR_BIT (&message->flags, flag); ++ NOTMUCH_SET_BIT (&message->lazy_flags, flag); + } + + time_t +diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h +index 2fbd38e..2f43c1d 100644 +--- a/lib/notmuch-private.h ++++ b/lib/notmuch-private.h +@@ -63,6 +63,17 @@ NOTMUCH_BEGIN_DECLS + #define STRNCMP_LITERAL(var, literal) \ + strncmp ((var), (literal), sizeof (literal) - 1) + ++/* Robust bit test/set/reset macros */ ++#define NOTMUCH_TEST_BIT(val, bit) \ ++ ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ? 0 \ ++ : !!((val) & (1ull << bit))) ++#define NOTMUCH_SET_BIT(valp, bit) \ ++ ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ? *(valp) \ ++ : (*(valp) |= (1ull << bit))) ++#define NOTMUCH_CLEAR_BIT(valp, bit) \ ++ ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ? *(valp) \ ++ : (*(valp) &= ~(1ull << bit))) ++ + #define unused(x) x __attribute__ ((unused)) + + #ifdef __cplusplus + +