[PATCH 4/5] cli: add global option "--uuid"

2015-08-14 Thread David Bremner
The function notmuch_exit_if_unmatched_db_uuid is split from
notmuch_process_shared_options because it needs an open notmuch
database.

There are two exceptional cases in uuid handling.

1) notmuch config and notmuch setup don't currently open the database,
   so it doesn't make sense to check the UUID.

2) notmuch compact opens the database inside the library, so we either
   need to open the database just to check uuid, or change the API.
---
 doc/man1/notmuch.rst   | 11 +--
 notmuch-client.h   |  4 
 notmuch-compact.c  |  5 +
 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 | 27 +++
 test/random-corpus.c   |  2 ++
 17 files changed, 91 insertions(+), 3 deletions(-)

diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
index 0401c91..3acfbdb 100644
--- a/doc/man1/notmuch.rst
+++ b/doc/man1/notmuch.rst
@@ -51,9 +51,16 @@ Supported global options for ``notmuch`` include
Specify the configuration file to use. This overrides any
configuration file specified by ${NOTMUCH\_CONFIG}.

+``--uuid=HEX``
+   Enforce that the database UUID (a unique identifier which
+   persists until e.g. the database is compacted)
+   is HEX; exit with an error if it is not. This is useful to
+   detect rollover in modification counts on messages. You can
+   find this UUID using e.g. ``notmuch count --lastmod``
+
 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 --uuid=HEX`` is
+equivalent to ``notmuch --uuid=HEX subcommand``.

 COMMANDS
 
diff --git a/notmuch-client.h b/notmuch-client.h
index 78680aa..4a4f86c 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_uuid;
 extern const notmuch_opt_desc_t  notmuch_shared_options [];
+void notmuch_exit_if_unmatched_db_uuid (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..9373721 100644
--- a/notmuch-compact.c
+++ b/notmuch-compact.c
@@ -46,6 +46,11 @@ notmuch_compact_command (notmuch_config_t *config, int argc, 
char *argv[])
 if (opt_index < 0)
return EXIT_FAILURE;

+if (notmuch_requested_db_uuid) {
+   fprintf (stderr, "Error: --uuid not implemented for compact\n");
+   return EXIT_FAILURE;
+}
+
 notmuch_process_shared_options (argv[0]);

 if (! quiet)
diff --git a/notmuch-config.c b/notmuch-config.c
index 9348278..d252bb2 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_uuid)
+   fprintf (stderr, "Warning: ignoring --uuid=%s\n",
+notmuch_requested_db_uuid);
+
 /* skip at least subcommand argument */
 argc-= opt_index;
 argv+= opt_index;
diff --git a/notmuch-count.c b/notmuch-count.c
index 182710a..f26e726 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -189,6 +189,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, 
char *argv[])
   NOTMUCH_DATABASE_MODE_READ_ONLY, ))
return EXIT_FAILURE;

+notmuch_exit_if_unmatched_db_uuid (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..24fc2f2 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, ))
return EXIT_FAILURE;

+notmuch_exit_if_unmatched_db_uuid (notmuch);
+
 char *output_file_name = NULL;
 int opt_index;

diff --git a/notmuch-insert.c b/notmuch-insert.c
index c277d62..5205c17 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -536,6 +536,8 @@ notmuch_insert_command 

[PATCH 4/5] cli: add global option --uuid

2015-08-14 Thread David Bremner
The function notmuch_exit_if_unmatched_db_uuid is split from
notmuch_process_shared_options because it needs an open notmuch
database.

There are two exceptional cases in uuid handling.

1) notmuch config and notmuch setup don't currently open the database,
   so it doesn't make sense to check the UUID.

2) notmuch compact opens the database inside the library, so we either
   need to open the database just to check uuid, or change the API.
---
 doc/man1/notmuch.rst   | 11 +--
 notmuch-client.h   |  4 
 notmuch-compact.c  |  5 +
 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 | 27 +++
 test/random-corpus.c   |  2 ++
 17 files changed, 91 insertions(+), 3 deletions(-)

diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
index 0401c91..3acfbdb 100644
--- a/doc/man1/notmuch.rst
+++ b/doc/man1/notmuch.rst
@@ -51,9 +51,16 @@ Supported global options for ``notmuch`` include
Specify the configuration file to use. This overrides any
configuration file specified by ${NOTMUCH\_CONFIG}.
 
