[PATCH v7 4/6] cli: add support for --output parameter in notmuch count
authorJani Nikula <jani@nikula.org>
Tue, 15 Nov 2011 20:08:51 +0000 (22:08 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:12 +0000 (09:40 -0800)
bc/3dd5387c63302e6795ae4ccebcf75e334c0e62 [new file with mode: 0644]

diff --git a/bc/3dd5387c63302e6795ae4ccebcf75e334c0e62 b/bc/3dd5387c63302e6795ae4ccebcf75e334c0e62
new file mode 100644 (file)
index 0000000..80fc857
--- /dev/null
@@ -0,0 +1,206 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id BD22B429E26\r
+       for <notmuch@notmuchmail.org>; Tue, 15 Nov 2011 12:09:18 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id jEDSprlgH1Mn for <notmuch@notmuchmail.org>;\r
+       Tue, 15 Nov 2011 12:09:14 -0800 (PST)\r
+Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 8E5A6431FB6\r
+       for <notmuch@notmuchmail.org>; Tue, 15 Nov 2011 12:09:14 -0800 (PST)\r
+Received: by mail-bw0-f53.google.com with SMTP id q10so8918567bka.26\r
+       for <notmuch@notmuchmail.org>; Tue, 15 Nov 2011 12:09:14 -0800 (PST)\r
+Received: by 10.204.157.135 with SMTP id b7mr11084345bkx.122.1321387754118;\r
+       Tue, 15 Nov 2011 12:09:14 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id a21sm18244988fao.18.2011.11.15.12.09.11\r
+       (version=SSLv3 cipher=OTHER); Tue, 15 Nov 2011 12:09:13 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v7 4/6] cli: add support for --output parameter in notmuch\r
+       count\r
+Date: Tue, 15 Nov 2011 22:08:51 +0200\r
+Message-Id:\r
+ <6efffc4f5a87a2adb0d9762a138e07d5e595e3d0.1321386762.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1321386762.git.jani@nikula.org>\r
+References: <cover.1321386762.git.jani@nikula.org>\r
+In-Reply-To: <cover.1321386762.git.jani@nikula.org>\r
+References: <cover.1321386762.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\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: Tue, 15 Nov 2011 20:09:18 -0000\r
+\r
+Add support for --output=messages (which remains the default) and\r
+--output=threads to notmuch count.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ NEWS            |    5 +++++\r
+ notmuch-count.c |   18 ++++++++++++++++--\r
+ notmuch.1       |   29 +++++++++++++++++++++++++----\r
+ notmuch.c       |   20 ++++++++++++++++----\r
+ 4 files changed, 62 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/NEWS b/NEWS\r
+index f224d02..7bd9987 100644\r
+--- a/NEWS\r
++++ b/NEWS\r
+@@ -28,6 +28,11 @@ Add "notmuch search" --offset and --limit options\r
+   The search command now takes options --offset=[-]N and --limit=N to limit\r
+   the number of results shown.\r
\r
++Add "notmuch count --output" option\r
++\r
++  The count command is now capable of counting threads in addition to\r
++  messages. This is selected using the new --output=(threads|messages) option.\r
++\r
+ Optimizations\r
+ -------------\r
\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index a35be40..20ce334 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -29,6 +29,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+     notmuch_query_t *query;\r
+     char *query_str;\r
+     int i;\r
++    notmuch_bool_t output_messages = TRUE;\r
\r
+     argc--; argv++; /* skip subcommand argument */\r
\r
+@@ -37,7 +38,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+           i++;\r
+           break;\r
+       }\r
+-      {\r
++      if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {\r
++          const char *opt = argv[i] + sizeof ("--output=") - 1;\r
++          if (strcmp (opt, "threads") == 0) {\r
++              output_messages = FALSE;\r
++          } else if (strcmp (opt, "messages") == 0) {\r
++              output_messages = TRUE;\r
++          } else {\r
++              fprintf (stderr, "Invalid value for --output: %s\n", opt);\r
++              return 1;\r
++          }\r
++      } else {\r
+           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
+           return 1;\r
+       }\r
+@@ -71,7 +82,10 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+       return 1;\r
+     }\r
\r
+-    printf ("%u\n", notmuch_query_count_messages(query));\r
++    if (output_messages)\r
++      printf ("%u\n", notmuch_query_count_messages (query));\r
++    else\r
++      printf ("%u\n", notmuch_query_count_threads (query));\r
\r
+     notmuch_query_destroy (query);\r
+     notmuch_database_close (notmuch);\r
+diff --git a/notmuch.1 b/notmuch.1\r
+index cda777b..bc2f965 100644\r
+--- a/notmuch.1\r
++++ b/notmuch.1\r
+@@ -372,14 +372,35 @@ section below for details of the supported syntax for <search-terms>.\r
+ .RE\r
+ .RS 4\r
+ .TP 4\r
+-.BR count " <search-term>..."\r
++.BR count " [options...] <search-term>..."\r
\r
+ Count messages matching the search terms.\r
\r
+-The number of matching messages is output to stdout.\r
++The number of matching messages (or threads) is output to stdout.\r
\r
+-With no search terms, a count of all messages in the database will be\r
+-displayed.\r
++With no search terms, a count of all messages (or threads) in the database will\r
++be displayed.\r
++\r
++Supported options for\r
++.B count\r
++include\r
++.RS 4\r
++.TP 4\r
++.B \-\-output=(messages|threads)\r
++\r
++.RS 4\r
++.TP 4\r
++.B messages\r
++\r
++Output the number of matching messages. This is the default.\r
++.RE\r
++.RS 4\r
++.TP 4\r
++.B threads\r
++\r
++Output the number of matching threads.\r
++.RE\r
++.RE\r
+ .RE\r
+ .RE\r
\r
+diff --git a/notmuch.c b/notmuch.c\r
+index 394371d..77973f8 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -328,12 +328,24 @@ static command_t commands[] = {\r
+       "\tSee \"notmuch help search-terms\" for details of the search\n"\r
+       "\tterms syntax." },\r
+     { "count", notmuch_count_command,\r
+-      "<search-terms> [...]",\r
++      "[options...] <search-terms> [...]",\r
+       "Count messages matching the search terms.",\r
+-      "\tThe number of matching messages is output to stdout.\n"\r
++      "\tThe number of matching messages (or threads) is output to stdout.\n"\r
++      "\n"\r
++      "\tWith no search terms, a count of all messages (or threads) in\n"\r
++      "\tthe database will be displayed.\n"\r
++      "\n"\r
++      "\tSupported options for count include:\n"\r
++      "\n"\r
++      "\t--output=(messages|threads)\n"\r
++      "\n"\r
++      "\t\tmessages (default)\n"\r
++      "\n"\r
++      "\t\tOutput the number of matching messages.\n"\r
++      "\n"\r
++      "\t\tthreads\n"\r
+       "\n"\r
+-      "\tWith no search terms, a count of all messages in the database\n"\r
+-      "\twill be displayed.\n"\r
++      "\t\tOutput the number of matching threads.\n"\r
+       "\n"\r
+       "\tSee \"notmuch help search-terms\" for details of the search\n"\r
+       "\tterms syntax." },\r
+-- \r
+1.7.5.4\r
+\r