--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 26596431FBD\r
+ for <notmuch@notmuchmail.org>; Thu, 2 Feb 2012 13:55:41 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id ekga1EboEg-f for <notmuch@notmuchmail.org>;\r
+ Thu, 2 Feb 2012 13:55:40 -0800 (PST)\r
+Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
+ [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id CD55A431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 2 Feb 2012 13:55:39 -0800 (PST)\r
+Received: by lahd3 with SMTP id d3so1670520lah.26\r
+ for <notmuch@notmuchmail.org>; Thu, 02 Feb 2012 13:55:38 -0800 (PST)\r
+Received: by 10.152.128.163 with SMTP id np3mr2414569lab.51.1328219738195;\r
+ Thu, 02 Feb 2012 13:55:38 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
+ [84.248.80.253])\r
+ by mx.google.com with ESMTPS id i9sm3049561lbz.3.2012.02.02.13.55.35\r
+ (version=SSLv3 cipher=OTHER); Thu, 02 Feb 2012 13:55:36 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org,\r
+ amdragon@MIT.EDU\r
+Subject: Re: [PATCH v4 07/11] lib: added interface\r
+ notmuch_thread_get_flag_messages\r
+In-Reply-To: <1328204619-25046-7-git-send-email-markwalters1009@gmail.com>\r
+References: <874nv9rv79.fsf@qmul.ac.uk>\r
+ <1328204619-25046-7-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Notmuch/0.11+139~g4340989 (http://notmuchmail.org) Emacs/23.3.1\r
+ (i686-pc-linux-gnu)\r
+Date: Thu, 02 Feb 2012 23:55:33 +0200\r
+Message-ID: <87k444yk6i.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 02 Feb 2012 21:55:41 -0000\r
+\r
+\r
+Hi Mark -\r
+\r
+This is my first look at any version of the series; apologies if I'm\r
+clueless about some details... Please find some comments below.\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+On Thu, 2 Feb 2012 17:43:35 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> The function is\r
+> notmuch_thread_get_flag_messages\r
+> (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags)\r
+> \r
+> and returns the number of messages with the specified flags on flag_mask.\r
+\r
+Is the purpose of this function to get the count of messages that have\r
+certain flags set, certain flags not set, and certain flags don't-care?\r
+\r
+At the very least, I think the documentation of the function should be\r
+greatly improved.\r
+\r
+I think the name of the function should be notmuch_thread_count_messages\r
+which is like notmuch_query_count_messages, but for messages in threads\r
+(and with some extra restrictions).\r
+\r
+> \r
+> This generalises the existing function\r
+> notmuch_thread_get_total_messages and\r
+> notmuch_thread_get_matched_messages which are retained to maintain\r
+> compatibility.\r
+> ---\r
+> lib/message.cc | 6 +++---\r
+> lib/notmuch.h | 15 +++++++++++++--\r
+> lib/thread.cc | 39 ++++++++++++++++++++++++++-------------\r
+> 3 files changed, 42 insertions(+), 18 deletions(-)\r
+> \r
+> diff --git a/lib/message.cc b/lib/message.cc\r
+> index 0075425..d60da83 100644\r
+> --- a/lib/message.cc\r
+> +++ b/lib/message.cc\r
+> @@ -746,7 +746,7 @@ notmuch_bool_t\r
+> notmuch_message_get_flag (notmuch_message_t *message,\r
+> notmuch_message_flag_t flag)\r
+> {\r
+> - return message->flags & (1 << flag);\r
+> + return message->flags & flag;\r
+> }\r
+> \r
+> void\r
+> @@ -754,9 +754,9 @@ notmuch_message_set_flag (notmuch_message_t *message,\r
+> notmuch_message_flag_t flag, notmuch_bool_t enable)\r
+> {\r
+> if (enable)\r
+> - message->flags |= (1 << flag);\r
+> + message->flags |= flag;\r
+> else\r
+> - message->flags &= ~(1 << flag);\r
+> + message->flags &= ~flag;\r
+> }\r
+> \r
+> time_t\r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index f75afae..c02e7f4 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -654,6 +654,16 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread);\r
+> int\r
+> notmuch_thread_get_total_messages (notmuch_thread_t *thread);\r
+> \r
+> +/* Get the number of messages in 'thread' which have the specified\r
+> + * flags on flag_mask.\r
+> + *\r
+> + * This is a more general interface than\r
+> + * notmuch_thread_get_total_messages or\r
+> + * notmuch_thread_get_matched_messages\r
+> + */\r
+> +int\r
+> +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags);\r
+> +\r
+> /* Get a notmuch_messages_t iterator for the top-level messages in\r
+> * 'thread'.\r
+> *\r
+> @@ -902,8 +912,9 @@ notmuch_message_get_filenames (notmuch_message_t *message);\r
+> \r
+> /* Message flags */\r
+> typedef enum _notmuch_message_flag {\r
+> - NOTMUCH_MESSAGE_FLAG_MATCH,\r
+> - NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
+> + NOTMUCH_MESSAGE_FLAG_MATCH = (1<<0),\r
+> + NOTMUCH_MESSAGE_FLAG_EXCLUDED = (1<<1),\r
+> + NOTMUCH_MESSAGE_FLAG_MAX = (1<<2)\r
+\r
+How are these used by the current lib users at the moment? How will they\r
+break with this change?\r
+\r
+Please align the assignments. \r
+\r
+> } notmuch_message_flag_t;\r
+> \r
+> /* Get a value of a flag for the email corresponding to 'message'. */\r
+> diff --git a/lib/thread.cc b/lib/thread.cc\r
+> index e976d64..542f7f4 100644\r
+> --- a/lib/thread.cc\r
+> +++ b/lib/thread.cc\r
+> @@ -37,8 +37,7 @@ struct visible _notmuch_thread {\r
+> \r
+> notmuch_message_list_t *message_list;\r
+> GHashTable *message_hash;\r
+> - int total_messages;\r
+> - int matched_messages;\r
+> + int flag_count_messages[NOTMUCH_MESSAGE_FLAG_MAX];\r
+> time_t oldest;\r
+> time_t newest;\r
+> };\r
+> @@ -226,7 +225,6 @@ _thread_add_message (notmuch_thread_t *thread,\r
+> \r
+> _notmuch_message_list_add_message (thread->message_list,\r
+> talloc_steal (thread, message));\r
+> - thread->total_messages++;\r
+> \r
+> g_hash_table_insert (thread->message_hash,\r
+> xstrdup (notmuch_message_get_message_id (message)),\r
+> @@ -319,21 +317,18 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
+> \r
+> date = notmuch_message_get_date (message);\r
+> \r
+> - if (date < thread->oldest || ! thread->matched_messages) {\r
+> + if (date < thread->oldest || ! notmuch_thread_get_matched_messages (thread)) {\r
+> thread->oldest = date;\r
+> if (sort == NOTMUCH_SORT_OLDEST_FIRST)\r
+> _thread_set_subject_from_message (thread, message);\r
+> }\r
+> \r
+> - if (date > thread->newest || ! thread->matched_messages) {\r
+> + if (date > thread->newest || ! notmuch_thread_get_matched_messages (thread)) {\r
+> thread->newest = date;\r
+> if (sort != NOTMUCH_SORT_OLDEST_FIRST)\r
+> _thread_set_subject_from_message (thread, message);\r
+> }\r
+> \r
+> - if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED))\r
+> - thread->matched_messages++;\r
+> -\r
+> if (g_hash_table_lookup_extended (thread->message_hash,\r
+> notmuch_message_get_message_id (message), NULL,\r
+> (void **) &hashed_message)) {\r
+> @@ -411,7 +406,7 @@ _notmuch_thread_create (void *ctx,\r
+> const char *thread_id;\r
+> char *thread_id_query_string;\r
+> notmuch_query_t *thread_id_query;\r
+> -\r
+> + int i;\r
+> notmuch_messages_t *messages;\r
+> notmuch_message_t *message;\r
+> \r
+> @@ -457,8 +452,8 @@ _notmuch_thread_create (void *ctx,\r
+> thread->message_hash = g_hash_table_new_full (g_str_hash, g_str_equal,\r
+> free, NULL);\r
+> \r
+> - thread->total_messages = 0;\r
+> - thread->matched_messages = 0;\r
+> + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++)\r
+> + thread->flag_count_messages[i] = 0;\r
+\r
+memset (thread->flag_count_messages, 0, sizeof(thread->flag_count_messages));\r
+\r
+> thread->oldest = 0;\r
+> thread->newest = 0;\r
+> \r
+> @@ -473,6 +468,7 @@ _notmuch_thread_create (void *ctx,\r
+> notmuch_messages_move_to_next (messages))\r
+> {\r
+> unsigned int doc_id;\r
+> + unsigned int message_flags;\r
+> \r
+> message = notmuch_messages_get (messages);\r
+> doc_id = _notmuch_message_get_doc_id (message);\r
+> @@ -485,6 +481,10 @@ _notmuch_thread_create (void *ctx,\r
+> _notmuch_doc_id_set_remove (match_set, doc_id);\r
+> _thread_add_matched_message (thread, message, sort);\r
+> }\r
+> + message_flags =\r
+> + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) |\r
+> + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED);\r
+> + thread->flag_count_messages[message_flags]++;\r
+\r
+The first impression of using a set of flags as index is that there's a\r
+bug. But this is to keep count of messages with certain flag sets rather\r
+than total for each flag, right? I think this needs more comments, more\r
+documentation. Already naming the field flag_set_message_counts or\r
+similar would help greatly.\r
+\r
+> \r
+> _notmuch_message_close (message);\r
+> }\r
+> @@ -511,15 +511,28 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread)\r
+> }\r
+> \r
+> int\r
+> +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags)\r
+> +{\r
+> + unsigned int i;\r
+> + int count = 0;\r
+> + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++)\r
+\r
+ARRAY_SIZE (thread->flag_count_messages)\r
+\r
+> + if ((i & flag_mask) == (flags & flag_mask))\r
+> + count += thread->flag_count_messages[i];\r
+> + return count;\r
+> +}\r
+\r
+I wonder if the same could be accomplished by using two flag mask\r
+parameters, include_flag_mask and exclude_flag_mask. I'm thinking of the\r
+usage, would it be easier to use:\r
+\r
+notmuch_query_count_messages (thread, NOTMUCH_MESSAGE_FLAG_MATCH, NOTMUCH_MESSAGE_FLAG_EXCLUDED);\r
+\r
+to get number of messages that have MATCH but not EXCLUDED? 0 as\r
+include_flag_mask could still be special for "all", and you could use:\r
+\r
+notmuch_query_count_messages (thread, 0, NOTMUCH_MESSAGE_FLAG_EXCLUDED);\r
+\r
+Note the name change according to my earlier suggestion. It might be\r
+wise to not export the function before the API is chrystal clear if\r
+there is no pressing need to do so.\r
+\r
+> +\r
+> +int\r
+> notmuch_thread_get_total_messages (notmuch_thread_t *thread)\r
+> {\r
+> - return thread->total_messages;\r
+> + return notmuch_thread_get_flag_messages (thread, 0, 0);\r
+> }\r
+> \r
+> int\r
+> notmuch_thread_get_matched_messages (notmuch_thread_t *thread)\r
+> {\r
+> - return thread->matched_messages;\r
+> + return notmuch_thread_get_flag_messages (thread,\r
+> + NOTMUCH_MESSAGE_FLAG_MATCH | NOTMUCH_MESSAGE_FLAG_EXCLUDED,\r
+> + NOTMUCH_MESSAGE_FLAG_MATCH);\r
+> }\r
+> \r
+> const char *\r
+> -- \r
+> 1.7.2.3\r
+> \r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r