--- /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 15DB7431E62\r
+ for <notmuch@notmuchmail.org>; Tue, 29 Jul 2014 09:48:36 -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 8XxPaj8Gw+Dd for <notmuch@notmuchmail.org>;\r
+ Tue, 29 Jul 2014 09:48:27 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu\r
+ [18.9.25.14])\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 33CB6431FC3\r
+ for <notmuch@notmuchmail.org>; Tue, 29 Jul 2014 09:48:21 -0700 (PDT)\r
+X-AuditID: 1209190e-f79946d000007db1-be-53d7d052b4c2\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id B8.F5.32177.350D7D35; Tue, 29 Jul 2014 12:48:19 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s6TGmHM2003473; \r
+ Tue, 29 Jul 2014 12:48:18 -0400\r
+Received: from drake.dyndns.org (31-33-71.wireless.csail.mit.edu\r
+ [128.31.33.71]) (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 s6TGmFNk030242\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Tue, 29 Jul 2014 12:48:17 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1XCAZS-0007GZ-Ky; Tue, 29 Jul 2014 12:48:14 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 00/14] Implement and use database "features"\r
+Date: Tue, 29 Jul 2014 12:47:58 -0400\r
+Message-Id: <1406652492-27803-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrBt84XqwQf8JdovVc3ksrt+cyezA\r
+ 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZexvecZYcM66Yv2kk+wNjG2GXYycHBICJhIN\r
+ 87eyQNhiEhfurWfrYuTiEBKYzSQxacU9JghnI6NE6+XNUM4xJok5y6ZAOXMZJRpmtLGB9LMJ\r
+ aEhs27+cEcQWEZCW2Hl3NiuIzSwgK/Hj/B8wW1jAXuLzur9g9SwCqhINEz+wg9i8Ag4SG69+\r
+ Y4W4Q06i4cYntgmMvAsYGVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpGuvlZpbopaaUbmIEh4Yk\r
+ 3w7GrweVDjEKcDAq8fBumHstWIg1say4MvcQoyQHk5Ior96+68FCfEn5KZUZicUZ8UWlOanF\r
+ hxglOJiVRHj5zgLleFMSK6tSi/JhUtIcLErivG+trYKFBNITS1KzU1MLUotgsjIcHEoSvK/P\r
+ AzUKFqWmp1akZeaUIKSZODhBhvMADd8HUsNbXJCYW5yZDpE/xajL8aH3TBuTEEtefl6qlDjv\r
+ JpAiAZCijNI8uDmwmH7FKA70ljDvQZAqHmA6gJv0CmgJE9ASVhewJSWJCCmpBkY+o9IvuUzm\r
+ IU47p2ld6sxYpKvJcZi5XOF0VJ9wyKw51TWBmbs2PKqfvH8Ot9tUOxNhi8KAZrdlYVoTlS/c\r
+ 1mD9Nj/amHNB1kaTDLWwQ4d7/jSLm1+PrLU+ulbiydnwEwtkwqP3H5+29e2XJbmSkQclkz6z\r
+ zjffGD+xZbGS+84v/47ytm3cdESJpTgj0VCLuag4EQBdjj2VxAIAAA==\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, 29 Jul 2014 16:48:36 -0000\r
+\r
+This is version 2 of\r
+id:1406433173-19169-1-git-send-email-amdragon@mit.edu. It fixes a bug\r
+pointed out by Mark [1] where the upgrade test would fail if the\r
+prerequisites were not available (rather than cleanly skipping the\r
+test like before). It also makes feature names more user-friendly and\r
+eliminates notmuch->needs_upgrade in favor of computing it on-the-fly\r
+in notmuch_database_needs_upgrade. The diff from v1 is below.\r
+\r
+[1] id:871tt718xp.fsf@qmul.ac.uk\r
+\r
+diff --git a/lib/database-private.h b/lib/database-private.h\r
+index 323b9fe..2ffab33 100644\r
+--- a/lib/database-private.h\r
++++ b/lib/database-private.h\r
+@@ -41,7 +41,6 @@ struct _notmuch_database {\r
+ \r
+ char *path;\r
+ \r
+- notmuch_bool_t needs_upgrade;\r
+ notmuch_database_mode_t mode;\r
+ int atomic_nesting;\r
+ Xapian::Database *xapian_db;\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index f105e27..b323691 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -238,7 +238,6 @@ static prefix_t PROBABILISTIC_PREFIX[]= {\r
+ { "subject", "XSUBJECT"},\r
+ };\r
+ \r
+-\r
+ const char *\r
+ _find_prefix (const char *name)\r
+ {\r
+@@ -275,12 +274,12 @@ static const struct\r
+ /* Compatibility flags when this feature is declared. */\r
+ const char *flags;\r
+ } feature_names[] = {\r
+- {NOTMUCH_FEATURE_FILE_TERMS, "file terms", "rw"},\r
+- {NOTMUCH_FEATURE_DIRECTORY_DOCS, "directory documents", "rw"},\r
++ {NOTMUCH_FEATURE_FILE_TERMS, "multiple paths per message", "rw"},\r
++ {NOTMUCH_FEATURE_DIRECTORY_DOCS, "relative directory paths", "rw"},\r
+ /* Header values are not required for reading a database because a\r
+ * reader can just refer to the message file. */\r
+- {NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, "from/subject/ID values", "w"},\r
+- {NOTMUCH_FEATURE_BOOL_FOLDER, "boolean folder terms", "rw"},\r
++ {NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, "from/subject/message-ID in database", "w"},\r
++ {NOTMUCH_FEATURE_BOOL_FOLDER, "exact folder:/path: search", "rw"},\r
+ };\r
+ \r
+ const char *\r
+@@ -790,7 +789,6 @@ notmuch_database_open (const char *path,\r
+ if (notmuch->path[strlen (notmuch->path) - 1] == '/')\r
+ notmuch->path[strlen (notmuch->path) - 1] = '\0';\r
+ \r
+- notmuch->needs_upgrade = FALSE;\r
+ notmuch->mode = mode;\r
+ notmuch->atomic_nesting = 0;\r
+ try {\r
+@@ -839,11 +837,6 @@ notmuch_database_open (const char *path,\r
+ goto DONE;\r
+ }\r
+ \r
+- /* Do we want an upgrade? */\r
+- if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE &&\r
+- NOTMUCH_FEATURES_CURRENT & ~notmuch->features)\r
+- notmuch->needs_upgrade = TRUE;\r
+-\r
+ notmuch->last_doc_id = notmuch->xapian_db->get_lastdocid ();\r
+ last_thread_id = notmuch->xapian_db->get_metadata ("last_thread_id");\r
+ if (last_thread_id.empty ()) {\r
+@@ -1173,7 +1166,8 @@ notmuch_database_get_version (notmuch_database_t *notmuch)\r
+ notmuch_bool_t\r
+ notmuch_database_needs_upgrade (notmuch_database_t *notmuch)\r
+ {\r
+- return notmuch->needs_upgrade;\r
++ return notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE &&\r
++ (NOTMUCH_FEATURES_CURRENT & ~notmuch->features);\r
+ }\r
+ \r
+ static volatile sig_atomic_t do_progress_notify = 0;\r
+diff --git a/test/T530-upgrade.sh b/test/T530-upgrade.sh\r
+index c88bbc7..c4c4ac8 100755\r
+--- a/test/T530-upgrade.sh\r
++++ b/test/T530-upgrade.sh\r
+@@ -3,52 +3,6 @@ test_description="database upgrade"\r
+ \r
+ . ./test-lib.sh\r
+ \r
+-test_begin_subtest "future database versions abort open"\r
+-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 9999 ""\r
+-output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
+-rm -rf ${MAIL_DIR}/.notmuch\r
+-test_expect_equal "$output" "\\r
+-Error: Notmuch database at FILENAME\r
+- has a newer database format version (9999) than supported by this\r
+- version of notmuch (3)."\r
+-\r
+-test_begin_subtest "unknown 'rw' feature aborts read/write open"\r
+-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\trw'\r
+-output=$(notmuch new 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
+-rm -rf ${MAIL_DIR}/.notmuch\r
+-test_expect_equal "$output" "\\r
+-Error: Notmuch database at FILENAME\r
+- requires features (test feature)\r
+- not supported by this version of notmuch."\r
+-\r
+-test_begin_subtest "unknown 'rw' feature aborts read-only open"\r
+-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\trw'\r
+-output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
+-rm -rf ${MAIL_DIR}/.notmuch\r
+-test_expect_equal "$output" "\\r
+-Error: Notmuch database at FILENAME\r
+- requires features (test feature)\r
+- not supported by this version of notmuch."\r
+-\r
+-test_begin_subtest "unknown 'w' feature aborts read/write open"\r
+-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\tw'\r
+-output=$(notmuch new 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
+-rm -rf ${MAIL_DIR}/.notmuch\r
+-test_expect_equal "$output" "\\r
+-Error: Notmuch database at FILENAME\r
+- requires features (test feature)\r
+- not supported by this version of notmuch."\r
+-\r
+-test_begin_subtest "unknown 'w' feature does not abort read-only open"\r
+-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\tw'\r
+-output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
+-rm -rf ${MAIL_DIR}/.notmuch\r
+-test_expect_equal "$output" ""\r
+-\r
+-#\r
+-# Database v1\r
+-#\r
+-\r
+ dbtarball=database-v1.tar.xz\r
+ \r
+ # XXX: Accomplish the same with test lib helpers\r
+diff --git a/test/T550-db-features.sh b/test/T550-db-features.sh\r
+new file mode 100755\r
+index 0000000..5569768\r
+--- /dev/null\r
++++ b/test/T550-db-features.sh\r
+@@ -0,0 +1,48 @@\r
++#!/usr/bin/env bash\r
++test_description="database version and feature compatibility"\r
++\r
++. ./test-lib.sh\r
++\r
++test_begin_subtest "future database versions abort open"\r
++${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 9999 ""\r
++output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
++rm -rf ${MAIL_DIR}/.notmuch\r
++test_expect_equal "$output" "\\r
++Error: Notmuch database at FILENAME\r
++ has a newer database format version (9999) than supported by this\r
++ version of notmuch (3)."\r
++\r
++test_begin_subtest "unknown 'rw' feature aborts read/write open"\r
++${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\trw'\r
++output=$(notmuch new 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
++rm -rf ${MAIL_DIR}/.notmuch\r
++test_expect_equal "$output" "\\r
++Error: Notmuch database at FILENAME\r
++ requires features (test feature)\r
++ not supported by this version of notmuch."\r
++\r
++test_begin_subtest "unknown 'rw' feature aborts read-only open"\r
++${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\trw'\r
++output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
++rm -rf ${MAIL_DIR}/.notmuch\r
++test_expect_equal "$output" "\\r
++Error: Notmuch database at FILENAME\r
++ requires features (test feature)\r
++ not supported by this version of notmuch."\r
++\r
++test_begin_subtest "unknown 'w' feature aborts read/write open"\r
++${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\tw'\r
++output=$(notmuch new 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
++rm -rf ${MAIL_DIR}/.notmuch\r
++test_expect_equal "$output" "\\r
++Error: Notmuch database at FILENAME\r
++ requires features (test feature)\r
++ not supported by this version of notmuch."\r
++\r
++test_begin_subtest "unknown 'w' feature does not abort read-only open"\r
++${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\tw'\r
++output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')\r
++rm -rf ${MAIL_DIR}/.notmuch\r
++test_expect_equal "$output" ""\r
++\r
++test_done\r
+\r
+\r