--- /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 3CDDD431FBD\r
+ for <notmuch@notmuchmail.org>; Sun, 9 Mar 2014 00:46: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 LKBuHo11PT2G for <notmuch@notmuchmail.org>;\r
+ Sun, 9 Mar 2014 00:45:58 -0800 (PST)\r
+Received: from mail-la0-f47.google.com (mail-la0-f47.google.com\r
+ [209.85.215.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id C6412431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 9 Mar 2014 00:45:57 -0800 (PST)\r
+Received: by mail-la0-f47.google.com with SMTP id y1so3897885lam.34\r
+ for <notmuch@notmuchmail.org>; Sun, 09 Mar 2014 00:45:55 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=RpDpnYnLLdbiwFqf+TVYQZKJggLeETc8U6hUqV5qZ48=;\r
+ b=WHsRfJPDoGfYpIKbl+GRRPiWWown1051C2B1m2UOfQo9mQbcsN9tpLCrGYHlDbK1Ro\r
+ 3GeloiaRAVzetCQOsXrEjZzW6zTGA/SAe2UWoqx6tmizxRZ/1dw6xBHHradI/rdcWgGR\r
+ /EG0wfuc3CFJYP6egisL6B1IrxMzBsURFCLL3zxiFq1PVx3xjXDaobCDTapcnfr+0LtA\r
+ 6wiDbBvwYmrjzODPDX4f1b1Mt/D04+M8cojAG5TQN/NAL6i1VeIbhT239rcI7/OT/h7i\r
+ G9bktMoSQxEvjPnKozEJAWrWOwfxzRu9ETFWBGqPnwQEf3Y09YHGXZ20MeZcdDOVlLii\r
+ fqkA==\r
+X-Gm-Message-State:\r
+ ALoCoQm73A9LRbFSFsMKNEaCcSVBxiXshfCJqOfA4MJS6mfzMfXB0DqKi3IFcO1nxNTJyMRSQjtx\r
+X-Received: by 10.112.46.225 with SMTP id y1mr17697584lbm.12.1394354754057;\r
+ Sun, 09 Mar 2014 00:45:54 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+ [88.195.111.91])\r
+ by mx.google.com with ESMTPSA id q6sm23951687lal.3.2014.03.09.00.45.52\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 09 Mar 2014 00:45:53 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Austin Clements <amdragon@MIT.EDU>, David Bremner <david@tethera.net>\r
+Subject: Re: [Patch v3 04/15] lib: make folder: prefix literal\r
+In-Reply-To: <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
+ <20140308235127.GL4709@mit.edu>\r
+User-Agent: Notmuch/0.17+101~g2c5a6ae9e6e9 (http://notmuchmail.org)\r
+ Emacs/24.3.1 (x86_64-pc-linux-gnu)\r
+Date: Sun, 09 Mar 2014 10:45:51 +0200\r
+Message-ID: <87pplv69q8.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Sun, 09 Mar 2014 08:46:06 -0000\r
+\r
+On Sun, 09 Mar 2014, Austin Clements <amdragon@MIT.EDU> wrote:\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
+Do you mean "... first letter of the _prefix_ is ..."?\r
+\r
+Jani.\r
+\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