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 365976DE02D2 for ; Sun, 9 Aug 2015 02:26:29 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.141 X-Spam-Level: X-Spam-Status: No, score=0.141 tagged_above=-999 required=5 tests=[AWL=0.131, 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 LyMtrejHLb4g for ; Sun, 9 Aug 2015 02:26:27 -0700 (PDT) Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224]) by arlo.cworth.org (Postfix) with ESMTPS id 776F46DE100F for ; Sun, 9 Aug 2015 02:26:27 -0700 (PDT) Received: from remotemail by gitolite.debian.net with local (Exim 4.80) (envelope-from ) id 1ZOMrR-0005WJ-6e; Sun, 09 Aug 2015 09:25:45 +0000 Received: (nullmailer pid 7065 invoked by uid 1000); Sun, 09 Aug 2015 09:24:47 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 3/5] cli/count: add --output=modifications Date: Sun, 9 Aug 2015 11:24:43 +0200 Message-Id: <1439112285-6681-4-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1439112285-6681-1-git-send-email-david@tethera.net> References: <1439112285-6681-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, 09 Aug 2015 09:26:29 -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 e0a5703..008c5d0 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