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