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 1A935431FCF for ; Sat, 7 Mar 2015 00:44:59 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 2.438 X-Spam-Level: ** X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 tests=[DNS_FROM_AHBL_RHSBL=2.438] 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 Wlteh8kQsmYF for ; Sat, 7 Mar 2015 00:44:58 -0800 (PST) Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net [87.98.215.224]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 7C58B431FBD for ; Sat, 7 Mar 2015 00:44:58 -0800 (PST) Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim 4.80) (envelope-from ) id 1YUALJ-0002K4-5y; Sat, 07 Mar 2015 08:44:17 +0000 Received: (nullmailer pid 20410 invoked by uid 1000); Sat, 07 Mar 2015 08:43:23 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/4] cli: update to use new count API Date: Sat, 7 Mar 2015 09:43:15 +0100 Message-Id: <1425717797-19990-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1425717797-19990-1-git-send-email-david@tethera.net> References: <1419971380-10307-6-git-send-email-david@tethera.net> <1425717797-19990-1-git-send-email-david@tethera.net> 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: Sat, 07 Mar 2015 08:44:59 -0000 Essentially replace each call to notmuch_count_* with an if block. --- notmuch-count.c | 14 ++++++++++++-- notmuch-reply.c | 8 +++++++- notmuch-search.c | 14 ++++++++++++-- notmuch-show.c | 8 +++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index 6058f7c..cd6b0c9 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -71,6 +71,8 @@ print_count (notmuch_database_t *notmuch, const char *query_str, { notmuch_query_t *query; size_t i; + unsigned count; + notmuch_status_t status; query = notmuch_query_create (notmuch, query_str); if (query == NULL) { @@ -83,10 +85,18 @@ print_count (notmuch_database_t *notmuch, const char *query_str, switch (output) { case OUTPUT_MESSAGES: - printf ("%u\n", notmuch_query_count_messages (query)); + if ((status = notmuch_query_count_messages_st (query, &count))) { + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status)); + return 1; + } + printf ("%u\n", count); break; case OUTPUT_THREADS: - printf ("%u\n", notmuch_query_count_threads (query)); + if ((status = notmuch_query_count_threads_st (query, &count))) { + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status)); + return 1; + } + printf ("%u\n", count); break; case OUTPUT_FILES: printf ("%u\n", count_files (query)); diff --git a/notmuch-reply.c b/notmuch-reply.c index 7c1c809..0b3e5fd 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -650,8 +650,14 @@ notmuch_reply_format_sprinter(void *ctx, notmuch_messages_t *messages; notmuch_message_t *message; mime_node_t *node; + unsigned count; + notmuch_status_t status; - if (notmuch_query_count_messages (query) != 1) { + if ((status = notmuch_query_count_messages_st (query, &count))) { + fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status)); + return 1; + } + if (count != 1) { fprintf (stderr, "Error: search term did not match precisely one message.\n"); return 1; } diff --git a/notmuch-search.c b/notmuch-search.c index a591d45..ba631c0 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -113,7 +113,14 @@ do_search_threads (search_context_t *ctx) int i; if (ctx->offset < 0) { - ctx->offset += notmuch_query_count_threads (ctx->query); + unsigned count; + notmuch_status_t status; + if ((status = notmuch_query_count_threads_st (ctx->query, &count))) { + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status)); + return 1; + } + + ctx->offset += count; if (ctx->offset < 0) ctx->offset = 0; } @@ -414,7 +421,10 @@ do_search_messages (search_context_t *ctx) int i; if (ctx->offset < 0) { - ctx->offset += notmuch_query_count_messages (ctx->query); + unsigned count; + if (notmuch_query_count_messages_st (ctx->query, &count)) + return 1; + ctx->offset += count; if (ctx->offset < 0) ctx->offset = 0; } diff --git a/notmuch-show.c b/notmuch-show.c index d416fbd..749b1af 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -982,8 +982,14 @@ do_show_single (void *ctx, { notmuch_messages_t *messages; notmuch_message_t *message; + unsigned count; + notmuch_status_t status; + if ((status = notmuch_query_count_messages_st (query, &count))) { + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status)); + return 1; + } - if (notmuch_query_count_messages (query) != 1) { + if (count != 1) { fprintf (stderr, "Error: search term did not match precisely one message.\n"); return 1; } -- 2.1.4