+``--uuid=HEX``
+   Enforce that the database UUID (a unique identifier which
+   persists until e.g. the database is compacted)
+   is HEX; exit with an error if it is not. This is useful to
+   detect rollover in modification counts on messages. You can
+   find this UUID using e.g. ``notmuch count --lastmod``
+
 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 --uuid=HEX`` is
+equivalent to ``notmuch --uuid=HEX subcommand``.
 
 COMMANDS
 
diff --git a/notmuch-client.h b/notmuch-client.h
index 78680aa..4a4f86c 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_uuid;
 extern const notmuch_opt_desc_t  notmuch_shared_options [];
+void notmuch_exit_if_unmatched_db_uuid (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..9373721 100644
--- a/notmuch-compact.c
+++ b/notmuch-compact.c
@@ -46,6 +46,11 @@ notmuch_compact_command (notmuch_config_t *config, int argc, 
char *argv[])
 if (opt_index  0)
return EXIT_FAILURE;
 
+if (notmuch_requested_db_uuid) {
+   fprintf (stderr, Error: --uuid not implemented for compact\n);
+   return EXIT_FAILURE;
+}
+
 notmuch_process_shared_options (argv[0]);
 
 if (! quiet)
diff --git a/notmuch-config.c b/notmuch-config.c
index 9348278..d252bb2 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_uuid)
+   fprintf (stderr, Warning: ignoring --uuid=%s\n,
+notmuch_requested_db_uuid);
+
 /* skip at least subcommand argument */
 argc-= opt_index;
 argv+= opt_index;
diff --git a/notmuch-count.c b/notmuch-count.c
index 182710a..f26e726 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -189,6 +189,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, 
char *argv[])
   NOTMUCH_DATABASE_MODE_READ_ONLY, notmuch))
return EXIT_FAILURE;
 
+notmuch_exit_if_unmatched_db_uuid (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..24fc2f2 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, notmuch))
return EXIT_FAILURE;
 
+notmuch_exit_if_unmatched_db_uuid (notmuch);
+
 char *output_file_name = NULL;
 int opt_index;
 
diff --git a/notmuch-insert.c b/notmuch-insert.c
index c277d62..5205c17 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -536,6 +536,8 @@ notmuch_insert_command 

[PATCH 4/5] cli: add global option "--uuid"

2015-08-10 Thread Tomi Ollila
On Sun, Aug 09 2015, David Bremner  wrote:

> The function notmuch_exit_if_unmatched_db_uuid is split from
> notmuch_process_shared_options because it needs an open notmuch
> database.
> ---
>  doc/man1/notmuch.rst   | 12 ++--
>  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 | 27 +++
>  test/random-corpus.c   |  2 ++
>  17 files changed, 91 insertions(+), 3 deletions(-)
>
> diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
> index 0401c91..0b89544 100644
> --- a/doc/man1/notmuch.rst
> +++ b/doc/man1/notmuch.rst
> @@ -51,9 +51,17 @@ Supported global options for ``notmuch`` include
>   Specify the configuration file to use. This overrides any
>   configuration file specified by ${NOTMUCH\_CONFIG}.
>  
> +``--uuid=HEX``
> +   Enforce that the database UUID (a unique identifier which
> +   persists until e.g. the database is compacted)
> +   is HEX; exit with an error if it is not. 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 --uuid=HEX`` is
> +equivalent to ``notmuch --uuid=HEX subcommand``.
>  
>  COMMANDS
>  
> diff --git a/notmuch-client.h b/notmuch-client.h
> index 78680aa..4a4f86c 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_uuid;
>  extern const notmuch_opt_desc_t  notmuch_shared_options [];
> +void notmuch_exit_if_unmatched_db_uuid (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..61fccd8 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_uuid)
> + fprintf (stderr, "Warning: ignoring --uuid=%s\n",
> +  notmuch_requested_db_uuid);
> +

I see in these commands this warning is issued, we don't open the database
(at this time, IIRC compact opens it later)...

... In this case I'm wondering whether giving --uuid should be considered
as error (and stopping) instead of printing warning and continuing.  In
some other cases we do warn and continue but here ... we're modifying
the database or configurations...
... later we could add database uuid check always if --uuid is given
and allow continuing if it matches in these cases...

One more (now the trivial thing) to go, do not stop here ;)

