[PATCH v3 2/6] cli: extract count printing to a separate function in notmuch count
authorJani Nikula <jani@nikula.org>
Sun, 31 Mar 2013 09:45:59 +0000 (12:45 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:54:08 +0000 (09:54 -0800)
18/47731303a6ea7e4319b22647f8d42935b0671f [new file with mode: 0644]

diff --git a/18/47731303a6ea7e4319b22647f8d42935b0671f b/18/47731303a6ea7e4319b22647f8d42935b0671f
new file mode 100644 (file)
index 0000000..34ba598
--- /dev/null
@@ -0,0 +1,170 @@
+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 0285B429E42\r
+       for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:18 -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 TkkLLiEWwB7K for <notmuch@notmuchmail.org>;\r
+       Sun, 31 Mar 2013 02:46:16 -0700 (PDT)\r
+Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com\r
+       [209.85.217.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 64F4E429E31\r
+       for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:13 -0700 (PDT)\r
+Received: by mail-lb0-f173.google.com with SMTP id w20so1236208lbh.4\r
+       for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:12 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+       :references:in-reply-to:references:x-gm-message-state;\r
+       bh=0J6jsAbnii4LrMwbBNnf/7MJgkQV9xH0Nm1qFiQY0zc=;\r
+       b=G3W6t8+6yp44tV6iehQ6aDTXTqTe/xrFrADKAERW8rmWF8W64XiGrq5t5ygpsMGEAO\r
+       sLYb3+mq26otu2gDjFX5gSdLr59UFlRAccoPgQVfareUBCP2uqvJL+vGYn4t0vpM9RNg\r
+       Z+DoLnMbikkvsB9AgzpLcjNLvddjTdEtAJF1ThrUcIeishgie73Bt6LwJvJu3l+h3eHY\r
+       CZAJ2TZni8n5u8ppF3KBPi/XysQOTM6eIGB+L6yD0tw8Mem3DjnvRtakSxMx6Wgyeief\r
+       /p6L6MVL3oY5I2eLjMcmerD+jsG81yHIJL6E9Bw6AprEfuzhyk8Kv+rjX3wzWssLgFcs\r
+       wZkA==\r
+X-Received: by 10.112.125.129 with SMTP id mq1mr3998724lbb.116.1364723171953; \r
+       Sun, 31 Mar 2013 02:46:11 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id sl5sm3723030lbb.10.2013.03.31.02.46.10\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 31 Mar 2013 02:46:11 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 2/6] cli: extract count printing to a separate function in\r
+       notmuch count\r
+Date: Sun, 31 Mar 2013 12:45:59 +0300\r
+Message-Id:\r
+ <a669137c4eef2c91f9572f5dc97b9ad115280e2a.1364722841.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <cover.1364722841.git.jani@nikula.org>\r
+References: <cover.1364722841.git.jani@nikula.org>\r
+In-Reply-To: <cover.1364722841.git.jani@nikula.org>\r
+References: <cover.1364722841.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQmqUuy7YcoV3j8yXVjQm+wSHi3fSRjYVmCotCXgyVtNMawOkZY+8fD00cekM2QKYHEEpG70\r
+Cc: Tomi Ollila <tomi.ollila@iki.fi>\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: Sun, 31 Mar 2013 09:46:18 -0000\r
+\r
+Make count printing on a query string reusable. No functional changes.\r
+---\r
+ notmuch-count.c |   59 +++++++++++++++++++++++++++++++++----------------------\r
+ 1 file changed, 36 insertions(+), 23 deletions(-)\r
+\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index c2f1b7d..630f036 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -32,16 +32,47 @@ enum {\r
+     EXCLUDE_FALSE,\r
+ };\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
++{\r
++    notmuch_query_t *query;\r
++    size_t i;\r
++\r
++    query = notmuch_query_create (notmuch, query_str);\r
++    if (query == NULL) {\r
++      fprintf (stderr, "Out of memory\n");\r
++      return 1;\r
++    }\r
++\r
++    for (i = 0; i < exclude_tags_length; i++)\r
++      notmuch_query_add_tag_exclude (query, exclude_tags[i]);\r
++\r
++    switch (output) {\r
++    case OUTPUT_MESSAGES:\r
++      printf ("%u\n", notmuch_query_count_messages (query));\r
++      break;\r
++    case OUTPUT_THREADS:\r
++      printf ("%u\n", notmuch_query_count_threads (query));\r
++      break;\r
++    }\r
++\r
++    notmuch_query_destroy (query);\r
++\r
++    return 0;\r
++}\r
++\r
+ int\r
+ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
+     notmuch_database_t *notmuch;\r
+-    notmuch_query_t *query;\r
+     char *query_str;\r
+     int opt_index;\r
+     int output = OUTPUT_MESSAGES;\r
+     int exclude = EXCLUDE_TRUE;\r
+-    unsigned int i;\r
++    const char **search_exclude_tags = NULL;\r
++    size_t search_exclude_tags_length = 0;\r
++    int ret;\r
\r
+     notmuch_opt_desc_t options[] = {\r
+       { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',\r
+@@ -71,33 +102,15 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+       return 1;\r
+     }\r
\r
+-    query = notmuch_query_create (notmuch, query_str);\r
+-    if (query == NULL) {\r
+-      fprintf (stderr, "Out of memory\n");\r
+-      return 1;\r
+-    }\r
+-\r
+     if (exclude == EXCLUDE_TRUE) {\r
+-      const char **search_exclude_tags;\r
+-      size_t search_exclude_tags_length;\r
+-\r
+       search_exclude_tags = notmuch_config_get_search_exclude_tags\r
+           (config, &search_exclude_tags_length);\r
+-      for (i = 0; i < search_exclude_tags_length; i++)\r
+-          notmuch_query_add_tag_exclude (query, search_exclude_tags[i]);\r
+     }\r
\r
+-    switch (output) {\r
+-    case OUTPUT_MESSAGES:\r
+-      printf ("%u\n", notmuch_query_count_messages (query));\r
+-      break;\r
+-    case OUTPUT_THREADS:\r
+-      printf ("%u\n", notmuch_query_count_threads (query));\r
+-      break;\r
+-    }\r
++    ret = print_count (notmuch, query_str, search_exclude_tags,\r
++                     search_exclude_tags_length, output);\r
\r
+-    notmuch_query_destroy (query);\r
+     notmuch_database_destroy (notmuch);\r
\r
+-    return 0;\r
++    return ret;\r
+ }\r
+-- \r
+1.7.10.4\r
+\r