--- /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 BCE61431FC7\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Jan 2014 13:18:32 -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 nqJ8vBnXO3Or for <notmuch@notmuchmail.org>;\r
+ Fri, 24 Jan 2014 13:18:26 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (dmz-mailsec-scanner-2.mit.edu\r
+ [18.9.25.13])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 2BB4F431FC3\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Jan 2014 13:18:26 -0800 (PST)\r
+X-AuditID: 1209190d-f79776d000000ce9-5a-52e2d8a1ecc6\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id D5.86.03305.1A8D2E25; Fri, 24 Jan 2014 16:18:25 -0500 (EST)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s0OLIOWs026329; \r
+ Fri, 24 Jan 2014 16:18:24 -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 s0OLINGu020312\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+ Fri, 24 Jan 2014 16:18:24 -0500\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1W6o8s-0006Dj-UL; Fri, 24 Jan 2014 16:18:22 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/5] lib: make folder: prefix literal\r
+In-Reply-To:\r
+ <d735583dd1bb48a87530fe3d52a57abd4d17acb8.1389304779.git.jani@nikula.org>\r
+References: <cover.1389304779.git.jani@nikula.org>\r
+ <d735583dd1bb48a87530fe3d52a57abd4d17acb8.1389304779.git.jani@nikula.org>\r
+User-Agent: Notmuch/0.17~rc2+14~g06f47e0 (http://notmuchmail.org) Emacs/23.4.1\r
+ (i486-pc-linux-gnu)\r
+Date: Fri, 24 Jan 2014 16:18:22 -0500\r
+Message-ID: <87wqhpm63l.fsf@awakening.csail.mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrPIsWRmVeSWpSXmKPExsUixCmqrbvwxqMgg8c7+SyapjtbXL85k9mB\r
+ yePW/dfsHs9W3WIOYIrisklJzcksSy3St0vgyng78xRjQU9ExanNP5gbGB+5dDFyckgImEj8\r
+ mPKbDcIWk7hwbz2YLSQwm0mic1JAFyMXkL2RUeLE5cmsEM5pJokTF56wQzhLGCXurJsM1sIm\r
+ oCGxbf9yRhBbRMBK4tzD1ywgtrCApcSOU0tYQWxOgTCJP3e7oVbUSOz8c5kZxBYVSJI4PfU3\r
+ UA0HB4uAqkTLZQeQMC/QdUvfb2OCsAUlTs58AjaSWUBL4sa/l0wTGAVmIUnNQpJawMi0ilE2\r
+ JbdKNzcxM6c4NVm3ODkxLy+1SNdILzezRC81pXQTIzgcJXl3ML47qHSIUYCDUYmH90PwwyAh\r
+ 1sSy4srcQ4ySHExKorxTLz8KEuJLyk+pzEgszogvKs1JLT7EKMHBrCTCO3czUI43JbGyKrUo\r
+ HyYlzcGiJM57k8M+SEggPbEkNTs1tSC1CCYrw8GhJMH79RpQo2BRanpqRVpmTglCmomDE2Q4\r
+ D9DwSSA1vMUFibnFmekQ+VOMilLivAtAEgIgiYzSPLheWLp4xSgO9Iowr+F1oCoeYKqB634F\r
+ NJgJaPCKsw9ABpckIqSkGhjX7+IPKXtiFzmvWdu1oDkj8dl+k/CftZMvXp6h8MZQ+MIUb73q\r
+ NF8jjwzBbR0PeB7d+BdiNvPetnqO81b1e99wr7p7Qnv/zb2aX3N5Xuk5ntzTfW/W/1vvBB4a\r
+ yfFFPn99TqL90B5+zYMcupWe5Zwn1DoEbz09ZeeovfF4pY7gIcejh/a+vrxEiaU4I9FQi7mo\r
+ OBEAkcueSvICAAA=\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, 24 Jan 2014 21:18:32 -0000\r
+\r
+On Thu, 09 Jan 2014, Jani Nikula <jani@nikula.org> wrote:\r
+> In xapian terms, convert folder: prefix from probabilistic to boolean\r
+> prefix. This change constitutes a database change: bump the database\r
+> version and add database upgrade support.\r
+> ---\r
+> lib/database.cc | 39 ++++++++++++-\r
+> lib/message.cc | 154 +++++++++++++++++++++++++-------------------------\r
+> lib/notmuch-private.h | 3 +\r
+> 3 files changed, 117 insertions(+), 79 deletions(-)\r
+>\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index f395061..145fd66 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
+> @@ -208,7 +208,8 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
+> { "thread", "G" },\r
+> { "tag", "K" },\r
+> { "is", "K" },\r
+> - { "id", "Q" }\r
+> + { "id", "Q" },\r
+> + { "folder", "P" },\r
+> };\r
+> \r
+> static prefix_t PROBABILISTIC_PREFIX[]= {\r
+> @@ -216,7 +217,6 @@ static prefix_t PROBABILISTIC_PREFIX[]= {\r
+> { "to", "XTO" },\r
+> { "attachment", "XATTACHMENT" },\r
+> { "subject", "XSUBJECT"},\r
+> - { "folder", "XFOLDER"}\r
+> };\r
+> \r
+> const char *\r
+> @@ -1167,6 +1167,39 @@ 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.\r
+> + */\r
+> + if (version < 2) {\r
+> + notmuch_query_t *query = notmuch_query_create (notmuch, "");\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
+\r
+Unless I'm missing something, the upgrade isn't done atomically. Should\r
+it be? (The answer may be "no", since this process appears to be\r
+idempotent; though it may simply be easier to reason about if it is\r
+atomic.)\r
+\r
+Everything else in this patch LGTM (modulo my complaint about stripping\r
+cur/new).\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 1b46379..500aa26 100644\r
+> --- a/lib/message.cc\r
+> +++ b/lib/message.cc\r
+> @@ -505,89 +505,27 @@ _notmuch_message_add_filename (notmuch_message_t *message,\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
+> + _notmuch_message_add_term (message, "folder", directory);\r
+> \r
+> talloc_free (local);\r
+> \r
+> return NOTMUCH_STATUS_SUCCESS;\r
+> }\r
+> \r
+> -/* Remove a particular 'filename' from 'message'.\r
+> - *\r
+> - * This change will not be reflected in the database until the next\r
+> - * call to _notmuch_message_sync.\r
+> - *\r
+> - * If this message still has other filenames, returns\r
+> - * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID.\r
+> - *\r
+> - * Note: This function does not remove a document from the database,\r
+> - * even if the specified filename is the only filename for this\r
+> - * message. For that functionality, see\r
+> - * _notmuch_database_remove_message. */\r
+> -notmuch_status_t\r
+> -_notmuch_message_remove_filename (notmuch_message_t *message,\r
+> - const char *filename)\r
+> +static void\r
+> +_notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)\r
+> {\r
+> - const char *direntry_prefix = _find_prefix ("file-direntry");\r
+> - int direntry_prefix_len = strlen (direntry_prefix);\r
+> - const char *folder_prefix = _find_prefix ("folder");\r
+> - int folder_prefix_len = strlen (folder_prefix);\r
+> - void *local = talloc_new (message);\r
+> - char *zfolder_prefix = talloc_asprintf(local, "Z%s", folder_prefix);\r
+> - int zfolder_prefix_len = strlen (zfolder_prefix);\r
+> - char *direntry;\r
+> - notmuch_private_status_t private_status;\r
+> - notmuch_status_t status;\r
+> - Xapian::TermIterator i, last;\r
+> -\r
+> - status = _notmuch_database_filename_to_direntry (\r
+> - local, message->notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);\r
+> - if (status || !direntry)\r
+> - return status;\r
+> + Xapian::TermIterator i;\r
+> + size_t prefix_len = strlen (prefix);\r
+> \r
+> - /* Unlink this file from its parent directory. */\r
+> - private_status = _notmuch_message_remove_term (message,\r
+> - "file-direntry", direntry);\r
+> - status = COERCE_STATUS (private_status,\r
+> - "Unexpected error from _notmuch_message_remove_term");\r
+> - if (status)\r
+> - return status;\r
+> -\r
+> - /* Re-synchronize "folder:" terms for this message. This requires:\r
+> - * 1. removing all "folder:" terms\r
+> - * 2. removing all "folder:" stemmed terms\r
+> - * 3. adding back terms for all remaining filenames of the message. */\r
+> -\r
+> - /* 1. removing all "folder:" terms */\r
+> while (1) {\r
+> i = message->doc.termlist_begin ();\r
+> - i.skip_to (folder_prefix);\r
+> + i.skip_to (prefix);\r
+> \r
+> /* Terminate loop when no terms remain with desired prefix. */\r
+> if (i == message->doc.termlist_end () ||\r
+> - strncmp ((*i).c_str (), folder_prefix, folder_prefix_len))\r
+> - {\r
+> + strncmp ((*i).c_str (), prefix, prefix_len))\r
+> break;\r
+> - }\r
+> -\r
+> - try {\r
+> - message->doc.remove_term ((*i));\r
+> - } catch (const Xapian::InvalidArgumentError) {\r
+> - /* Ignore failure to remove non-existent term. */\r
+> - }\r
+> - }\r
+> -\r
+> - /* 2. removing all "folder:" stemmed terms */\r
+> - while (1) {\r
+> - i = message->doc.termlist_begin ();\r
+> - i.skip_to (zfolder_prefix);\r
+> -\r
+> - /* Terminate loop when no terms remain with desired prefix. */\r
+> - if (i == message->doc.termlist_end () ||\r
+> - strncmp ((*i).c_str (), zfolder_prefix, zfolder_prefix_len))\r
+> - {\r
+> - break;\r
+> - }\r
+> \r
+> try {\r
+> message->doc.remove_term ((*i));\r
+> @@ -595,12 +533,18 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+> /* Ignore failure to remove non-existent term. */\r
+> }\r
+> }\r
+> +}\r
+> \r
+> - /* 3. adding back terms for all remaining filenames of the message. */\r
+> - i = message->doc.termlist_begin ();\r
+> - i.skip_to (direntry_prefix);\r
+> +/* Add "folder:" terms for all filenames of the message. */\r
+> +static notmuch_status_t\r
+> +_notmuch_message_add_folder_terms (void *ctx, notmuch_message_t *message)\r
+> +{\r
+> + const char *direntry_prefix = _find_prefix ("file-direntry");\r
+> + int direntry_prefix_len = strlen (direntry_prefix);\r
+> + Xapian::TermIterator i = message->doc.termlist_begin ();\r
+> + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
+> \r
+> - for (; i != message->doc.termlist_end (); i++) {\r
+> + for (i.skip_to (direntry_prefix); i != message->doc.termlist_end (); i++) {\r
+> unsigned int directory_id;\r
+> const char *direntry, *directory;\r
+> char *colon;\r
+> @@ -620,18 +564,76 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+> if (colon == NULL || *colon != ':')\r
+> INTERNAL_ERROR ("malformed direntry");\r
+> \r
+> - directory = _notmuch_database_get_directory_path (local,\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
+> + _notmuch_message_add_term (message, "folder", directory);\r
+> }\r
+> \r
+> + return status;\r
+> +}\r
+> +\r
+> +/* Remove a particular 'filename' from 'message'.\r
+> + *\r
+> + * This change will not be reflected in the database until the next\r
+> + * call to _notmuch_message_sync.\r
+> + *\r
+> + * If this message still has other filenames, returns\r
+> + * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID.\r
+> + *\r
+> + * Note: This function does not remove a document from the database,\r
+> + * even if the specified filename is the only filename for this\r
+> + * message. For that functionality, see\r
+> + * _notmuch_database_remove_message. */\r
+> +notmuch_status_t\r
+> +_notmuch_message_remove_filename (notmuch_message_t *message,\r
+> + const char *filename)\r
+> +{\r
+> + void *local = talloc_new (message);\r
+> + char *direntry;\r
+> + notmuch_private_status_t private_status;\r
+> + notmuch_status_t status;\r
+> +\r
+> + status = _notmuch_database_filename_to_direntry (\r
+> + local, message->notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);\r
+> + if (status || !direntry)\r
+> + return status;\r
+> +\r
+> + /* Unlink this file from its parent directory. */\r
+> + private_status = _notmuch_message_remove_term (message,\r
+> + "file-direntry", direntry);\r
+> + status = COERCE_STATUS (private_status,\r
+> + "Unexpected error from _notmuch_message_remove_term");\r
+> + if (status)\r
+> + return status;\r
+> +\r
+> + /* Remove all "folder:" terms from the message. */\r
+> + _notmuch_message_remove_terms (message, _find_prefix ("folder"));\r
+> +\r
+> + /* Add back "folder:" terms for all remaining filenames of the message. */\r
+> + status = _notmuch_message_add_folder_terms (local, message);\r
+> +\r
+> talloc_free (local);\r
+> \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:" terms. */\r
+> + _notmuch_message_add_folder_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
+> -- \r
+> 1.8.5.2\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r