>  notmuch_process_shared_options (argv[0]);
>  
>  if (! quiet)
> diff --git a/notmuch-config.c b/notmuch-config.c
> index 9348278..d252bb2 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_uuid)
> + fprintf (stderr, "Warning: ignoring --uuid=%s\n",
> +  notmuch_requested_db_uuid);
> +
>  /* skip at least subcommand argument */
>  argc-= opt_index;
>  argv+= opt_index;
> diff --git a/notmuch-count.c b/notmuch-count.c
> index 7c61ccb..091e376 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, ))
>   return EXIT_FAILURE;
>  
> +notmuch_exit_if_unmatched_db_uuid (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..24fc2f2 

[PATCH 4/5] cli: add global option "--uuid"

2015-08-10 Thread Daniel Schoepe
On Mon, 10 Aug 2015 13:32 +0200, David Bremner wrote:
> So compacting is in fact a bit of a strange case, it preserves the
> lastmod counters (because those are just terms on documents), but not
> the uuid. This means from notmuch point of view have no programmatic way
> to know that we can trust the lastmod data, i.e. no way to distinguish a
> previous notmuch-compact from "notmuch dump && rm the database &&
> notmuch new && notmuch restore".  On the other hand, I _think_ we could
> promise the user that lastmod data is preserved by compacting; they
> would just have to tell whatever external tool to ignore uuid errors and
> perhaps set the new uuid.

Yeah, I think it's reasonable to assume that if the user will delete and
recreate the database, they will also perform the necessary
reinitialization of whatever tool makes use of lastmod / UUID. I guess
this also means that tools often only care about lastmod values and not
the UUID, to allow for compacting without thinking the database is
completely different now.

Another option is to include lastmod values in the output of
notmuch-dump. Doing that in a clean way might be hard though and I think
this shouldn't be part of this series (which looks fine to me now).

Best regards,
Daniel


[PATCH 4/5] cli: add global option "--uuid"

2015-08-10 Thread David Bremner
Daniel Schoepe  writes:

> Based on quick experiments, it seems that the revisions don't change
> when compacting the database; is this something that the patches
> guarantee or a coincidence?

Now that you mention it, I can see that despite essentially quoting the
xapian docs, compacting might not be the best example.

According to the xapian docs:

   The UUID will persist for the lifetime of the database.

Replicas (eg, made with the replication protocol, or by copying all
the database files) will have the same UUID. However, copies (made
with copydatabase, or xapian-compact) will have different UUIDs.

So compacting is in fact a bit of a strange case, it preserves the
lastmod counters (because those are just terms on documents), but not
the uuid. This means from notmuch point of view have no programmatic way
to know that we can trust the lastmod data, i.e. no way to distinguish a
previous notmuch-compact from "notmuch dump && rm the database &&
notmuch new && notmuch restore".  On the other hand, I _think_ we could
promise the user that lastmod data is preserved by compacting; they
would just have to tell whatever external tool to ignore uuid errors and
perhaps set the new uuid.

d


[PATCH 4/5] cli: add global option "--uuid"

2015-08-10 Thread Daniel Schoepe
On Sun, 09 Aug 2015 11:24+0200, David Bremner wrote:
> +``--uuid=HEX``
> +   Enforce that the database UUID (a unique identifier which
> +   persists until e.g. the database is compacted)
> +   is HEX; exit with an error if it is not. 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``

I think it's not entirely clear what the connection between the UUID and
the revisions on messages is. For example, compacting a database
shouldn't make a difference "extensionally", so the naive assumption
might be that the UUID, or, maybe more importantly, the revision counts
don't change.

For example, if lastmod queries are used to incrementally back up or
synchronize tags, then it doesn't matter if the database got compacted,
all one cares about are the changes to messages' tags since an earlier
point.

Based on quick experiments, it seems that the revisions don't change
when compacting the database; is this something that the patches
guarantee or a coincidence?

Best regards,
Daniel


Re: [PATCH 4/5] cli: add global option --uuid

2015-08-10 Thread Tomi Ollila
On Sun, Aug 09 2015, David Bremner da...@tethera.net wrote:

 The function notmuch_exit_if_unmatched_db_uuid is split from
 notmuch_process_shared_options because it needs an open notmuch
 database.
 ---
  doc/man1/notmuch.rst   | 12 ++--
  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 | 27 +++
  test/random-corpus.c   |  2 ++
  17 files changed, 91 insertions(+), 3 deletions(-)

 diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
 index 0401c91..0b89544 100644
 --- a/doc/man1/notmuch.rst
 +++ b/doc/man1/notmuch.rst
 @@ -51,9 +51,17 @@ Supported global options for ``notmuch`` include
   Specify the configuration file to use. This overrides any
   configuration file specified by ${NOTMUCH\_CONFIG}.
  
 +``--uuid=HEX``
 +   Enforce that the database UUID (a unique identifier which
 +   persists until e.g. the database is compacted)
 +   is HEX; exit with an error if it is not. 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 --uuid=HEX`` is
 +equivalent to ``notmuch --uuid=HEX subcommand``.
  
  COMMANDS
  
 diff --git a/notmuch-client.h b/notmuch-client.h
 index 78680aa..4a4f86c 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_uuid;
  extern const notmuch_opt_desc_t  notmuch_shared_options [];
 +void notmuch_exit_if_unmatched_db_uuid (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..61fccd8 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_uuid)
 + fprintf (stderr, Warning: ignoring --uuid=%s\n,
 +  notmuch_requested_db_uuid);
 +

I see in these commands this warning is issued, we don't open the database
(at this time, IIRC compact opens it later)...

... In this case I'm wondering whether giving --uuid should be considered
as error (and stopping) instead of printing warning and continuing.  In
some other cases we do warn and continue but here ... we're modifying
the database or configurations...
... later we could add database uuid check always if --uuid is given
and allow continuing if it matches in these cases...

One more (now the trivial thing) to go, do not stop here ;)

  notmuch_process_shared_options (argv[0]);
  
  if (! quiet)
 diff --git a/notmuch-config.c b/notmuch-config.c
 index 9348278..d252bb2 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_uuid)
 + fprintf (stderr, Warning: ignoring --uuid=%s\n,
 +  notmuch_requested_db_uuid);
 +
  /* skip at least subcommand argument */
  argc-= opt_index;
  argv+= opt_index;
 diff --git a/notmuch-count.c b/notmuch-count.c
 index 7c61ccb..091e376 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, notmuch))
   return EXIT_FAILURE;
  
 +notmuch_exit_if_unmatched_db_uuid (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..24fc2f2 100644
 --- a/notmuch-dump.c
 +++ b/notmuch-dump.c
 @@ -215,6 +215,8 @@ notmuch_dump_command 

Re: [PATCH 4/5] cli: add global option --uuid

2015-08-10 Thread Daniel Schoepe
On Mon, 10 Aug 2015 13:32 +0200, David Bremner wrote:
 So compacting is in fact a bit of a strange case, it preserves the
 lastmod counters (because those are just terms on documents), but not
 the uuid. This means from notmuch point of view have no programmatic way
 to know that we can trust the lastmod data, i.e. no way to distinguish a
 previous notmuch-compact from notmuch dump  rm the database 
 notmuch new  notmuch restore.  On the other hand, I _think_ we could
 promise the user that lastmod data is preserved by compacting; they
 would just have to tell whatever external tool to ignore uuid errors and
 perhaps set the new uuid.

Yeah, I think it's reasonable to assume that if the user will delete and
recreate the database, they will also perform the necessary
reinitialization of whatever tool makes use of lastmod / UUID. I guess
this also means that tools often only care about lastmod values and not
the UUID, to allow for compacting without thinking the database is
completely different now.

Another option is to include lastmod values in the output of
notmuch-dump. Doing that in a clean way might be hard though and I think
this shouldn't be part of this series (which looks fine to me now).

Best regards,
Daniel
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 4/5] cli: add global option --uuid

