From: David Bremner Date: Fri, 5 Jun 2015 17:28:36 +0000 (+0200) Subject: [PATCH 4/6] cli/count: add --output=modifications X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fe85b72bb2a6ed1904cc006c91689536c3348117;p=notmuch-archives.git [PATCH 4/6] cli/count: add --output=modifications --- diff --git a/25/830fb6af80cd29e93085799c18059741d018d2 b/25/830fb6af80cd29e93085799c18059741d018d2 new file mode 100644 index 000000000..165ae5cc6 --- /dev/null +++ b/25/830fb6af80cd29e93085799c18059741d018d2 @@ -0,0 +1,135 @@ +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 4C0DF6DE17E8 + for ; Fri, 5 Jun 2015 10:31:27 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.236 +X-Spam-Level: +X-Spam-Status: No, score=0.236 tagged_above=-999 required=5 tests=[AWL=0.226, + 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 hUTH_VJ9YrIY for ; + Fri, 5 Jun 2015 10:31:25 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id 632A56DE179F + for ; Fri, 5 Jun 2015 10:31:15 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1Z0vRx-0002oA-F6; Fri, 05 Jun 2015 17:30:33 +0000 +Received: (nullmailer pid 24254 invoked by uid 1000); Fri, 05 Jun 2015 + 17:28:42 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH 4/6] cli/count: add --output=modifications +Date: Fri, 5 Jun 2015 19:28:36 +0200 +Message-Id: <1433525318-23756-5-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1433525318-23756-1-git-send-email-david@tethera.net> +References: <1432936375-astroid-4-0i1n6yczs2-1520@strange> + <1433525318-23756-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: Fri, 05 Jun 2015 17:31:27 -0000 + +We need some way to extract the uuid/revision of the database, and +count seems like the least bad choice of current commands. +The (perhaps weak) argument for count over search is that count +already reports statistics about the entire database. +--- + notmuch-count.c | 18 +++++++++++++++++- + test/T570-revision-tracking.sh | 12 ++++++++++++ + 2 files changed, 29 insertions(+), 1 deletion(-) + +diff --git a/notmuch-count.c b/notmuch-count.c +index 57a88a8..7c61ccb 100644 +--- a/notmuch-count.c ++++ b/notmuch-count.c +@@ -25,6 +25,7 @@ enum { + OUTPUT_THREADS, + OUTPUT_MESSAGES, + OUTPUT_FILES, ++ OUTPUT_LASTMOD, + }; + + /* The following is to allow future options to be added more easily */ +@@ -71,6 +72,9 @@ print_count (notmuch_database_t *notmuch, const char *query_str, + { + notmuch_query_t *query; + size_t i; ++ unsigned long revision; ++ const char *uuid; ++ int ret = 0; + + query = notmuch_query_create (notmuch, query_str); + if (query == NULL) { +@@ -91,11 +95,22 @@ print_count (notmuch_database_t *notmuch, const char *query_str, + case OUTPUT_FILES: + printf ("%u\n", count_files (query)); + break; ++ case OUTPUT_LASTMOD: ++ if (strcmp (notmuch_query_get_query_string (query), "*") != 0) { ++ fprintf (stderr, "Error: Only '*' is currently supported " ++ " with output=modifications\n"); ++ ret = 1; ++ goto DONE; ++ } ++ ++ revision = notmuch_database_get_revision (notmuch, &uuid); ++ printf ("%s\t%lu\n", uuid, revision); + } + ++ DONE: + notmuch_query_destroy (query); + +- return 0; ++ return ret; + } + + static int +@@ -139,6 +154,7 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) + (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS }, + { "messages", OUTPUT_MESSAGES }, + { "files", OUTPUT_FILES }, ++ { "modifications", OUTPUT_LASTMOD }, + { 0, 0 } } }, + { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x', + (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, +diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh +index 74a7c49..062fd59 100755 +--- a/test/T570-revision-tracking.sh ++++ b/test/T570-revision-tracking.sh +@@ -34,4 +34,16 @@ UUID 53 + EOF + test_expect_equal_file EXPECTED CLEAN + ++grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT ++ ++test_begin_subtest "output of count matches test code" ++notmuch count --output=modifications '*' > OUTPUT ++test_expect_equal_file INITIAL_OUTPUT OUTPUT ++ ++test_begin_subtest "modification count increases" ++before=$(notmuch count --output=modifications '*' | cut -f2) ++notmuch tag +a-random-tag-8743632 '*' ++after=$(notmuch count --output=modifications '*' | cut -f2) ++result=$(($before < $after)) ++test_expect_equal 1 ${result} + test_done +-- +2.1.4 +