From: Mark Walters Date: Thu, 2 Feb 2012 23:24:56 +0000 (+0000) Subject: Re: [PATCH v4 07/11] lib: added interface notmuch_thread_get_flag_messages X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=ccf2d405939bd31e13333a52cdb3bdaec31902a6;p=notmuch-archives.git Re: [PATCH v4 07/11] lib: added interface notmuch_thread_get_flag_messages --- diff --git a/57/10c67f06df7547b4bff8096348fdede5a50480 b/57/10c67f06df7547b4bff8096348fdede5a50480 new file mode 100644 index 000000000..b24b3542b --- /dev/null +++ b/57/10c67f06df7547b4bff8096348fdede5a50480 @@ -0,0 +1,260 @@ +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 CEA4E431FBD + for ; Thu, 2 Feb 2012 15:23:50 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, 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 Uvpgz3b8l+gt for ; + Thu, 2 Feb 2012 15:23:49 -0800 (PST) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 8A9AC431FAF + for ; Thu, 2 Feb 2012 15:23:49 -0800 (PST) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1Rt60J-0002yi-Pm; Thu, 02 Feb 2012 23:23:48 +0000 +Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] + helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1Rt60J-0002v8-61; Thu, 02 Feb 2012 23:23:47 +0000 +From: Mark Walters +To: Jani Nikula , notmuch@notmuchmail.org, amdragon@MIT.EDU +Subject: Re: [PATCH v4 07/11] lib: added interface + notmuch_thread_get_flag_messages +In-Reply-To: <87d39wygts.fsf@nikula.org> +References: <874nv9rv79.fsf@qmul.ac.uk> + <1328204619-25046-7-git-send-email-markwalters1009@gmail.com> + <87k444yk6i.fsf@nikula.org> <871uqcswfb.fsf@qmul.ac.uk> + <87d39wygts.fsf@nikula.org> +User-Agent: Notmuch/0.11+140~gb5e1cf0 (http://notmuchmail.org) Emacs/23.2.1 + (i486-pc-linux-gnu) +Date: Thu, 02 Feb 2012 23:24:56 +0000 +Message-ID: <87sjisrf7b.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 94.192.233.223 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: 213c140df5c652a3c95276e07c1279d6 (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay + * domain + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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: Thu, 02 Feb 2012 23:23:50 -0000 + +On Fri, 03 Feb 2012 01:07:59 +0200, Jani Nikula wrote: +> On Thu, 02 Feb 2012 22:27:36 +0000, Mark Walters wrote: +> > On Thu, 02 Feb 2012 23:55:33 +0200, Jani Nikula wrote: +> > > +> > > Hi Mark - +> > > +> > > This is my first look at any version of the series; apologies if I'm +> > > clueless about some details... Please find some comments below. +> > > +> > > BR, +> > > Jani. +> > > +> > > +> > > On Thu, 2 Feb 2012 17:43:35 +0000, Mark Walters wrote: +> > > > The function is +> > > > notmuch_thread_get_flag_messages +> > > > (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags) +> > > > +> > > > and returns the number of messages with the specified flags on flag_mask. +> > > +> > > Is the purpose of this function to get the count of messages that have +> > > certain flags set, certain flags not set, and certain flags don't-care? +> > +> > Yes: I was trying to follow Austin's suggestion from +> > id:"20120124025331.GZ16740@mit.edu" (although stupidly I didn't +> > follow his suggestion of a function name). +> > +> > > At the very least, I think the documentation of the function should be +> > > greatly improved. +> > > +> > > I think the name of the function should be notmuch_thread_count_messages +> > > which is like notmuch_query_count_messages, but for messages in threads +> > > (and with some extra restrictions). +> > +> > Yes I like your name; before I change it do you (and others) prefer it +> > to Austin's suggestion of notmuch_thread_count_flags. Or we could even +> > be more verbose with something like +> > notmuch_thread_count_messages_with_flags +> +> I'd like to make it clear that it's about message count. Not about +> getting flags, not about flag counts. _with_flags is a matter of taste, +> no strong opinions there. + +I think I will go with notmuch_thread_count_messages as you suggest. + +> > > > /* Message flags */ +> > > > typedef enum _notmuch_message_flag { +> > > > - NOTMUCH_MESSAGE_FLAG_MATCH, +> > > > - NOTMUCH_MESSAGE_FLAG_EXCLUDED +> > > > + NOTMUCH_MESSAGE_FLAG_MATCH = (1<<0), +> > > > + NOTMUCH_MESSAGE_FLAG_EXCLUDED = (1<<1), +> > > > + NOTMUCH_MESSAGE_FLAG_MAX = (1<<2) +> > > +> > > How are these used by the current lib users at the moment? How will they +> > > break with this change? + +I will just comment on this: the *only* reason I put in +NOTMUCH_MESSAGE_FLAG_MAX was as a way of keeping track of the size of +the bitfield. If there is a better way do say! + +> > The only existing flag is NOTMUCH_MESSAGE_FLAG_MATCH: that is currently +> > zero but in the current code that is the bit offset of the flag; in my +> > version it is the actual bit for the flag (otherwise I think flag masks +> > end up very ugly). I believe all callers use notmuch_message_set_flag +> > and notmuch_message_get_flag so they should not notice the difference. +> > +> > > Please align the assignments. +> > +> > Will do. +> > +> > > > @@ -457,8 +452,8 @@ _notmuch_thread_create (void *ctx, +> > > > thread->message_hash = g_hash_table_new_full (g_str_hash, g_str_equal, +> > > > free, NULL); +> > > > +> > > > - thread->total_messages = 0; +> > > > - thread->matched_messages = 0; +> > > > + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++) +> > > > + thread->flag_count_messages[i] = 0; +> > > +> > > memset (thread->flag_count_messages, 0, sizeof(thread->flag_count_messages)); +> > +> > +> > Will do +> > +> > > > thread->oldest = 0; +> > > > thread->newest = 0; +> > > > +> > > > @@ -473,6 +468,7 @@ _notmuch_thread_create (void *ctx, +> > > > notmuch_messages_move_to_next (messages)) +> > > > { +> > > > unsigned int doc_id; +> > > > + unsigned int message_flags; +> > > > +> > > > message = notmuch_messages_get (messages); +> > > > doc_id = _notmuch_message_get_doc_id (message); +> > > > @@ -485,6 +481,10 @@ _notmuch_thread_create (void *ctx, +> > > > _notmuch_doc_id_set_remove (match_set, doc_id); +> > > > _thread_add_matched_message (thread, message, sort); +> > > > } +> > > > + message_flags = +> > > > + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) | +> > > > + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED); +> > > > + thread->flag_count_messages[message_flags]++; +> > > +> > > The first impression of using a set of flags as index is that there's a +> > > bug. But this is to keep count of messages with certain flag sets rather +> > > than total for each flag, right? I think this needs more comments, more +> > > documentation. Already naming the field flag_set_message_counts or +> > > similar would help greatly. +> > +> > I will try and document it better: on first reading I parsed your name +> > as flag set (as verb) message counts whereas I assume you mean "flag +> > set" as a noun! I will see if I can come up with something though. +> +> Yes, as a noun! :) + +I haven't come up with a good name: the best I have come up with is +flagset_message_count so if you have any suggestions... + +> > > > _notmuch_message_close (message); +> > > > } +> > > > @@ -511,15 +511,28 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread) +> > > > } +> > > > +> > > > int +> > > > +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags) +> > > > +{ +> > > > + unsigned int i; +> > > > + int count = 0; +> > > > + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++) +> > > +> > > ARRAY_SIZE (thread->flag_count_messages) +> > +> > ok +> > +> > > +> > > > + if ((i & flag_mask) == (flags & flag_mask)) +> > > > + count += thread->flag_count_messages[i]; +> > > > + return count; +> > > > +} +> > > +> > > I wonder if the same could be accomplished by using two flag mask +> > > parameters, include_flag_mask and exclude_flag_mask. I'm thinking of the +> > > usage, would it be easier to use: +> > > +> > > notmuch_query_count_messages (thread, NOTMUCH_MESSAGE_FLAG_MATCH, NOTMUCH_MESSAGE_FLAG_EXCLUDED); +> > > +> > > to get number of messages that have MATCH but not EXCLUDED? 0 as +> > > include_flag_mask could still be special for "all", and you could use: +> > > +> > > notmuch_query_count_messages (thread, 0, NOTMUCH_MESSAGE_FLAG_EXCLUDED); +> > > +> > > Note the name change according to my earlier suggestion. It might be +> > > wise to not export the function before the API is chrystal clear if +> > > there is no pressing need to do so. +> > +> > (I assume you mean notmuch_thread_count_messages.) +> +> Doh! Yes. +> +> > Can I just check this +> > would return the number of messages which have all the flags in +> > include_flag_mask and none of the flags in exclude_flag_mask? + +Yes I think this works better: these are the flags I want, these are the +ones I don't want seems natural (versus here are the ones I care about +and here are the ones of those I want). But I will wait to see if anyone +else has an opinion. + +> Yes, but only if it makes sense to you! :) +> +> > +> > I completely agree about leaving it until we have the API well worked +> > out. I wrote it in response to Austin's suggestion and then it looked +> > like it would useful in my attempts to remove the +> > notmuch_query_set_omit_excluded_messages API. However, those attempts +> > failed so it doesn't have any users yet. +> > +> > Best wishes +> > +> > Mark