2015-08-10 Thread Daniel Schoepe
On Sun, 09 Aug 2015 11:24+0200, David Bremner wrote:
 +``--uuid=HEX``
 +   Enforce that the database UUID (a unique identifier which
 +   persists until e.g. the database is compacted)
 +   is HEX; exit with an error if it is not. 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``

I think it's not entirely clear what the connection between the UUID and
the revisions on messages is. For example, compacting a database
shouldn't make a difference extensionally, so the naive assumption
might be that the UUID, or, maybe more importantly, the revision counts
don't change.

For example, if lastmod queries are used to incrementally back up or
synchronize tags, then it doesn't matter if the database got compacted,
all one cares about are the changes to messages' tags since an earlier
point.

Based on quick experiments, it seems that the revisions don't change
when compacting the database; is this something that the patches
guarantee or a coincidence?

Best regards,
Daniel
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 4/5] cli: add global option "--uuid"

2015-08-09 Thread David Bremner
The function notmuch_exit_if_unmatched_db_uuid is split from
notmuch_process_shared_options because it needs an open notmuch
database.
---
 doc/man1/notmuch.rst   | 12 ++--
 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 | 27 +++
 test/random-corpus.c   |  2 ++
 17 files changed, 91 insertions(+), 3 deletions(-)

diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
index 0401c91..0b89544 100644
--- a/doc/man1/notmuch.rst
+++ b/doc/man1/notmuch.rst
@@ -51,9 +51,17 @@ Supported global options for ``notmuch`` include
Specify the configuration file to use. This overrides any
configuration file specified by ${NOTMUCH\_CONFIG}.

