[PATCH 09/14] lib: Use database features to drive upgrade
authorAustin Clements <amdragon@MIT.EDU>
Sun, 27 Jul 2014 03:52:48 +0000 (23:52 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:03:53 +0000 (10:03 -0800)
6f/06cae541e7d4e6d04dd8bd42b8a2267eefced5 [new file with mode: 0644]

diff --git a/6f/06cae541e7d4e6d04dd8bd42b8a2267eefced5 b/6f/06cae541e7d4e6d04dd8bd42b8a2267eefced5
new file mode 100644 (file)
index 0000000..47fbc25
--- /dev/null
@@ -0,0 +1,166 @@
+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 15C23431FC7\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:54:02 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] 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 4hE6-G5nrxNH for <notmuch@notmuchmail.org>;\r
+       Sat, 26 Jul 2014 20:53:56 -0700 (PDT)\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 80D20431FDB\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:15 -0700 (PDT)\r
+X-AuditID: 1209190d-f79c06d000002f07-b7-53d477a99c88\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\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 D6.E8.12039.9A774D35; Sat, 26 Jul 2014 23:53:13 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s6R3r2gT014364; \r
+       Sat, 26 Jul 2014 23:53:02 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (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 s6R3r0UG016404\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 26 Jul 2014 23:53:01 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1XBFW8-00051T-DJ; Sat, 26 Jul 2014 23:53:00 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 09/14] lib: Use database features to drive upgrade\r
+Date: Sat, 26 Jul 2014 23:52:48 -0400\r
+Message-Id: <1406433173-19169-10-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <1406433173-19169-1-git-send-email-amdragon@mit.edu>\r
+References: <1406433173-19169-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixG6noruy/EqwwbwnGhbXb85kdmD0eLbq\r
+       FnMAYxSXTUpqTmZZapG+XQJXxpkjTawFS6QqLm+ew9TA2CLaxcjBISFgIrF8X1EXIyeQKSZx\r
+       4d56ti5GLg4hgdlMEq1velkhnI2MEpuONbBDOHeYJC41drOAtAgJzGWU2L/PEcRmE9CQ2LZ/\r
+       OSOILSIgLbHz7mxWkA3MAmoSf7pUQMLCAk4Smz++YAexWQRUJbY9u84MYvMKOEpMXXGADeIK\r
+       OYmGG5/AbE6g+PFnJ9hAxggJOEjcupQ4gZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl0j\r
+       vdzMEr3UlNJNjKCA4ZTk3cH47qDSIUYBDkYlHt4MtivBQqyJZcWVuYcYJTmYlER595sBhfiS\r
+       8lMqMxKLM+KLSnNSiw8xSnAwK4nwChUD5XhTEiurUovyYVLSHCxK4rxvra2ChQTSE0tSs1NT\r
+       C1KLYLIyHBxKErzTy4AaBYtS01Mr0jJzShDSTBycIMN5gIZvKAUZXlyQmFucmQ6RP8WoKCXO\r
+       +wskIQCSyCjNg+uFRfQrRnGgV4R5WUFW8ACTAVz3K6DBTECDWfwvgwwuSURISTUwLv7K28pq\r
+       0hJWszC9y2RtTsSaq3zz4vMlUk99mB3C0h0fd/7e2/tOH6ZLRc3t5y/11H9vpqAtuvLppsmz\r
+       L6mEabItc9sZqL7zg63FZvusC5fWXjDbaPXxXplThYt/DPvpwwsvStTzJT/QSCjs3TajSsOl\r
+       0vhm65dPrx8rP4i165+tKDdJMMxaiaU4I9FQi7moOBEA2Yubi8MCAAA=\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, 27 Jul 2014 03:54:02 -0000\r
+\r
+Previously, we had database version information hard-coded in the\r
+upgrade code.  Slightly re-organize the upgrade process around the set\r
+of new database features to be enabled by the upgrade.\r
+---\r
+ lib/database.cc | 24 +++++++++++++-----------\r
+ 1 file changed, 13 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 0be7180..1dd2cd9 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1201,11 +1201,12 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+                         void *closure)\r
+ {\r
+     void *local = talloc_new (NULL);\r
++    Xapian::TermIterator t, t_end;\r
+     Xapian::WritableDatabase *db;\r
+     struct sigaction action;\r
+     struct itimerval timerval;\r
+     notmuch_bool_t timer_is_active = FALSE;\r
+-    unsigned int version;\r
++    unsigned int target_features, new_features;\r
+     notmuch_status_t status;\r
+     unsigned int count = 0, total = 0;\r
\r
+@@ -1215,9 +1216,10 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
\r
+     db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);\r
\r
+-    version = notmuch_database_get_version (notmuch);\r
++    target_features = notmuch->features | NOTMUCH_FEATURES_CURRENT;\r
++    new_features = NOTMUCH_FEATURES_CURRENT & ~notmuch->features;\r
\r
+-    if (version >= NOTMUCH_DATABASE_VERSION)\r
++    if (! new_features)\r
+       return NOTMUCH_STATUS_SUCCESS;\r
\r
+     if (progress_notify) {\r
+@@ -1245,12 +1247,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+      * data field. Copy that into the new format by calling\r
+      * notmuch_message_add_filename.\r
+      */\r
+-    if (version < 1) {\r
++    if (new_features & NOTMUCH_FEATURE_FILE_TERMS) {\r
+       notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
+       notmuch_messages_t *messages;\r
+       notmuch_message_t *message;\r
+       char *filename;\r
+-      Xapian::TermIterator t, t_end;\r
\r
+       total = notmuch_query_count_messages (query);\r
\r
+@@ -1279,11 +1280,12 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+       }\r
\r
+       notmuch_query_destroy (query);\r
++    }\r
\r
+-      /* Also, before version 1 we stored directory timestamps in\r
+-       * XTIMESTAMP documents instead of the current XDIRECTORY\r
+-       * documents. So copy those as well. */\r
+-\r
++    /* Also, before version 1 we stored directory timestamps in\r
++     * XTIMESTAMP documents instead of the current XDIRECTORY\r
++     * documents. So copy those as well. */\r
++    if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
+       t_end = notmuch->xapian_db->allterms_end ("XTIMESTAMP");\r
\r
+       for (t = notmuch->xapian_db->allterms_begin ("XTIMESTAMP");\r
+@@ -1327,7 +1329,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+      * stemmed. Change it to the current boolean prefix. Add "path:"\r
+      * prefixes while at it.\r
+      */\r
+-    if (version < 2) {\r
++    if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER) {\r
+       notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
+       notmuch_messages_t *messages;\r
+       notmuch_message_t *message;\r
+@@ -1356,7 +1358,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+       notmuch_query_destroy (query);\r
+     }\r
\r
+-    notmuch->features |= NOTMUCH_FEATURES_CURRENT;\r
++    notmuch->features = target_features;\r
+     db->set_metadata ("features", _print_features (local, notmuch->features));\r
+     db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));\r
\r
+-- \r
+2.0.0\r
+\r