[PATCH v2 00/14] Implement and use database "features"
Austin Clements
amdragon at MIT.EDU
Tue Jul 29 09:47:58 PDT 2014
This is version 2 of
id:1406433173-19169-1-git-send-email-amdragon at mit.edu. It fixes a bug
pointed out by Mark [1] where the upgrade test would fail if the
prerequisites were not available (rather than cleanly skipping the
test like before). It also makes feature names more user-friendly and
eliminates notmuch->needs_upgrade in favor of computing it on-the-fly
in notmuch_database_needs_upgrade. The diff from v1 is below.
[1] id:871tt718xp.fsf at qmul.ac.uk
diff --git a/lib/database-private.h b/lib/database-private.h
index 323b9fe..2ffab33 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -41,7 +41,6 @@ struct _notmuch_database {
char *path;
- notmuch_bool_t needs_upgrade;
notmuch_database_mode_t mode;
int atomic_nesting;
Xapian::Database *xapian_db;
diff --git a/lib/database.cc b/lib/database.cc
index f105e27..b323691 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -238,7 +238,6 @@ static prefix_t PROBABILISTIC_PREFIX[]= {
{ "subject", "XSUBJECT"},
};
-
const char *
_find_prefix (const char *name)
{
@@ -275,12 +274,12 @@ static const struct
/* Compatibility flags when this feature is declared. */
const char *flags;
} feature_names[] = {
- {NOTMUCH_FEATURE_FILE_TERMS, "file terms", "rw"},
- {NOTMUCH_FEATURE_DIRECTORY_DOCS, "directory documents", "rw"},
+ {NOTMUCH_FEATURE_FILE_TERMS, "multiple paths per message", "rw"},
+ {NOTMUCH_FEATURE_DIRECTORY_DOCS, "relative directory paths", "rw"},
/* Header values are not required for reading a database because a
* reader can just refer to the message file. */
- {NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, "from/subject/ID values", "w"},
- {NOTMUCH_FEATURE_BOOL_FOLDER, "boolean folder terms", "rw"},
+ {NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, "from/subject/message-ID in database", "w"},
+ {NOTMUCH_FEATURE_BOOL_FOLDER, "exact folder:/path: search", "rw"},
};
const char *
@@ -790,7 +789,6 @@ notmuch_database_open (const char *path,
if (notmuch->path[strlen (notmuch->path) - 1] == '/')
notmuch->path[strlen (notmuch->path) - 1] = '\0';
- notmuch->needs_upgrade = FALSE;
notmuch->mode = mode;
notmuch->atomic_nesting = 0;
try {
@@ -839,11 +837,6 @@ notmuch_database_open (const char *path,
goto DONE;
}
- /* Do we want an upgrade? */
- if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE &&
- NOTMUCH_FEATURES_CURRENT & ~notmuch->features)
- notmuch->needs_upgrade = TRUE;
-
notmuch->last_doc_id = notmuch->xapian_db->get_lastdocid ();
last_thread_id = notmuch->xapian_db->get_metadata ("last_thread_id");
if (last_thread_id.empty ()) {
@@ -1173,7 +1166,8 @@ notmuch_database_get_version (notmuch_database_t *notmuch)
notmuch_bool_t
notmuch_database_needs_upgrade (notmuch_database_t *notmuch)
{
- return notmuch->needs_upgrade;
+ return notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE &&
+ (NOTMUCH_FEATURES_CURRENT & ~notmuch->features);
}
static volatile sig_atomic_t do_progress_notify = 0;
diff --git a/test/T530-upgrade.sh b/test/T530-upgrade.sh
index c88bbc7..c4c4ac8 100755
--- a/test/T530-upgrade.sh
+++ b/test/T530-upgrade.sh
@@ -3,52 +3,6 @@ test_description="database upgrade"
. ./test-lib.sh
-test_begin_subtest "future database versions abort open"
-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 9999 ""
-output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
-rm -rf ${MAIL_DIR}/.notmuch
-test_expect_equal "$output" "\
-Error: Notmuch database at FILENAME
- has a newer database format version (9999) than supported by this
- version of notmuch (3)."
-
-test_begin_subtest "unknown 'rw' feature aborts read/write open"
-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\trw'
-output=$(notmuch new 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
-rm -rf ${MAIL_DIR}/.notmuch
-test_expect_equal "$output" "\
-Error: Notmuch database at FILENAME
- requires features (test feature)
- not supported by this version of notmuch."
-
-test_begin_subtest "unknown 'rw' feature aborts read-only open"
-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\trw'
-output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
-rm -rf ${MAIL_DIR}/.notmuch
-test_expect_equal "$output" "\
-Error: Notmuch database at FILENAME
- requires features (test feature)
- not supported by this version of notmuch."
-
-test_begin_subtest "unknown 'w' feature aborts read/write open"
-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\tw'
-output=$(notmuch new 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
-rm -rf ${MAIL_DIR}/.notmuch
-test_expect_equal "$output" "\
-Error: Notmuch database at FILENAME
- requires features (test feature)
- not supported by this version of notmuch."
-
-test_begin_subtest "unknown 'w' feature does not abort read-only open"
-${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\tw'
-output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
-rm -rf ${MAIL_DIR}/.notmuch
-test_expect_equal "$output" ""
-
-#
-# Database v1
-#
-
dbtarball=database-v1.tar.xz
# XXX: Accomplish the same with test lib helpers
diff --git a/test/T550-db-features.sh b/test/T550-db-features.sh
new file mode 100755
index 0000000..5569768
--- /dev/null
+++ b/test/T550-db-features.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+test_description="database version and feature compatibility"
+
+. ./test-lib.sh
+
+test_begin_subtest "future database versions abort open"
+${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 9999 ""
+output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
+rm -rf ${MAIL_DIR}/.notmuch
+test_expect_equal "$output" "\
+Error: Notmuch database at FILENAME
+ has a newer database format version (9999) than supported by this
+ version of notmuch (3)."
+
+test_begin_subtest "unknown 'rw' feature aborts read/write open"
+${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\trw'
+output=$(notmuch new 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
+rm -rf ${MAIL_DIR}/.notmuch
+test_expect_equal "$output" "\
+Error: Notmuch database at FILENAME
+ requires features (test feature)
+ not supported by this version of notmuch."
+
+test_begin_subtest "unknown 'rw' feature aborts read-only open"
+${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\trw'
+output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
+rm -rf ${MAIL_DIR}/.notmuch
+test_expect_equal "$output" "\
+Error: Notmuch database at FILENAME
+ requires features (test feature)
+ not supported by this version of notmuch."
+
+test_begin_subtest "unknown 'w' feature aborts read/write open"
+${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\tw'
+output=$(notmuch new 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
+rm -rf ${MAIL_DIR}/.notmuch
+test_expect_equal "$output" "\
+Error: Notmuch database at FILENAME
+ requires features (test feature)
+ not supported by this version of notmuch."
+
+test_begin_subtest "unknown 'w' feature does not abort read-only open"
+${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 3 $'test feature\tw'
+output=$(notmuch search x 2>&1 | sed 's/\(database at\) .*/\1 FILENAME/')
+rm -rf ${MAIL_DIR}/.notmuch
+test_expect_equal "$output" ""
+
+test_done
More information about the notmuch
mailing list