+``--uuid=HEX``
+   Enforce that the database UUID (a unique identifier which
+   persists until e.g. the database is compacted)
+   is HEX; exit with an error if it is not. 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 --uuid=HEX`` is
+equivalent to ``notmuch --uuid=HEX subcommand``.

 COMMANDS
 
diff --git a/notmuch-client.h b/notmuch-client.h
index 78680aa..4a4f86c 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_uuid;
 extern const notmuch_opt_desc_t  notmuch_shared_options [];
+void notmuch_exit_if_unmatched_db_uuid (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..61fccd8 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_uuid)
+   fprintf (stderr, "Warning: ignoring --uuid=%s\n",
+notmuch_requested_db_uuid);
+
 notmuch_process_shared_options (argv[0]);

 if (! quiet)
diff --git a/notmuch-config.c b/notmuch-config.c
index 9348278..d252bb2 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_uuid)
+   fprintf (stderr, "Warning: ignoring --uuid=%s\n",
+notmuch_requested_db_uuid);
+
 /* skip at least subcommand argument */
 argc-= opt_index;
 argv+= opt_index;
diff --git a/notmuch-count.c b/notmuch-count.c
index 7c61ccb..091e376 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, ))
return EXIT_FAILURE;

+notmuch_exit_if_unmatched_db_uuid (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..24fc2f2 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, ))
return EXIT_FAILURE;

+notmuch_exit_if_unmatched_db_uuid (notmuch);
+
 char *output_file_name = NULL;
 int opt_index;

diff --git a/notmuch-insert.c b/notmuch-insert.c
index c277d62..5205c17 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, ))
return EXIT_FAILURE;

+notmuch_exit_if_unmatched_db_uuid (notmuch);
+
 /* Write the message to the Maildir new directory. */
 newpath = 

[PATCH 4/5] cli: add global option --uuid

2015-08-09 Thread David Bremner
The function notmuch_exit_if_unmatched_db_uuid is split from
notmuch_process_shared_options because it needs an open notmuch
database.
---
 doc/man1/notmuch.rst   | 12 ++--
 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 | 27 +++
 test/random-corpus.c   |  2 ++
 17 files changed, 91 insertions(+), 3 deletions(-)

diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
index 0401c91..0b89544 100644
--- a/doc/man1/notmuch.rst
+++ b/doc/man1/notmuch.rst
@@ -51,9 +51,17 @@ Supported global options for ``notmuch`` include
Specify the configuration file to use. This overrides any
configuration file specified by ${NOTMUCH\_CONFIG}.
 
+``--uuid=HEX``
+   Enforce that the database UUID (a unique identifier which
+   persists until e.g. the database is compacted)
+   is HEX; exit with an error if it is not. 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 --uuid=HEX`` is
+equivalent to ``notmuch --uuid=HEX subcommand``.
 
 COMMANDS
 
diff --git a/notmuch-client.h b/notmuch-client.h
index 78680aa..4a4f86c 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_uuid;
 extern const notmuch_opt_desc_t  notmuch_shared_options [];
+void notmuch_exit_if_unmatched_db_uuid (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..61fccd8 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_uuid)
+   fprintf (stderr, Warning: ignoring --uuid=%s\n,
+notmuch_requested_db_uuid);
+
 notmuch_process_shared_options (argv[0]);
 
 if (! quiet)
diff --git a/notmuch-config.c b/notmuch-config.c
index 9348278..d252bb2 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_uuid)
+   fprintf (stderr, Warning: ignoring --uuid=%s\n,
+notmuch_requested_db_uuid);
+
 /* skip at least subcommand argument */
 argc-= opt_index;
 argv+= opt_index;
diff --git a/notmuch-count.c b/notmuch-count.c
index 7c61ccb..091e376 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, notmuch))
return EXIT_FAILURE;
 
+notmuch_exit_if_unmatched_db_uuid (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..24fc2f2 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, notmuch))
return EXIT_FAILURE;
 
+notmuch_exit_if_unmatched_db_uuid (notmuch);
+
 char *output_file_name = NULL;
 int opt_index;
 
diff --git a/notmuch-insert.c b/notmuch-insert.c
index c277d62..5205c17 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, notmuch))
return EXIT_FAILURE;
 
+notmuch_exit_if_unmatched_db_uuid (notmuch);
+
 /* Write the message to the Maildir new directory. */