--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id A90A46DE1B72\r
+ for <notmuch@notmuchmail.org>; Sun, 5 Apr 2015 16:01:18 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.575\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.575 tagged_above=-999 required=5 tests=[AWL=0.565, \r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id mGpQNBG8B7aO for <notmuch@notmuchmail.org>;\r
+ Sun, 5 Apr 2015 16:01:17 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id D369E6DE1B6F\r
+ for <notmuch@notmuchmail.org>; Sun, 5 Apr 2015 16:01:16 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1YetWs-0002ob-TW; Sun, 05 Apr 2015 23:00:34 +0000\r
+Received: (nullmailer pid 2259 invoked by uid 1000); Sun, 05 Apr 2015\r
+ 22:59:25 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP2 12/12] cli: add global option "--db-revision"\r
+Date: Mon, 6 Apr 2015 07:59:14 +0900\r
+Message-Id: <1428274754-1698-13-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net>\r
+References: <1428274754-1698-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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, 05 Apr 2015 23:01:18 -0000\r
+\r
+The function notmuch_exit_if_unmatched_db_revision is split from\r
+notmuch_process_shared_options because it needs an open notmuch\r
+database.\r
+---\r
+ notmuch-client.h | 5 +++++\r
+ notmuch-compact.c | 4 ++++\r
+ notmuch-config.c | 4 ++++\r
+ notmuch-count.c | 2 ++\r
+ notmuch-dump.c | 2 ++\r
+ notmuch-insert.c | 2 ++\r
+ notmuch-new.c | 3 ++-\r
+ notmuch-reply.c | 2 ++\r
+ notmuch-restore.c | 2 ++\r
+ notmuch-search.c | 2 ++\r
+ notmuch-setup.c | 4 ++++\r
+ notmuch-show.c | 2 ++\r
+ notmuch-tag.c | 2 ++\r
+ notmuch.c | 18 ++++++++++++++++++\r
+ 14 files changed, 53 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 76dbc38..24aa78a 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -466,6 +466,11 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
+ notmuch_bool_t gzip_output);\r
+ \r
+ #include "command-line-arguments.h"\r
++\r
++extern char *notmuch_requested_db_revision;\r
+ extern const notmuch_opt_desc_t notmuch_shared_options [];\r
+ void notmuch_process_shared_options (const char* help_name);\r
++\r
++void notmuch_exit_if_unmatched_db_revision (notmuch_database_t *notmuch);\r
++\r
+ #endif\r
+diff --git a/notmuch-compact.c b/notmuch-compact.c\r
+index 5be551d..3da4bfb 100644\r
+--- a/notmuch-compact.c\r
++++ b/notmuch-compact.c\r
+@@ -46,6 +46,10 @@ notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])\r
+ if (opt_index < 0)\r
+ return EXIT_FAILURE;\r
+ \r
++ if (notmuch_requested_db_revision)\r
++ fprintf (stderr, "Warning: ignoring --db-revision=%s\n",\r
++ notmuch_requested_db_revision);\r
++\r
+ notmuch_process_shared_options (argv[0]);\r
+ \r
+ if (! quiet)\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index 568b3dc..a9d4e73 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -883,6 +883,10 @@ notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])\r
+ if (opt_index < 0)\r
+ return EXIT_FAILURE;\r
+ \r
++ if (notmuch_requested_db_revision)\r
++ fprintf (stderr, "Warning: ignoring --db-revision=%s\n",\r
++ notmuch_requested_db_revision);\r
++\r
+ notmuch_process_shared_options (argv[0]);\r
+ \r
+ /* skip subcommand argument */\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index 57a88a8..e29ac2b 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -175,6 +175,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return EXIT_FAILURE;\r
+ \r
++ notmuch_exit_if_unmatched_db_revision (notmuch);\r
++\r
+ query_str = query_string_from_args (config, argc-opt_index, argv+opt_index);\r
+ if (query_str == NULL) {\r
+ fprintf (stderr, "Out of memory.\n");\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index fab22bd..9c0b82d 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -215,6 +215,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+ return EXIT_FAILURE;\r
+ \r
++ notmuch_exit_if_unmatched_db_revision (notmuch);\r
++\r
+ char *output_file_name = NULL;\r
+ int opt_index;\r
+ \r
+diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+index 697880f..63b7a48 100644\r
+--- a/notmuch-insert.c\r
++++ b/notmuch-insert.c\r
+@@ -536,6 +536,8 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+ return EXIT_FAILURE;\r
+ \r
++ notmuch_exit_if_unmatched_db_revision (notmuch);\r
++\r
+ /* Write the message to the Maildir new directory. */\r
+ newpath = maildir_write_new (config, STDIN_FILENO, maildir);\r
+ if (! newpath) {\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 895f5d9..e494a3b 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -995,10 +995,11 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+ fputs (status_string, stderr);\r
+ free (status_string);\r
+ }\r
+-\r
+ return EXIT_FAILURE;\r
+ }\r
+ \r
++ notmuch_exit_if_unmatched_db_revision (notmuch);\r
++\r
+ if (notmuch_database_needs_upgrade (notmuch)) {\r
+ time_t now = time (NULL);\r
+ struct tm *gm_time = gmtime (&now);\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 4464741..52e0d9b 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -831,6 +831,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
+ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return EXIT_FAILURE;\r
+ \r
++ notmuch_exit_if_unmatched_db_revision (notmuch);\r
++\r
+ query = notmuch_query_create (notmuch, query_string);\r
+ if (query == NULL) {\r
+ fprintf (stderr, "Out of memory\n");\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index 2a534dc..3e96aa8 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -165,6 +165,8 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
+ }\r
+ \r
+ notmuch_process_shared_options (argv[0]);\r
++ notmuch_exit_if_unmatched_db_revision (notmuch);\r
++\r
+ name_for_error = input_file_name ? input_file_name : "stdin";\r
+ \r
+ if (! accumulate)\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 5d17dac..453a041 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -583,6 +583,8 @@ _notmuch_search_prepare (search_context_t *ctx, notmuch_config_t *config, int ar\r
+ return EXIT_FAILURE;\r
+ }\r
+ \r
++ notmuch_exit_if_unmatched_db_revision (ctx->notmuch);\r
++\r
+ query_str = query_string_from_args (ctx->notmuch, argc, argv);\r
+ if (query_str == NULL) {\r
+ fprintf (stderr, "Out of memory.\n");\r
+diff --git a/notmuch-setup.c b/notmuch-setup.c\r
+index 5fc6e25..ddc6491 100644\r
+--- a/notmuch-setup.c\r
++++ b/notmuch-setup.c\r
+@@ -155,6 +155,10 @@ notmuch_setup_command (notmuch_config_t *config,\r
+ if (opt_index < 0)\r
+ return EXIT_FAILURE;\r
+ \r
++ if (notmuch_requested_db_revision)\r
++ fprintf (stderr, "Warning: ignoring --db-revision=%s\n",\r
++ notmuch_requested_db_revision);\r
++\r
+ notmuch_process_shared_options (argv[0]);\r
+ \r
+ if (notmuch_config_is_new (config))\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 3917b82..de16db3 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -1220,6 +1220,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
+ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return EXIT_FAILURE;\r
+ \r
++ notmuch_exit_if_unmatched_db_revision (notmuch);\r
++\r
+ query = notmuch_query_create (notmuch, query_string);\r
+ if (query == NULL) {\r
+ fprintf (stderr, "Out of memory\n");\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index 35f971d..2c54eec 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -261,6 +261,8 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+ return EXIT_FAILURE;\r
+ \r
++ notmuch_exit_if_unmatched_db_revision (notmuch);\r
++\r
+ if (notmuch_config_get_maildir_synchronize_flags (config))\r
+ tag_flags |= TAG_FLAG_MAILDIR_SYNC;\r
+ \r
+diff --git a/notmuch.c b/notmuch.c\r
+index c7f8c8f..90e6de3 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -47,10 +47,12 @@ static int\r
+ _help_for (const char *topic);\r
+ \r
+ static notmuch_bool_t print_version = FALSE, print_help = FALSE;\r
++char *notmuch_requested_db_revision = NULL;\r
+ \r
+ const notmuch_opt_desc_t notmuch_shared_options [] = {\r
+ { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
++ { NOTMUCH_OPT_STRING, ¬much_requested_db_revision, "db-revision", 'd', 0 },\r
+ {0, 0, 0, 0, 0}\r
+ };\r
+ \r
+@@ -196,6 +198,22 @@ be supported in the future.\n", notmuch_format_version);\r
+ }\r
+ }\r
+ \r
++void\r
++notmuch_exit_if_unmatched_db_revision (notmuch_database_t *notmuch)\r
++{\r
++ const char *uuid = NULL;\r
++\r
++ if (!notmuch_requested_db_revision)\r
++ return;\r
++ IGNORE_RESULT (notmuch_database_get_revision (notmuch, &uuid));\r
++\r
++ if (strcmp (notmuch_requested_db_revision, uuid) != 0){\r
++ fprintf (stderr, "Error: requested database revision %s does not match %s\n",\r
++ notmuch_requested_db_revision, uuid);\r
++ exit (1);\r
++ }\r
++}\r
++\r
+ static void\r
+ exec_man (const char *page)\r
+ {\r
+-- \r
+2.1.4\r
+\r