--- /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 E7B00431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 3 Feb 2012 00:48:35 -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 lwTDnanmKTM2 for <notmuch@notmuchmail.org>;\r
+ Fri, 3 Feb 2012 00:48:34 -0800 (PST)\r
+Received: from mail-qw0-f46.google.com (mail-qw0-f46.google.com\r
+ [209.85.216.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id B5039431FAE\r
+ for <notmuch@notmuchmail.org>; Fri, 3 Feb 2012 00:48:34 -0800 (PST)\r
+Received: by qadc10 with SMTP id c10so636782qad.5\r
+ for <notmuch@notmuchmail.org>; Fri, 03 Feb 2012 00:48:32 -0800 (PST)\r
+Received: by 10.224.116.15 with SMTP id k15mr5247391qaq.79.1328258912859;\r
+ Fri, 03 Feb 2012 00:48:32 -0800 (PST)\r
+Received: from localhost (nikula.org. [92.243.24.172])\r
+ by mx.google.com with ESMTPS id k19sm5139971qak.4.2012.02.03.00.48.29\r
+ (version=SSLv3 cipher=OTHER); Fri, 03 Feb 2012 00:48:31 -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: <87sjisrf7b.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
+ <87d39wygts.fsf@nikula.org> <87sjisrf7b.fsf@qmul.ac.uk>\r
+User-Agent: Notmuch/0.10.2+187~g43d4f26 (http://notmuchmail.org) Emacs/23.1.1\r
+ (i686-pc-linux-gnu)\r
+Date: Fri, 03 Feb 2012 08:48:27 +0000\r
+Message-ID: <871uqc9uas.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: Fri, 03 Feb 2012 08:48:36 -0000\r
+\r
+On Thu, 02 Feb 2012 23:24:56 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> On Fri, 03 Feb 2012 01:07:59 +0200, Jani Nikula <jani@nikula.org> wrote:\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
+> I think I will go with notmuch_thread_count_messages as you suggest.\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
+> I will just comment on this: the *only* reason I put in\r
+> NOTMUCH_MESSAGE_FLAG_MAX was as a way of keeping track of the size of\r
+> the bitfield. If there is a better way do say!\r
+\r
+At least one improvement would be to make it NOTMUCH_MESSAGE_FLAG_ALL\r
+(or similar) which would be the OR of all the other flags. Above, it\r
+should be equal to (1 << 2) - 1. Not only is this something usable to\r
+the library users, but also more accurate - if I'm not mistaken, the\r
+flagset array currently has one element too many.\r
+\r
+If documented properly, the users should not be surprised that in the\r
+future more flags might be added to NOTMUCH_MESSAGE_FLAG_ALL, and\r
+depending on the case they may or may not want to use that.\r
+\r
+Some purists might say that #defines are better suited for defining bit\r
+flags than enums, but I'm fine with either.\r
+\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
+> I haven't come up with a good name: the best I have come up with is\r
+> flagset_message_count so if you have any suggestions...\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 I think this works better: these are the flags I want, these are the\r
+> ones I don't want seems natural (versus here are the ones I care about\r
+> and here are the ones of those I want). But I will wait to see if anyone\r
+> else has an opinion.\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