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 21C0E431FBC for ; Sat, 7 Mar 2015 06:00:38 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 1.738 X-Spam-Level: * X-Spam-Status: No, score=1.738 tagged_above=-999 required=5 tests=[DNS_FROM_AHBL_RHSBL=2.438, 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 mnspBoGBoB+T for ; Sat, 7 Mar 2015 06:00:35 -0800 (PST) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B27C2431FAE for ; Sat, 7 Mar 2015 06:00:34 -0800 (PST) Received: by widex7 with SMTP id ex7so8954426wid.3 for ; Sat, 07 Mar 2015 06:00:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-type; bh=YVV2JUurDzsr6lc7zVUKUmcXy/5h5FAab/nRvI9XA9M=; b=GJ+NqAIjJKqcNee0QTgSHrarFF4KZdEe/Es7+P/qx/6EG0Rc5cvCYwMn5u7enST+mu /aZxuqHcV4gTVFloeIci82jLLtTkJuK0uI0IyxryKOjVFHTcXSamToVrMBpl+lRxX3yf cbJFVhuWy4qIP8TU7e28fn1ckNeqlTjEweGpPzb6MXHbVXobMVLrTKEeQ82KLwLecRJB bKBNMC4F8XDLaV8271N4zjbdiT42PIJY2z2exyEyjjzYIRsqZ2IkX1HnHptdyPe6QTqC wRQIeOhBfoJWsUT/5bDC2wsSd9jaKL7xQX8aftN4HCfqVCxPMofMbp4ibS0T5gSH4KYA rNww== X-Gm-Message-State: ALoCoQnj/77iwdnWIVlmNOYH/FB8Q+dILdAT/Di6db9qPpimYww6sLkEmp+pAINzFbIRfHdbrCI6 X-Received: by 10.180.82.129 with SMTP id i1mr42296183wiy.77.1425736833854; Sat, 07 Mar 2015 06:00:33 -0800 (PST) Received: from localhost (mobile-internet-bcee3b-76.dhcp.inet.fi. [188.238.59.76]) by mx.google.com with ESMTPSA id fa3sm6745204wib.17.2015.03.07.06.00.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Mar 2015 06:00:33 -0800 (PST) From: Jani Nikula To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH 2/4] cli: update to use new count API In-Reply-To: <1425717797-19990-3-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> <1425717797-19990-3-git-send-email-david@tethera.net> User-Agent: Notmuch/0.19+74~g6aeef2e (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Sat, 07 Mar 2015 16:00:53 +0200 Message-ID: <87sidgj4a2.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain 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 14:00:38 -0000 On Sat, 07 Mar 2015, David Bremner wrote: > Essentially replace each call to notmuch_count_* with an if block. LGTM, nitpicks inline. > --- > 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; As I said in patch 1, I'd personally prefer "unsigned int". > + 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))) { I'd rather have the assignment and check in separate lines. Somehow I feel it emphasizes the distinction between the happy day flow and the unusual cases. Same for other hunks in this patch. > + 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 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch