unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 00/12] Add ghost messages and fix thread linking
@ 2014-10-06 23:17 Austin Clements
  2014-10-06 23:17 ` [PATCH v2 01/12] lib: Move message ID compression to _notmuch_message_create_for_message_id Austin Clements
                   ` (12 more replies)
  0 siblings, 13 replies; 21+ messages in thread
From: Austin Clements @ 2014-10-06 23:17 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2014-10-22  1:51 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-06 23:17 [PATCH 00/12] Add ghost messages and fix thread linking Austin Clements
2014-10-06 23:17 ` [PATCH v2 01/12] lib: Move message ID compression to _notmuch_message_create_for_message_id Austin Clements
2014-10-06 23:17 ` [PATCH v2 02/12] lib: Refactor _notmuch_database_link_message Austin Clements
2014-10-06 23:17 ` [PATCH v2 03/12] lib: Handle empty date value Austin Clements
2014-10-11  5:12   ` David Bremner
2014-10-06 23:17 ` [PATCH v2 04/12] lib: Add a ghost messages database feature Austin Clements
2014-10-06 23:17 ` [PATCH v2 05/12] lib: Update database schema doc for ghost messages Austin Clements
2014-10-06 23:17 ` [PATCH v2 06/12] lib: Introduce macros for bit operations Austin Clements
2014-10-06 23:17 ` [PATCH v2 07/12] lib: Internal support for querying and creating ghost messages Austin Clements
2014-10-21 23:05   ` Mark Walters
2014-10-22  1:33     ` Austin Clements
2014-10-06 23:17 ` [PATCH v2 08/12] lib: Implement ghost-based thread linking Austin Clements
2014-10-21 23:10   ` Mark Walters
2014-10-22  1:49     ` Austin Clements
2014-10-06 23:17 ` [PATCH v2 09/12] lib: Implement upgrade to ghost messages feature Austin Clements
2014-10-06 23:17 ` [PATCH v2 10/12] lib: Enable " Austin Clements
2014-10-06 23:17 ` [PATCH v2 11/12] test: Test upgrade to " Austin Clements
2014-10-06 23:17 ` [PATCH v2 12/12] lib: Remove unnecessary thread linking steps when using ghost messages Austin Clements
2014-10-21 23:17   ` Mark Walters
2014-10-22  1:51     ` Austin Clements
2014-10-21 23:32 ` [PATCH 00/12] Add ghost messages and fix thread linking Mark Walters

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).