Essentially replace each call to notmuch_count_* with an if block. --- notmuch-count.c | 16 ++++++++++++++-- notmuch-reply.c | 11 ++++++++++- notmuch-search.c | 17 +++++++++++++++-- notmuch-show.c | 11 ++++++++++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index d555bf1..b475495 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -72,6 +72,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) { @@ -84,10 +86,20 @@ print_count (notmuch_database_t *notmuch, const char *query_str, switch (output) { case OUTPUT_MESSAGES: - printf ("%u\n", notmuch_query_count_messages (query)); + status = notmuch_query_count_messages_st (query, &count); + if (status) { + 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)); + status = notmuch_query_count_threads_st (query, &count); + if (status) { + 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 dca4e42..88998c3 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -657,8 +657,17 @@ notmuch_reply_format_sprinter(void *ctx, notmuch_messages_t *messages; notmuch_message_t *message; mime_node_t *node; + unsigned count; + notmuch_status_t status; + + status = notmuch_query_count_messages_st (query, &count); + + if (status) { + 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; } diff --git a/notmuch-search.c b/notmuch-search.c index 20feda4..d8020f2 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -114,7 +114,15 @@ do_search_threads (search_context_t *ctx) notmuch_status_t status; if (ctx->offset < 0) { - ctx->offset += notmuch_query_count_threads (ctx->query); + unsigned count; + notmuch_status_t status; + status = notmuch_query_count_threads_st (ctx->query, &count); + if (status) { + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status)); + return 1; + } + + ctx->offset += count; if (ctx->offset < 0) ctx->offset = 0; } @@ -418,7 +426,12 @@ do_search_messages (search_context_t *ctx) notmuch_status_t status; if (ctx->offset < 0) { - ctx->offset += notmuch_query_count_messages (ctx->query); + unsigned count; + notmuch_status_t status; + status = notmuch_query_count_messages_st (ctx->query, &count); + if (status) + return 1; + ctx->offset += count; if (ctx->offset < 0) ctx->offset = 0; } diff --git a/notmuch-show.c b/notmuch-show.c index af8741d..834ed89 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -982,8 +982,17 @@ do_show_single (void *ctx, { notmuch_messages_t *messages; notmuch_message_t *message; + unsigned count; + notmuch_status_t status; + + status = notmuch_query_count_messages_st (query, &count); + + if (status) { + 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