[PATCH v2 2/6] cli: extract count printing to a separate function in notmuch count
authorJani Nikula <jani@nikula.org>
Sat, 9 Mar 2013 15:12:22 +0000 (17:12 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:59 +0000 (09:53 -0800)
fc/520b81bc3630c646871eb5ee53f1acff67e56a [new file with mode: 0644]

diff --git a/fc/520b81bc3630c646871eb5ee53f1acff67e56a b/fc/520b81bc3630c646871eb5ee53f1acff67e56a
new file mode 100644 (file)
index 0000000..2ae4df5
--- /dev/null
@@ -0,0 +1,169 @@
+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 710FC431FBD\r
+       for <notmuch@notmuchmail.org>; Sat,  9 Mar 2013 07:12:42 -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 fDo0HiKAkIXU for <notmuch@notmuchmail.org>;\r
+       Sat,  9 Mar 2013 07:12:41 -0800 (PST)\r
+Received: from mail-la0-f48.google.com (mail-la0-f48.google.com\r
+       [209.85.215.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id F015F431FC3\r
+       for <notmuch@notmuchmail.org>; Sat,  9 Mar 2013 07:12:39 -0800 (PST)\r
+Received: by mail-la0-f48.google.com with SMTP id fq13so2568074lab.21\r
+       for <notmuch@notmuchmail.org>; Sat, 09 Mar 2013 07:12:38 -0800 (PST)\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=dr76RrNpdGi2LNPcD99+w8AWDpSVPNFr+cUmtwSQt8rXbxyIaRoM+xQ5XlnNvAO0V7\r
+       vZOzAYT7iUZn99vkKIFAjkjW8SzL7leyjsXMUaNxBmK0zj8jmxqyBhE6DA+GXL0O8k6V\r
+       ugODq/4wiSQere/N/pU2qP6nmpoQzUKifk636qPZUSdc/+fbKcArIC3lUxvTbHNlTo/X\r
+       S7y4u1KB/wW+RTc4xtHEwq+53oupgI9oyZ314mdaX3qE29HAFBN9uC5qUo4sZ3HgClnF\r
+       uSBGiAQ//mNWC4k8WJ8iJvyX8NJmsCVphLIymR6GVH9okDHvLgGHfgl6u+W00KSMbGoy\r
+       pZjg==\r
+X-Received: by 10.112.10.102 with SMTP id h6mr2316951lbb.75.1362841958399;\r
+       Sat, 09 Mar 2013 07:12:38 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id e9sm2696962lbz.1.2013.03.09.07.12.36\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sat, 09 Mar 2013 07:12:37 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/6] cli: extract count printing to a separate function in\r
+       notmuch count\r
+Date: Sat,  9 Mar 2013 17:12:22 +0200\r
+Message-Id:\r
+ <fd3f0f94e505cd4e35b04efe6a9cac394caa61c6.1362841844.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <cover.1362841844.git.jani@nikula.org>\r
+References: <cover.1362841844.git.jani@nikula.org>\r
+In-Reply-To: <cover.1362841844.git.jani@nikula.org>\r
+References: <cover.1362841844.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQnFJFx96AXW8BZVe+HtO2VGlYkO+CAM8/q/QxsV/Xu/qETK5zfQwXTXVLyLWpZh+YVIsBF1\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: Sat, 09 Mar 2013 15:12:42 -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