From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 5/6] cli: add global option "--db-revision"
Date: Fri, 5 Jun 2015 19:28:37 +0200 [thread overview]
Message-ID: <1433525318-23756-6-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1433525318-23756-1-git-send-email-david@tethera.net>
The function notmuch_exit_if_unmatched_db_revision is split from
notmuch_process_shared_options because it needs an open notmuch
database.
---
doc/man1/notmuch.rst | 10 ++++++++--
notmuch-client.h | 4 ++++
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 ++++++++++++++++++
test/T570-revision-tracking.sh | 26 ++++++++++++++++++++++++++
test/random-corpus.c | 2 ++
17 files changed, 88 insertions(+), 3 deletions(-)
diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
index ae0461a..b3f75a4 100644
--- a/doc/man1/notmuch.rst
+++ b/doc/man1/notmuch.rst
@@ -49,9 +49,15 @@ Supported global options for ``notmuch`` include
Specify the configuration file to use. This overrides any
configuration file specified by ${NOTMUCH\_CONFIG}.
+ ``--db-revision=UUID``
+ Enforce that the database revision is UUID. This is useful to
+ detect rollover in modification counts on messages. You can
+ find this UUID in the first column of output from
+ ``notmuch count --output=modifications``
+
All global options except ``--config`` can also be specified after the
-command. For example, ``notmuch subcommand --version`` is equivalent to
-``notmuch --version subcommand``.
+command. For example, ``notmuch subcommand --db-revision`` is
+equivalent to ``notmuch --db-revision subcommand``.
COMMANDS
========
diff --git a/notmuch-client.h b/notmuch-client.h
index 78680aa..d3fab21 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -466,7 +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_exit_if_unmatched_db_revision (notmuch_database_t *notmuch);
+
void notmuch_process_shared_options (const char* subcommand_name);
int notmuch_minimal_options (const char* subcommand_name,
int argc, char **argv);
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 9348278..f1826e4 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -878,6 +878,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);
+
/* skip at least subcommand argument */
argc-= opt_index;
argv+= opt_index;
diff --git a/notmuch-count.c b/notmuch-count.c
index 7c61ccb..dda85b5 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -191,6 +191,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 c277d62..42d346f 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 8ff1ade..2064a86 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 b89a17e..919837c 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 7dd5822..dffda81 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -148,6 +148,10 @@ notmuch_setup_command (notmuch_config_t *config,
if (notmuch_minimal_options ("setup", argc, argv) < 0)
return EXIT_FAILURE;
+ if (notmuch_requested_db_revision)
+ fprintf (stderr, "Warning: ignoring --db-revision=%s\n",
+ notmuch_requested_db_revision);
+
if (notmuch_config_is_new (config))
welcome_message_pre_setup ();
diff --git a/notmuch-show.c b/notmuch-show.c
index b80933a..2535c8c 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1213,6 +1213,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 38d99aa..22446fe 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 c528dce..fab737c 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}
};
@@ -218,6 +220,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)
{
diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh
index 062fd59..bb09bf6 100755
--- a/test/T570-revision-tracking.sh
+++ b/test/T570-revision-tracking.sh
@@ -46,4 +46,30 @@ notmuch tag +a-random-tag-8743632 '*'
after=$(notmuch count --output=modifications '*' | cut -f2)
result=$(($before < $after))
test_expect_equal 1 ${result}
+
+notmuch count --output=modifications '*' | cut -f1 > UUID
+
+test_expect_success 'search succeeds with correct db revision' \
+ "notmuch search --db-revision=$(cat UUID) '*'"
+
+test_expect_success 'db-revision works as global option ' \
+ "notmuch --db-revision=$(cat UUID) search '*'"
+
+test_expect_code 1 'db-revision works as global option II' \
+ "notmuch --db-revision=this-is-no-uuid search '*'"
+
+test_expect_code 1 'search fails with incorrect db revision' \
+ "notmuch search --db-revision=this-is-no-uuid '*'"
+
+test_expect_success 'show succeeds with correct db revision' \
+ "notmuch show --db-revision=$(cat UUID) '*'"
+
+test_expect_code 1 'show fails with incorrect db revision' \
+ "notmuch show --db-revision=this-is-no-uuid '*'"
+
+test_expect_success 'tag succeeds with correct db revision' \
+ "notmuch tag --db-revision=$(cat UUID) +test '*'"
+
+test_expect_code 1 'tag fails with incorrect db revision' \
+ "notmuch show --db-revision=this-is-no-uuid '*' +test2"
test_done
diff --git a/test/random-corpus.c b/test/random-corpus.c
index b377eb4..542b453 100644
--- a/test/random-corpus.c
+++ b/test/random-corpus.c
@@ -119,6 +119,8 @@ const notmuch_opt_desc_t notmuch_shared_options[] = {
{ 0, 0, 0, 0, 0 }
};
+char *notmuch_requested_db_revision = NULL;
+
void
notmuch_process_shared_options (unused (const char *dummy))
{
--
2.1.4
next prev parent reply other threads:[~2015-06-05 17:30 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-05 22:59 Revision tracking, round 2 David Bremner
2015-04-05 22:59 ` [WIP2 01/12] lib: Only sync modified message documents David Bremner
2015-04-05 22:59 ` [WIP2 02/12] lib: Add per-message last modification tracking David Bremner
2015-04-05 22:59 ` [WIP2 03/12] lib: API to retrieve database revision and UUID David Bremner
2015-04-05 22:59 ` [WIP2 04/12] cli: add type introspection to sprinter type David Bremner
2015-04-05 22:59 ` [WIP2 05/12] cli: add two sprinter utility functions David Bremner
2015-04-05 22:59 ` [WIP2 06/12] cli/show: add extra element to structured output for metadata David Bremner
2015-04-05 22:59 ` [WIP2 07/12] lib: Add "lastmod:" queries for filtering by last modification David Bremner
2015-04-05 22:59 ` [WIP2 08/12] cli/show: add lastmod to structured output David Bremner
2015-04-05 22:59 ` [WIP2 09/12] cli/search: add metadata element " David Bremner
2015-04-05 22:59 ` [WIP2 10/12] emacs: convert notmuch-search to format-version 3 David Bremner
2015-04-05 22:59 ` [WIP2 11/12] emacs: convert notmuch-tree " David Bremner
2015-04-05 22:59 ` [WIP2 12/12] cli: add global option "--db-revision" David Bremner
2015-05-29 21:56 ` Revision tracking, round 2 Gaute Hope
2015-06-05 17:28 ` revision tracking patches, round 1 David Bremner
2015-06-05 17:28 ` [PATCH 1/6] lib: Only sync modified message documents David Bremner
2015-08-04 7:07 ` David Bremner
2015-06-05 17:28 ` [PATCH 2/6] lib: Add per-message last modification tracking David Bremner
2015-08-07 7:36 ` Daniel Schoepe
2015-08-07 20:38 ` David Bremner
2015-08-08 13:05 ` Austin Clements
2015-08-08 5:33 ` [PATCH] fixup! " David Bremner
2015-06-05 17:28 ` [PATCH 3/6] lib: API to retrieve database revision and UUID David Bremner
2015-08-06 10:26 ` Tomi Ollila
2015-06-05 17:28 ` [PATCH 4/6] cli/count: add --output=modifications David Bremner
2015-06-05 17:28 ` David Bremner [this message]
2015-08-07 8:05 ` [PATCH 5/6] cli: add global option "--db-revision" Daniel Schoepe
2015-08-07 20:47 ` David Bremner
2015-06-05 17:28 ` [PATCH 6/6] lib: Add "lastmod:" queries for filtering by last modification David Bremner
2015-08-07 8:16 ` Daniel Schoepe
2015-08-07 20:22 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1433525318-23756-6-git-send-email-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).