From 11a03eab9659b187103848635dc346c50f9de20b Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 7 Mar 2015 20:23:01 +0100 Subject: [PATCH] [PATCH 4/5] lib: add versions of notmuch_query_count_{message,threads} with status return --- f6/88008a598b1485618f9df9960a81b7697fd94c | 254 ++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 f6/88008a598b1485618f9df9960a81b7697fd94c diff --git a/f6/88008a598b1485618f9df9960a81b7697fd94c b/f6/88008a598b1485618f9df9960a81b7697fd94c new file mode 100644 index 000000000..cb70d0911 --- /dev/null +++ b/f6/88008a598b1485618f9df9960a81b7697fd94c @@ -0,0 +1,254 @@ +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 191B6431FBC + for ; Sat, 7 Mar 2015 11:24:25 -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 lJnqICRGaIxG for ; + Sat, 7 Mar 2015 11:24:22 -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 0D5C0431FAE + for ; Sat, 7 Mar 2015 11:24:22 -0800 (PST) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YUKK4-0004DC-8O; Sat, 07 Mar 2015 19:23:40 +0000 +Received: (nullmailer pid 28727 invoked by uid 1000); Sat, 07 Mar 2015 + 19:23:13 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH 4/5] lib: add versions of + notmuch_query_count_{message,threads} with status return +Date: Sat, 7 Mar 2015 20:23:01 +0100 +Message-Id: <1425756182-28468-5-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1425756182-28468-1-git-send-email-david@tethera.net> +References: <1425756182-28468-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 19:24:25 -0000 + +Although I think it's a pretty bad idea to continue using the old API, +this allows both a more gentle transition for clients of the library, +and allows us to break one monolithic change into a series +--- + lib/database.cc | 8 +++++++- + lib/notmuch.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ + lib/query.cc | 38 ++++++++++++++++++++++++++++++-------- + 3 files changed, 83 insertions(+), 15 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 8680963..b8fb7f7 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -1275,7 +1275,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + if (new_features & + (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) { + notmuch_query_t *query = notmuch_query_create (notmuch, ""); +- total += notmuch_query_count_messages (query); ++ unsigned msg_count; ++ ++ status = notmuch_query_count_messages_st (query, &msg_count); ++ if (status) ++ goto DONE; ++ ++ total += msg_count; + notmuch_query_destroy (query); + } + if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) { +diff --git a/lib/notmuch.h b/lib/notmuch.h +index 087f3f0..2acfbb5 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -927,12 +927,31 @@ notmuch_threads_destroy (notmuch_threads_t *threads); + * This function performs a search and returns Xapian's best + * guess as to number of matching messages. + * +- * If a Xapian exception occurs, this function may return 0 (after +- * printing a message). ++ * @returns ++ * ++ * NOTMUCH_STATUS_SUCCESS: query complete successfully. ++ * ++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The ++ * value of *count is not defined. + */ +-unsigned ++notmuch_status_t ++notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count); ++ ++/** ++ * like notmuch_query_count_messages_st, but without a status return ++ * ++ * May return 0 in the case of errors. ++ * ++ * @deprecated Deprecated since libnotmuch 4.2 (notmuch 0.20). Please ++ * use notmuch_query_count_messages_st instead. ++ */ ++NOTMUCH_DEPRECATED(4,2) ++unsigned int + notmuch_query_count_messages (notmuch_query_t *query); + ++ ++ ++ + /** + * Return the number of threads matching a search. + * +@@ -941,13 +960,34 @@ notmuch_query_count_messages (notmuch_query_t *query); + * search. + * + * Note that this is a significantly heavier operation than +- * notmuch_query_count_messages(). ++ * notmuch_query_count_messages{_st}(). + * +- * If an error occurs, this function may return 0. ++ * @returns ++ * ++ * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value ++ * of *count is not defined ++ ++ * NOTMUCH_STATUS_SUCCESS: query complete successfully. ++ * ++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The ++ * value of *count is not defined. + */ +-unsigned ++notmuch_status_t ++notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count); ++ ++/** ++ * like notmuch_query_count_threads, but without a status return. ++ * ++ * May return 0 in case of errors. ++ * ++ * @deprecated Deprecated as of libnotmuch 4.2 (notmuch 0.20). Please ++ * use notmuch_query_count_threads_st instead. ++ */ ++NOTMUCH_DEPRECATED(4,2) ++unsigned int + notmuch_query_count_threads (notmuch_query_t *query); + ++ + /** + * Get the thread ID of 'thread'. + * +diff --git a/lib/query.cc b/lib/query.cc +index 1871a81..984f577 100644 +--- a/lib/query.cc ++++ b/lib/query.cc +@@ -538,9 +538,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads) + talloc_free (threads); + } + +-unsigned ++unsigned int + notmuch_query_count_messages (notmuch_query_t *query) + { ++ notmuch_status_t status; ++ unsigned int count; ++ ++ status = notmuch_query_count_messages_st (query, &count); ++ return status ? 0 : count; ++} ++ ++notmuch_status_t ++notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out) ++{ + notmuch_database_t *notmuch = query->notmuch; + const char *query_string = query->query_string; + Xapian::doccount count = 0; +@@ -595,18 +605,30 @@ notmuch_query_count_messages (notmuch_query_t *query) + fprintf (stderr, "A Xapian exception occurred: %s\n", + error.get_msg().c_str()); + fprintf (stderr, "Query string was: %s\n", query->query_string); ++ return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } + +- return count; ++ *count_out = count; ++ return NOTMUCH_STATUS_SUCCESS; + } + + unsigned + notmuch_query_count_threads (notmuch_query_t *query) + { ++ notmuch_status_t status; ++ unsigned int count; ++ ++ status = notmuch_query_count_threads_st (query, &count); ++ return status ? 0 : count; ++} ++ ++notmuch_status_t ++notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count) ++{ + notmuch_messages_t *messages; + GHashTable *hash; +- unsigned int count; + notmuch_sort_t sort; ++ notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; + + sort = query->sort; + query->sort = NOTMUCH_SORT_UNSORTED; +@@ -615,12 +637,12 @@ notmuch_query_count_threads (notmuch_query_t *query) + return ret; + query->sort = sort; + if (messages == NULL) +- return 0; ++ return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); + if (hash == NULL) { + talloc_free (messages); +- return 0; ++ return NOTMUCH_STATUS_OUT_OF_MEMORY; + } + + while (notmuch_messages_valid (messages)) { +@@ -629,7 +651,7 @@ notmuch_query_count_threads (notmuch_query_t *query) + char *thread_id_copy = talloc_strdup (messages, thread_id); + if (unlikely (thread_id_copy == NULL)) { + notmuch_message_destroy (message); +- count = 0; ++ ret = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + g_hash_table_insert (hash, thread_id_copy, NULL); +@@ -637,11 +659,11 @@ notmuch_query_count_threads (notmuch_query_t *query) + notmuch_messages_move_to_next (messages); + } + +- count = g_hash_table_size (hash); ++ *count = g_hash_table_size (hash); + + DONE: + g_hash_table_unref (hash); + talloc_free (messages); + +- return count; ++ return ret; + } +-- +2.1.4 + -- 2.26.2