From 560dd162b6c987e9e5e332a1e269b2179f3f33fa Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Tue, 15 Jan 2013 23:54:44 +0200 Subject: [PATCH] [PATCH 2/5] cli: extract count printing to a separate function in notmuch count --- 7b/e00faf2c7f93184b31c26d781fbddce8da9b57 | 170 ++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 7b/e00faf2c7f93184b31c26d781fbddce8da9b57 diff --git a/7b/e00faf2c7f93184b31c26d781fbddce8da9b57 b/7b/e00faf2c7f93184b31c26d781fbddce8da9b57 new file mode 100644 index 000000000..bd6f7ba0b --- /dev/null +++ b/7b/e00faf2c7f93184b31c26d781fbddce8da9b57 @@ -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 D793D431FD4 + for ; Tue, 15 Jan 2013 13:55:01 -0800 (PST) +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 JE7T23TJCa+V for ; + Tue, 15 Jan 2013 13:55:00 -0800 (PST) +Received: from mail-la0-f51.google.com (mail-la0-f51.google.com + [209.85.215.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 8C775431FBC + for ; Tue, 15 Jan 2013 13:54:57 -0800 (PST) +Received: by mail-la0-f51.google.com with SMTP id fj20so704709lab.10 + for ; Tue, 15 Jan 2013 13:54:56 -0800 (PST) +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=lyw1doEiw720ujyPRpWWZ7TSj36nr/lY9ncMqPKrA0o=; + b=UbCKf+sI7CMwgtqD7yq2Fh5pBcrOWEP4z9BRzu7NPENnbWtVRcxY33myIq3Q/8edmV + kwBDBPZT0rNDd2Xrp9YANMaFNYchoD0SNzUZo3Xn3GwyejhVJLW21pwEhMF9u8BesGb0 + Isykt96+jSJ3TQ/856Vt+CoCUv5k6lkd49DzKzuqOrwhY5n8eU2knyDNuumVhir6weGz + b8ATo0WThXrJc9Dc9Fjj7nBJWK8LKcWmFnX/DX15g7TtHAwN4kABFfr5ARTqo9xOXYTJ + Ag7Vl3ft8QdJ7ue0Ui89yOj26zHZe1RbV3jUC3cJNFb3utz73yGqbY5QvuQnEWCWILQB + hfaQ== +X-Received: by 10.112.50.138 with SMTP id c10mr37221528lbo.104.1358286896037; + Tue, 15 Jan 2013 13:54:56 -0800 (PST) +Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. + [80.223.81.27]) + by mx.google.com with ESMTPS id bf3sm7272564lbb.16.2013.01.15.13.54.54 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Tue, 15 Jan 2013 13:54:55 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 2/5] cli: extract count printing to a separate function in + notmuch count +Date: Tue, 15 Jan 2013 23:54:44 +0200 +Message-Id: + <6f272f35a53fa297f1bd127c15d07cd2f4876222.1358273133.git.jani@nikula.org> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-Gm-Message-State: + ALoCoQltJEvGsLPZcr0U/YJz6ljdfYpWqSibAmqjiTG+qKe3mb4JHsJ7dSKznq3qNlFdBLxATIUQ +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: Tue, 15 Jan 2013 21:55:02 -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 6a9fae3..0e14b48 100644 +--- a/notmuch-count.c ++++ b/notmuch-count.c +@@ -32,17 +32,48 @@ 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 (void *ctx, int argc, char *argv[]) + { + notmuch_config_t *config; + 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', +@@ -76,33 +107,15 @@ notmuch_count_command (void *ctx, 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