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