unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/4] cli: update to use new count API
Date: Sat,  7 Mar 2015 09:43:15 +0100	[thread overview]
Message-ID: <1425717797-19990-3-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1425717797-19990-1-git-send-email-david@tethera.net>

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

  parent reply	other threads:[~2015-03-07  8:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-30 20:29 update count API round 2 David Bremner
2014-12-30 20:29 ` [Patch v2 1/5] build: integrate building ruby bindings into notmuch build process David Bremner
2014-12-30 20:29 ` [Patch v2 2/5] test: add python tests for query.count_{messages,threads} David Bremner
2014-12-30 20:29 ` [Patch v2 3/5] test: port existing python tests to ruby David Bremner
2014-12-30 20:29 ` [Patch v2 4/5] bindings/ruby: gitignore *.o David Bremner
2014-12-30 20:29 ` [Patch v2 5/5] lib: add status return to notmuch_query_count_{message,threads} David Bremner
2015-03-07  8:43   ` update count API, round 3 David Bremner
2015-03-07  8:43     ` [PATCH 1/4] lib: add versions of notmuch_query_count_{message,threads} with status return David Bremner
2015-03-07 13:57       ` [PATCH 1/4] lib: add versions of notmuch_query_count_{message, threads} " Jani Nikula
2015-03-07  8:43     ` David Bremner [this message]
2015-03-07 14:00       ` [PATCH 2/4] cli: update to use new count API Jani Nikula
2015-03-07  8:43     ` [PATCH 3/4] ruby: update bindings for " David Bremner
2015-03-07  8:43     ` [PATCH 4/4] python: " David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425717797-19990-3-git-send-email-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).