[PATCH v3 4/7] cli: add support for --output parameter in notmuch count
authorJani Nikula <jani@nikula.org>
Fri, 4 Nov 2011 20:25:12 +0000 (22:25 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:59 +0000 (09:39 -0800)
df/a8ed68dd844acc96ef48a017a23c0d8d248beb [new file with mode: 0644]

diff --git a/df/a8ed68dd844acc96ef48a017a23c0d8d248beb b/df/a8ed68dd844acc96ef48a017a23c0d8d248beb
new file mode 100644 (file)
index 0000000..92880db
--- /dev/null
@@ -0,0 +1,111 @@
+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 065AA429E31\r
+       for <notmuch@notmuchmail.org>; Fri,  4 Nov 2011 13:25:30 -0700 (PDT)\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 Z2bOdaxCu83s for <notmuch@notmuchmail.org>;\r
+       Fri,  4 Nov 2011 13:25:28 -0700 (PDT)\r
+Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
+       [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 959C2429E2F\r
+       for <notmuch@notmuchmail.org>; Fri,  4 Nov 2011 13:25:27 -0700 (PDT)\r
+Received: by mail-fx0-f53.google.com with SMTP id n15so52582faa.26\r
+       for <notmuch@notmuchmail.org>; Fri, 04 Nov 2011 13:25:27 -0700 (PDT)\r
+Received: by 10.223.76.66 with SMTP id b2mr27329292fak.15.1320438327178;\r
+       Fri, 04 Nov 2011 13:25:27 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id l26sm18277004fad.17.2011.11.04.13.25.25\r
+       (version=SSLv3 cipher=OTHER); Fri, 04 Nov 2011 13:25:26 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 4/7] cli: add support for --output parameter in notmuch\r
+       count\r
+Date: Fri,  4 Nov 2011 22:25:12 +0200\r
+Message-Id:\r
+ <9bb08f8ab40e14b28137ea7a4d592d587efce0bc.1320349030.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1320349030.git.jani@nikula.org>\r
+References: <cover.1320349030.git.jani@nikula.org>\r
+In-Reply-To: <cover.1320349030.git.jani@nikula.org>\r
+References: <cover.1320349030.git.jani@nikula.org>\r
+Cc: amdragon@mit.edu\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: Fri, 04 Nov 2011 20:25:30 -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
+ notmuch-count.c |   18 ++++++++++++++++--\r
+ 1 files changed, 16 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index a35be40..09b413e 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
+-- \r
+1.7.5.4\r
+\r