--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 BA3E1431E64\r
+ for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 20:44:48 -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 Mru7AIKc-mMB for <notmuch@notmuchmail.org>;\r
+ Mon, 30 Jan 2012 20:44:46 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
+ [18.7.68.37])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1EA8C431FBC\r
+ for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 20:44:46 -0800 (PST)\r
+X-AuditID: 12074425-b7f4a6d0000008e0-97-4f2771bd419f\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 08.F4.02272.DB1772F4; Mon, 30 Jan 2012 23:44:45 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0V4ij1l032194; \r
+ Mon, 30 Jan 2012 23:44:45 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0V4ii2W029861\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Mon, 30 Jan 2012 23:44:45 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Rs5ZQ-0002m6-TW; Mon, 30 Jan 2012 23:43:52 -0500\r
+Date: Mon, 30 Jan 2012 23:43:52 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH 3/7] lib: Make notmuch_query_search_messages set the\r
+ exclude flag\r
+Message-ID: <20120131044352.GZ17991@mit.edu>\r
+References: <8762fu4aqt.fsf@qmul.ac.uk>\r
+ <1327862394-14334-3-git-send-email-markwalters1009@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1327862394-14334-3-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFuplleLIzCtJLcpLzFFi42IRYrdT191bqO5vsOiNpsXquTwW12/OZHZg\r
+ 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4MhbdXsZacMO4Yue3HywNjDM1uxg5OCQETCQ+\r
+ tct3MXICmWISF+6tZwOxhQT2MUq8bIvoYuQCsjcwSny5+pUdwjnJJHFlwycWCGcJo8TxxnOs\r
+ IC0sAqoS+/6/YASx2QQ0JLbtXw5miwjoSNw+tIAdxGYWkJb49ruZCcQWFgiXWPTnOwuIzQtU\r
+ c+rSS2aI1ekS3dcOsUHEBSVOznzCAtGrJXHj30smkKtB5iz/xwES5hTwkpi/7S/YKlEBFYkp\r
+ J7exTWAUmoWkexaS7lkI3QsYmVcxyqbkVunmJmbmFKcm6xYnJ+blpRbpWujlZpbopaaUbmIE\r
+ h7SL6g7GCYeUDjEKcDAq8fAKfFLzF2JNLCuuzD3EKMnBpCTKO6dA3V+ILyk/pTIjsTgjvqg0\r
+ J7X4EKMEB7OSCO+b1UDlvCmJlVWpRfkwKWkOFiVxXk2td35A/yaWpGanphakFsFkZTg4lCR4\r
+ w4CxKyRYlJqeWpGWmVOCkGbi4AQZzgM0XBSkhre4IDG3ODMdIn+KUZej/e3u84xCLHn5ealS\r
+ 4ryMIEUCIEUZpXlwc2Cp6BWjONBbwrz6IFU8wDQGN+kV0BImoCXPGVRBlpQkIqSkGhiFq/Yf\r
+ aLrDeb2hdkv9KX3pz7EWF5I3eyhonfb1PPT3dCLLkekuruZ9R1VLpn7vt4wKFVw/V1TvhW/9\r
+ 4bOO5j+Td0hcu+iTdDXtHM8BM9M7S1qz5vw65b3CPKD7ikxfmJTM46abh2Ujfke98jMuEl9T\r
+ fIJ1epP5ec9IzQO6NznDdQK/HVQTPKrEUpyRaKjFXFScCABshsHfIAMAAA==\r
+Cc: notmuch@notmuchmail.org\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: Tue, 31 Jan 2012 04:44:48 -0000\r
+\r
+Quoth Mark Walters on Jan 29 at 6:39 pm:\r
+> Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by\r
+> notmuch_query_search_messages for excluded messages. Also add an\r
+> option omit_excluded_messages to the search that we do not want the\r
+> excludes at all.\r
+> \r
+> This exclude flag will be added to notmuch_query_search threads in the\r
+> next patch.\r
+> ---\r
+> lib/notmuch-private.h | 1 +\r
+> lib/notmuch.h | 8 ++++++-\r
+> lib/query.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++---\r
+> 3 files changed, 56 insertions(+), 5 deletions(-)\r
+> \r
+> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+> index 7bf153e..e791bb0 100644\r
+> --- a/lib/notmuch-private.h\r
+> +++ b/lib/notmuch-private.h\r
+> @@ -401,6 +401,7 @@ typedef struct _notmuch_message_list {\r
+> */\r
+> struct visible _notmuch_messages {\r
+> notmuch_bool_t is_of_list_type;\r
+> + notmuch_doc_id_set_t *excluded_doc_ids;\r
+\r
+I might be following the diff wrong, but shouldn't this be a field of\r
+notmuch_mset_messages_t? (Then it also doesn't have to be a pointer,\r
+which is really how notmuch_doc_id_set_t was designed to be used.)\r
+\r
+> notmuch_message_node_t *iterator;\r
+> };\r
+> \r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index 7929fe7..740d005 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -449,6 +449,11 @@ typedef enum {\r
+> const char *\r
+> notmuch_query_get_query_string (notmuch_query_t *query);\r
+> \r
+> +/* specify whether to results should omit the excluded results rather\r
+> + * than just marking them excluded */\r
+> +void\r
+> +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);\r
+> +\r
+\r
+I don't think we should add this API. The library behavior will not\r
+change for library users that don't use excludes and library users\r
+that do use excludes should by aware of the excluded flag and do the\r
+appropriate thing.\r
+\r
+I can see why this is handy in some cases, but I don't think it\r
+provides enough utility to warrant becoming part of the permanent and\r
+minimal library interface.\r
+\r
+> /* Specify the sorting desired for this query. */\r
+> void\r
+> notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
+> @@ -895,7 +900,8 @@ 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_MATCH,\r
+> + NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
+> } notmuch_message_flag_t;\r
+> \r
+> /* Get a value of a flag for the email corresponding to 'message'. */\r
+> diff --git a/lib/query.cc b/lib/query.cc\r
+> index c25b301..7d165d2 100644\r
+> --- a/lib/query.cc\r
+> +++ b/lib/query.cc\r
+> @@ -28,6 +28,7 @@ struct _notmuch_query {\r
+> const char *query_string;\r
+> notmuch_sort_t sort;\r
+> notmuch_string_list_t *exclude_terms;\r
+> + notmuch_bool_t omit_excluded_messages;\r
+> };\r
+> \r
+> typedef struct _notmuch_mset_messages {\r
+> @@ -57,6 +58,12 @@ struct visible _notmuch_threads {\r
+> notmuch_doc_id_set_t match_set;\r
+> };\r
+> \r
+> +/* we need this in the message functions so forward declare */\r
+\r
+Comments should start with a capital letter and end with a period.\r
+(The code isn't completely consistent about this, but it is something\r
+we're codifying in the upcoming style guide.)\r
+\r
+> +static notmuch_bool_t\r
+> +_notmuch_doc_id_set_init (void *ctx,\r
+> + notmuch_doc_id_set_t *doc_ids,\r
+> + GArray *arr);\r
+> +\r
+> notmuch_query_t *\r
+> notmuch_query_create (notmuch_database_t *notmuch,\r
+> const char *query_string)\r
+> @@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
+> \r
+> query->exclude_terms = _notmuch_string_list_create (query);\r
+> \r
+> + query->omit_excluded_messages = FALSE;\r
+> +\r
+> return query;\r
+> }\r
+> \r
+> @@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
+> }\r
+> \r
+> void\r
+> +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)\r
+> +{\r
+> + query->omit_excluded_messages = omit;\r
+> +}\r
+> +\r
+> +void\r
+> notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)\r
+> {\r
+> query->sort = sort;\r
+> @@ -173,6 +188,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+> "mail"));\r
+> Xapian::Query string_query, final_query, exclude_query;\r
+> Xapian::MSet mset;\r
+> + Xapian::MSetIterator iterator;\r
+> unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
+> Xapian::QueryParser::FLAG_PHRASE |\r
+> Xapian::QueryParser::FLAG_LOVEHATE |\r
+> @@ -190,11 +206,35 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+> final_query = Xapian::Query (Xapian::Query::OP_AND,\r
+> mail_query, string_query);\r
+> }\r
+> + messages->base.excluded_doc_ids = NULL;\r
+> +\r
+> + if (query->exclude_terms) {\r
+> + exclude_query = _notmuch_exclude_tags (query, final_query);\r
+> + exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
+> + exclude_query, final_query);\r
+> +\r
+> + if (query->omit_excluded_messages)\r
+> + final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
+> + final_query, exclude_query);\r
+> + else {\r
+> + enquire.set_weighting_scheme (Xapian::BoolWeight());\r
+> + enquire.set_query (exclude_query);\r
+> +\r
+> + mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
+> +\r
+> + GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
+> +\r
+> + for (iterator = mset.begin (); iterator != mset.end (); iterator++)\r
+> + {\r
+\r
+No newline before the brace.\r
+\r
+> + unsigned int doc_id = *iterator;\r
+> + g_array_append_val (excluded_doc_ids, doc_id);\r
+> + }\r
+> + messages->base.excluded_doc_ids = talloc (query, _notmuch_doc_id_set);\r
+> + _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,\r
+> + excluded_doc_ids);\r
+\r
+Don't forget to g_array_unref excluded_doc_ids.\r
+\r
+> + }\r
+> + }\r
+> \r
+> - exclude_query = _notmuch_exclude_tags (query, final_query);\r
+> -\r
+> - final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
+> - final_query, exclude_query);\r
+> \r
+> enquire.set_weighting_scheme (Xapian::BoolWeight());\r
+> \r
+> @@ -283,6 +323,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
+> INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");\r
+> }\r
+> \r
+> + if ((messages->excluded_doc_ids) &&\r
+> + (_notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id)))\r
+\r
+No need for so many parens (just a nit).\r
+\r
+> + notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
+> +\r
+> return message;\r
+> }\r
+> \r