--- /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 123C4431FB6\r
+ for <notmuch@notmuchmail.org>; Sat, 8 Mar 2014 15:51:37 -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 JQsxD92l1xwf for <notmuch@notmuchmail.org>;\r
+ Sat, 8 Mar 2014 15:51:33 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (dmz-mailsec-scanner-5.mit.edu\r
+ [18.7.68.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 3EB01431FBD\r
+ for <notmuch@notmuchmail.org>; Sat, 8 Mar 2014 15:51:33 -0800 (PST)\r
+X-AuditID: 12074422-f79526d000000c47-3b-531bad04f91f\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 89.81.03143.40DAB135; Sat, 8 Mar 2014 18:51:32 -0500 (EST)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s28NpVfg015055; \r
+ Sat, 8 Mar 2014 18:51:32 -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.8/8.12.4) with ESMTP id s28NpRoo013295\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+ Sat, 8 Mar 2014 18:51:28 -0500\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1WMR1b-0001qU-Ay; Sat, 08 Mar 2014 18:51:27 -0500\r
+Date: Sat, 8 Mar 2014 18:51:27 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: jani@nikula.org, David Bremner <david@tethera.net>\r
+Subject: Re: [Patch v3 04/15] lib: make folder: prefix literal\r
+Message-ID: <20140308235127.GL4709@mit.edu>\r
+References: <1394313585-28422-1-git-send-email-david@tethera.net>\r
+ <1394313585-28422-5-git-send-email-david@tethera.net>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1394313585-28422-5-git-send-email-david@tethera.net>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFupileLIzCtJLcpLzFFi42IRYrdT12VZKx1s0PhB1+JGazejRdN0Z4vr\r
+ N2cyOzB73Lr/mt3j2apbzB5bDr1nDmCO4rJJSc3JLEst0rdL4Mr43/+CvWC7V8XXd2fZGhhv\r
+ WHQxcnJICJhIHH42jw3CFpO4cG89kM3FISQwm0niw9Y/rBDOBkaJLRvWM4FUCQmcYpK428MO\r
+ YS9hlJjwyw7EZhFQkVi3bhZYDZuAhsS2/csZuxg5OEQEzCSmLa8FCTMLSEt8+90MViIsYCfR\r
+ 9/IAC4jNK6AtMedQMxvEyEqJrYfOQMUFJU7OfMIC0aslcePfSyaQkSBzlv/jAAlzCjhJtO/o\r
+ YASxRYEumHJyG9sERqFZSLpnIemehdC9gJF5FaNsSm6Vbm5iZk5xarJucXJiXl5qka6pXm5m\r
+ iV5qSukmRnCQuyjtYPx5UOkQowAHoxIP74NJ0sFCrIllxZW5hxglOZiURHk7VwCF+JLyUyoz\r
+ Eosz4otKc1KLDzFKcDArifC+7ATK8aYkVlalFuXDpKQ5WJTEefvOSgQLCaQnlqRmp6YWpBbB\r
+ ZGU4OJQkeIPWADUKFqWmp1akZeaUIKSZODhBhvMADS8EqeEtLkjMLc5Mh8ifYlSUEuetWQ2U\r
+ EABJZJTmwfXCktArRnGgV4R5a0DaeYAJDK77FdBgJqDBzcelQAaXJCKkpBoYVRZMWMjvadNd\r
+ GXXb5o3Q2WBT3f64zrqok1+WWq31zT9uwaDP3Dgxc7ZlZNseoekr1hv/0Fz7fNWTd+1/di3Y\r
+ 37xAcINudJLuAp9nx75Kn3r2YK/crfqIJarL3BMuLuFKO8LFc+D563O3Jm0OXTW/LWum78uN\r
+ OXG1z2bImTPNZG3YGnpCWte/VImlOCPRUIu5qDgRAOpf5bAdAwAA\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: Sat, 08 Mar 2014 23:51:37 -0000\r
+\r
+Quoth David Bremner on Mar 08 at 5:19 pm:\r
+> From: Jani Nikula <jani@nikula.org>\r
+> \r
+> In xapian terms, convert folder: prefix from probabilistic to boolean\r
+> prefix, matching the paths, relative form the maildir root, of the\r
+\r
+s/form/from/\r
+\r
+> message files, ignoring the maildir new and cur leaf directories.\r
+> \r
+> folder:foo matches all message files in foo, foo/new, and foo/cur.\r
+> \r
+> folder:foo/new does *not* match message files in foo/new.\r
+> \r
+> folder:"" matches all message files in the top level maildir and its\r
+> new and cur subdirectories.\r
+> \r
+> This change constitutes a database change: bump the database version\r
+> and add database upgrade support for folder: terms. The upgrade also\r
+> adds path: terms.\r
+> ---\r
+> lib/database.cc | 38 ++++++++++++++++++++++--\r
+> lib/message.cc | 80 ++++++++++++++++++++++++++++++++++++++++++++-------\r
+> lib/notmuch-private.h | 3 ++\r
+> 3 files changed, 108 insertions(+), 13 deletions(-)\r
+> \r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index 93cc7f5..186e3a7 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -42,7 +42,7 @@ typedef struct {\r
+> const char *prefix;\r
+> } prefix_t;\r
+> \r
+> -#define NOTMUCH_DATABASE_VERSION 1\r
+> +#define NOTMUCH_DATABASE_VERSION 2\r
+> \r
+> #define STRINGIFY(s) _SUB_STRINGIFY(s)\r
+> #define _SUB_STRINGIFY(s) #s\r
+> @@ -210,6 +210,7 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
+> { "is", "K" },\r
+> { "id", "Q" },\r
+> { "path", "P" },\r
+> + { "folder", "XFOLDER:" },\r
+\r
+It took me a while to figure out that the ":" here means that Xapian\r
+will unconditionally use a ":" after the prefix, instead of only using\r
+a ":" when the first letter following the prefix is upper-case ASCII.\r
+Maybe I was only confused by this because I simultaneously knew too\r
+much and not enough about Xapian, but it might be worth a comment.\r
+Something like,\r
+\r
+ /* Without the ":", since this is a multi-letter prefix, Xapian\r
+ * will add a colon itself if the first letter of the path is\r
+ * upper-case ASCII. Including the ":" forces there to always be\r
+ * a colon, which keeps our own logic simpler. */\r
+\r
+> };\r
+> \r
+> static prefix_t PROBABILISTIC_PREFIX[]= {\r
+> @@ -217,7 +218,6 @@ static prefix_t PROBABILISTIC_PREFIX[]= {\r
+> { "to", "XTO" },\r
+> { "attachment", "XATTACHMENT" },\r
+> { "subject", "XSUBJECT"},\r
+> - { "folder", "XFOLDER"}\r
+> };\r
+> \r
+> const char *\r
+> @@ -1168,6 +1168,40 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+> }\r
+> }\r
+> \r
+> + /*\r
+> + * Prior to version 2, the "folder:" prefix was probabilistic and\r
+> + * stemmed. Change it to the current boolean prefix. Add "path:"\r
+> + * prefixes while at it.\r
+> + */\r
+> + if (version < 2) {\r
+> + notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
+\r
+Three space indentation and no tabs? (It looks like this was in\r
+Jani's v2, also. I'm guessing at some point there was a copy-paste\r
+from a diff with tabs converted to spaces?)\r
+\r
+> + notmuch_messages_t *messages;\r
+> + notmuch_message_t *message;\r
+> +\r
+> + count = 0;\r
+> + total = notmuch_query_count_messages (query);\r
+> +\r
+> + for (messages = notmuch_query_search_messages (query);\r
+> + notmuch_messages_valid (messages);\r
+> + notmuch_messages_move_to_next (messages)) {\r
+> + if (do_progress_notify) {\r
+> + progress_notify (closure, (double) count / total);\r
+> + do_progress_notify = 0;\r
+> + }\r
+> +\r
+> + message = notmuch_messages_get (messages);\r
+> +\r
+> + _notmuch_message_upgrade_folder (message);\r
+> + _notmuch_message_sync (message);\r
+> +\r
+> + notmuch_message_destroy (message);\r
+> +\r
+> + count++;\r
+> + }\r
+> +\r
+> + notmuch_query_destroy (query);\r
+> + }\r
+> +\r
+> db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));\r
+> db->flush ();\r
+> \r
+> diff --git a/lib/message.cc b/lib/message.cc\r
+> index 21abe8e..31cb9f1 100644\r
+> --- a/lib/message.cc\r
+> +++ b/lib/message.cc\r
+> @@ -504,6 +504,56 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)\r
+> }\r
+> }\r
+> \r
+> +/* Return true if p points at "new" or "cur". */\r
+> +static bool is_maildir (const char *p)\r
+> +{\r
+> + return strcmp (p, "cur") == 0 || strcmp (p, "new") == 0;\r
+> +}\r
+> +\r
+> +/* Add "folder:" term for directory. */\r
+> +static notmuch_status_t\r
+> +_notmuch_message_add_folder_terms (notmuch_message_t *message,\r
+> + const char *directory)\r
+> +{\r
+> + char *folder, *last;\r
+> +\r
+> + folder = talloc_strdup (NULL, directory);\r
+> + if (! folder)\r
+> + return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+\r
+Same formatting problem in this chunk.\r
+\r
+> +\r
+> + /*\r
+> + * If the message file is in a leaf directory named "new" or\r
+> + * "cur", presume maildir and index the parent directory. Thus a\r
+> + * "folder:" prefix search matches messages in the specified\r
+> + * maildir folder, i.e. in the specified directory and its "new"\r
+> + * and "cur" subdirectories.\r
+> + *\r
+> + * Note that this means the "folder:" prefix can't be used for\r
+> + * distinguishing between message files in "new" or "cur". The\r
+> + * "path:" prefix needs to be used for that.\r
+> + *\r
+> + * Note the deliberate difference to _filename_is_in_maildir(). We\r
+> + * don't want to index different things depending on the existence\r
+> + * or non-existence of all maildir sibling directories "new",\r
+> + * "cur", and "tmp". Doing so would be surprising, and difficult\r
+> + * for the user to fix in case all subdirectories were not in\r
+> + * place during indexing.\r
+> + */\r
+> + last = strrchr (folder, '/');\r
+> + if (last) {\r
+> + if (is_maildir (last + 1))\r
+> + *last = '\0';\r
+> + } else if (is_maildir (folder)) {\r
+> + *folder = '\0';\r
+> + }\r
+> +\r
+> + _notmuch_message_add_term (message, "folder", folder);\r
+> +\r
+> + talloc_free (folder);\r
+> +\r
+> + return NOTMUCH_STATUS_SUCCESS;\r
+> +}\r
+> +\r
+> #define RECURSIVE_SUFFIX "/**"\r
+> \r
+> /* Add "path:" terms for directory. */\r
+> @@ -570,9 +620,8 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)\r
+> directory = _notmuch_database_get_directory_path (ctx,\r
+> message->notmuch,\r
+> directory_id);\r
+> - if (strlen (directory))\r
+> - _notmuch_message_gen_terms (message, "folder", directory);\r
+> \r
+> + _notmuch_message_add_folder_terms (message, directory);\r
+> _notmuch_message_add_path_terms (message, directory);\r
+> }\r
+> \r
+> @@ -610,9 +659,7 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
+> * notmuch_directory_get_child_files() . */\r
+> _notmuch_message_add_term (message, "file-direntry", direntry);\r
+> \r
+> - /* New terms allow user to search with folder: specification. */\r
+> - _notmuch_message_gen_terms (message, "folder", directory);\r
+> -\r
+> + _notmuch_message_add_folder_terms (message, directory);\r
+> _notmuch_message_add_path_terms (message, directory);\r
+> \r
+> talloc_free (local);\r
+> @@ -637,8 +684,6 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+> const char *filename)\r
+> {\r
+> void *local = talloc_new (message);\r
+> - const char *folder_prefix = _find_prefix ("folder");\r
+> - char *zfolder_prefix = talloc_asprintf(local, "Z%s", folder_prefix);\r
+> char *direntry;\r
+> notmuch_private_status_t private_status;\r
+> notmuch_status_t status;\r
+> @@ -659,10 +704,7 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+> /* Re-synchronize "folder:" and "path:" terms for this message. */\r
+> \r
+> /* Remove all "folder:" terms. */\r
+> - _notmuch_message_remove_terms (message, folder_prefix);\r
+> -\r
+> - /* Remove all "folder:" stemmed terms. */\r
+> - _notmuch_message_remove_terms (message, zfolder_prefix);\r
+> + _notmuch_message_remove_terms (message, _find_prefix ("folder"));\r
+> \r
+> /* Remove all "path:" terms. */\r
+> _notmuch_message_remove_terms (message, _find_prefix ("path"));\r
+> @@ -675,6 +717,22 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+> return status;\r
+> }\r
+> \r
+> +/* Upgrade the "folder:" prefix from V1 to V2. */\r
+> +#define FOLDER_PREFIX_V1 "XFOLDER"\r
+> +#define ZFOLDER_PREFIX_V1 "Z" FOLDER_PREFIX_V1\r
+> +void\r
+> +_notmuch_message_upgrade_folder (notmuch_message_t *message)\r
+> +{\r
+> + /* Remove all old "folder:" terms. */\r
+> + _notmuch_message_remove_terms (message, FOLDER_PREFIX_V1);\r
+> +\r
+> + /* Remove all old "folder:" stemmed terms. */\r
+> + _notmuch_message_remove_terms (message, ZFOLDER_PREFIX_V1);\r
+> +\r
+> + /* Add new boolean "folder:" and "path:" terms. */\r
+> + _notmuch_message_add_directory_terms (message, message);\r
+> +}\r
+> +\r
+> char *\r
+> _notmuch_message_talloc_copy_data (notmuch_message_t *message)\r
+> {\r
+> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+> index af185c7..59eb2bc 100644\r
+> --- a/lib/notmuch-private.h\r
+> +++ b/lib/notmuch-private.h\r
+> @@ -263,6 +263,9 @@ _notmuch_message_gen_terms (notmuch_message_t *message,\r
+> void\r
+> _notmuch_message_upgrade_filename_storage (notmuch_message_t *message);\r
+> \r
+> +void\r
+> +_notmuch_message_upgrade_folder (notmuch_message_t *message);\r
+> +\r
+> notmuch_status_t\r
+> _notmuch_message_add_filename (notmuch_message_t *message,\r
+> const char *filename);\r