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