--- /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 4C763431FBD\r
+ for <notmuch@notmuchmail.org>; Thu, 2 Feb 2012 15:08:06 -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 FfU92uywqYy3 for <notmuch@notmuchmail.org>;\r
+ Thu, 2 Feb 2012 15:08:05 -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 0EBC3431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 2 Feb 2012 15:08:04 -0800 (PST)\r
+Received: by lahd3 with SMTP id d3so1700581lah.26\r
+ for <notmuch@notmuchmail.org>; Thu, 02 Feb 2012 15:08:03 -0800 (PST)\r
+Received: by 10.152.109.161 with SMTP id ht1mr2483217lab.33.1328224083512;\r
+ Thu, 02 Feb 2012 15:08:03 -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 k13sm3156059lbu.16.2012.02.02.15.08.00\r
+ (version=SSLv3 cipher=OTHER); Thu, 02 Feb 2012 15:08:02 -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: <871uqcswfb.fsf@qmul.ac.uk>\r
+References: <874nv9rv79.fsf@qmul.ac.uk>\r
+ <1328204619-25046-7-git-send-email-markwalters1009@gmail.com>\r
+ <87k444yk6i.fsf@nikula.org> <871uqcswfb.fsf@qmul.ac.uk>\r
+User-Agent: Notmuch/0.11+139~g4340989 (http://notmuchmail.org) Emacs/23.3.1\r
+ (i686-pc-linux-gnu)\r
+Date: Fri, 03 Feb 2012 01:07:59 +0200\r
+Message-ID: <87d39wygts.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 23:08:06 -0000\r
+\r
+On Thu, 02 Feb 2012 22:27:36 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> On Thu, 02 Feb 2012 23:55:33 +0200, Jani Nikula <jani@nikula.org> wrote:\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
+> Yes: I was trying to follow Austin's suggestion from\r
+> id:"20120124025331.GZ16740@mit.edu" (although stupidly I didn't\r
+> follow his suggestion of a function name).\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
+> Yes I like your name; before I change it do you (and others) prefer it\r
+> to Austin's suggestion of notmuch_thread_count_flags. Or we could even\r
+> be more verbose with something like\r
+> notmuch_thread_count_messages_with_flags\r
+\r
+I'd like to make it clear that it's about message count. Not about\r
+getting flags, not about flag counts. _with_flags is a matter of taste,\r
+no strong opinions there.\r
+\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
+> The only existing flag is NOTMUCH_MESSAGE_FLAG_MATCH: that is currently\r
+> zero but in the current code that is the bit offset of the flag; in my\r
+> version it is the actual bit for the flag (otherwise I think flag masks\r
+> end up very ugly). I believe all callers use notmuch_message_set_flag\r
+> and notmuch_message_get_flag so they should not notice the difference.\r
+> \r
+> > Please align the assignments. \r
+> \r
+> Will do.\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
+> \r
+> Will do \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
+> I will try and document it better: on first reading I parsed your name\r
+> as flag set (as verb) message counts whereas I assume you mean "flag\r
+> set" as a noun! I will see if I can come up with something though.\r
+\r
+Yes, as a noun! :)\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
+> ok\r
+> \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
+> (I assume you mean notmuch_thread_count_messages.)\r
+\r
+Doh! Yes.\r
+\r
+> Can I just check this\r
+> would return the number of messages which have all the flags in\r
+> include_flag_mask and none of the flags in exclude_flag_mask?\r
+\r
+Yes, but only if it makes sense to you! :)\r
+\r
+> \r
+> I completely agree about leaving it until we have the API well worked\r
+> out. I wrote it in response to Austin's suggestion and then it looked\r
+> like it would useful in my attempts to remove the\r
+> notmuch_query_set_omit_excluded_messages API. However, those attempts\r
+> failed so it doesn't have any users yet.\r
+> \r
+> Best wishes\r
+> \r
+> Mark\r