--- /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 EC0346DE190D\r
+ for <notmuch@notmuchmail.org>; Fri, 14 Aug 2015 09:49:13 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.134\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.134 tagged_above=-999 required=5 tests=[AWL=0.124, \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 W8T8aSnuZWAM for <notmuch@notmuchmail.org>;\r
+ Fri, 14 Aug 2015 09:49:12 -0700 (PDT)\r
+Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 0F0FA6DE18FD\r
+ for <notmuch@notmuchmail.org>; Fri, 14 Aug 2015 09:49:12 -0700 (PDT)\r
+Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1ZQI9d-0003dv-NJ; Fri, 14 Aug 2015 16:48:29 +0000\r
+Received: (nullmailer pid 15756 invoked by uid 1000); Fri, 14 Aug 2015\r
+ 16:48:02 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/5] cli/count: add --lastmod\r
+Date: Fri, 14 Aug 2015 18:47:56 +0200\r
+Message-Id: <1439570878-15165-4-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.5.0\r
+In-Reply-To: <1439570878-15165-1-git-send-email-david@tethera.net>\r
+References: <1439570878-15165-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: Fri, 14 Aug 2015 16:49:14 -0000\r
+\r
+In the short term we need a way to get lastmod information e.g. for\r
+the test suite. In the long term we probably want to add lastmod\r
+information to at least the structured output for several other\r
+clients (e.g. show, search).\r
+---\r
+ doc/man1/notmuch-count.rst | 5 +++++\r
+ notmuch-count.c | 32 +++++++++++++++++++++++---------\r
+ test/T570-revision-tracking.sh | 12 ++++++++++++\r
+ 3 files changed, 40 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/doc/man1/notmuch-count.rst b/doc/man1/notmuch-count.rst\r
+index ca78c18..99de13a 100644\r
+--- a/doc/man1/notmuch-count.rst\r
++++ b/doc/man1/notmuch-count.rst\r
+@@ -47,6 +47,11 @@ Supported options for **count** include\r
+ (or threads) in the database will be output. This option is not\r
+ compatible with specifying search terms on the command line.\r
+ \r
++ ``--lastmod``\r
++ Append lastmod (counter for number of database updates) and UUID\r
++ to the output. lastmod values are only comparable between databases\r
++ with the same UUID.\r
++\r
+ ``--input=``\ <filename>\r
+ Read input from given file, instead of from stdin. Implies\r
+ ``--batch``.\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index 57a88a8..182710a 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -25,6 +25,7 @@ enum {\r
+ OUTPUT_THREADS,\r
+ OUTPUT_MESSAGES,\r
+ OUTPUT_FILES,\r
++ OUTPUT_LASTMOD,\r
+ };\r
+ \r
+ /* The following is to allow future options to be added more easily */\r
+@@ -67,10 +68,13 @@ count_files (notmuch_query_t *query)\r
+ \r
+ static int\r
+ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+- const char **exclude_tags, size_t exclude_tags_length, int output)\r
++ const char **exclude_tags, size_t exclude_tags_length, int output, int print_lastmod)\r
+ {\r
+ notmuch_query_t *query;\r
+ size_t i;\r
++ unsigned long revision;\r
++ const char *uuid;\r
++ int ret = 0;\r
+ \r
+ query = notmuch_query_create (notmuch, query_str);\r
+ if (query == NULL) {\r
+@@ -83,24 +87,31 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+ \r
+ switch (output) {\r
+ case OUTPUT_MESSAGES:\r
+- printf ("%u\n", notmuch_query_count_messages (query));\r
++ printf ("%u", notmuch_query_count_messages (query));\r
+ break;\r
+ case OUTPUT_THREADS:\r
+- printf ("%u\n", notmuch_query_count_threads (query));\r
++ printf ("%u", notmuch_query_count_threads (query));\r
+ break;\r
+ case OUTPUT_FILES:\r
+- printf ("%u\n", count_files (query));\r
++ printf ("%u", count_files (query));\r
+ break;\r
+ }\r
+ \r
++ if (print_lastmod) {\r
++ revision = notmuch_database_get_revision (notmuch, &uuid);\r
++ printf ("\t%s\t%lu\n", uuid, revision);\r
++ } else {\r
++ fputs ("\n", stdout);\r
++ }\r
++\r
+ notmuch_query_destroy (query);\r
+ \r
+- return 0;\r
++ return ret;\r
+ }\r
+ \r
+ static int\r
+ count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,\r
+- size_t exclude_tags_length, int output)\r
++ size_t exclude_tags_length, int output, int print_lastmod)\r
+ {\r
+ char *line = NULL;\r
+ ssize_t line_len;\r
+@@ -110,7 +121,7 @@ count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,\r
+ while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {\r
+ chomp_newline (line);\r
+ ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,\r
+- output);\r
++ output, print_lastmod);\r
+ }\r
+ \r
+ if (line)\r
+@@ -130,6 +141,7 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ const char **search_exclude_tags = NULL;\r
+ size_t search_exclude_tags_length = 0;\r
+ notmuch_bool_t batch = FALSE;\r
++ notmuch_bool_t print_lastmod = FALSE;\r
+ FILE *input = stdin;\r
+ char *input_file_name = NULL;\r
+ int ret;\r
+@@ -139,11 +151,13 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },\r
+ { "messages", OUTPUT_MESSAGES },\r
+ { "files", OUTPUT_FILES },\r
++ { "modifications", OUTPUT_LASTMOD },\r
+ { 0, 0 } } },\r
+ { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',\r
+ (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },\r
+ { "false", EXCLUDE_FALSE },\r
+ { 0, 0 } } },\r
++ { NOTMUCH_OPT_BOOLEAN, &print_lastmod, "lastmod", 'l', 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
+ { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
+ { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },\r
+@@ -188,10 +202,10 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ \r
+ if (batch)\r
+ ret = count_file (notmuch, input, search_exclude_tags,\r
+- search_exclude_tags_length, output);\r
++ search_exclude_tags_length, output, print_lastmod);\r
+ else\r
+ ret = print_count (notmuch, query_str, search_exclude_tags,\r
+- search_exclude_tags_length, output);\r
++ search_exclude_tags_length, output, print_lastmod);\r
+ \r
+ notmuch_database_destroy (notmuch);\r
+ \r
+diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh\r
+index e0a5703..4fff689 100755\r
+--- a/test/T570-revision-tracking.sh\r
++++ b/test/T570-revision-tracking.sh\r
+@@ -34,4 +34,16 @@ UUID 53\r
+ EOF\r
+ test_expect_equal_file EXPECTED CLEAN\r
+ \r
++grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT\r
++\r
++test_begin_subtest "output of count matches test code"\r
++notmuch count --lastmod '*' | cut -f2-3 > OUTPUT\r
++test_expect_equal_file INITIAL_OUTPUT OUTPUT\r
++\r
++test_begin_subtest "modification count increases"\r
++before=$(notmuch count --lastmod '*' | cut -f3)\r
++notmuch tag +a-random-tag-8743632 '*'\r
++after=$(notmuch count --lastmod '*' | cut -f3)\r
++result=$(($before < $after))\r
++test_expect_equal 1 ${result}\r
+ test_done\r
+-- \r
+2.5.0\r
+\r