--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 191B6431FBC\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 11:24:25 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.438\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id lJnqICRGaIxG for <notmuch@notmuchmail.org>;\r
+ Sat, 7 Mar 2015 11:24:22 -0800 (PST)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 0D5C0431FAE\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 11:24:22 -0800 (PST)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1YUKK4-0004DC-8O; Sat, 07 Mar 2015 19:23:40 +0000\r
+Received: (nullmailer pid 28727 invoked by uid 1000); Sat, 07 Mar 2015\r
+ 19:23:13 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/5] lib: add versions of\r
+ notmuch_query_count_{message,threads} with status return\r
+Date: Sat, 7 Mar 2015 20:23:01 +0100\r
+Message-Id: <1425756182-28468-5-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1425756182-28468-1-git-send-email-david@tethera.net>\r
+References: <1425756182-28468-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 07 Mar 2015 19:24:25 -0000\r
+\r
+Although I think it's a pretty bad idea to continue using the old API,\r
+this allows both a more gentle transition for clients of the library,\r
+and allows us to break one monolithic change into a series\r
+---\r
+ lib/database.cc | 8 +++++++-\r
+ lib/notmuch.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++------\r
+ lib/query.cc | 38 ++++++++++++++++++++++++++++++--------\r
+ 3 files changed, 83 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 8680963..b8fb7f7 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1275,7 +1275,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+ if (new_features &\r
+ (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {\r
+ notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
+- total += notmuch_query_count_messages (query);\r
++ unsigned msg_count;\r
++\r
++ status = notmuch_query_count_messages_st (query, &msg_count);\r
++ if (status)\r
++ goto DONE;\r
++\r
++ total += msg_count;\r
+ notmuch_query_destroy (query);\r
+ }\r
+ if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 087f3f0..2acfbb5 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -927,12 +927,31 @@ notmuch_threads_destroy (notmuch_threads_t *threads);\r
+ * This function performs a search and returns Xapian's best\r
+ * guess as to number of matching messages.\r
+ *\r
+- * If a Xapian exception occurs, this function may return 0 (after\r
+- * printing a message).\r
++ * @returns\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
++ * value of *count is not defined.\r
+ */\r
+-unsigned\r
++notmuch_status_t\r
++notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
++\r
++/**\r
++ * like notmuch_query_count_messages_st, but without a status return\r
++ *\r
++ * May return 0 in the case of errors.\r
++ *\r
++ * @deprecated Deprecated since libnotmuch 4.2 (notmuch 0.20). Please\r
++ * use notmuch_query_count_messages_st instead.\r
++ */\r
++NOTMUCH_DEPRECATED(4,2)\r
++unsigned int\r
+ notmuch_query_count_messages (notmuch_query_t *query);\r
+ \r
++\r
++\r
++\r
+ /**\r
+ * Return the number of threads matching a search.\r
+ *\r
+@@ -941,13 +960,34 @@ notmuch_query_count_messages (notmuch_query_t *query);\r
+ * search.\r
+ *\r
+ * Note that this is a significantly heavier operation than\r
+- * notmuch_query_count_messages().\r
++ * notmuch_query_count_messages{_st}().\r
+ *\r
+- * If an error occurs, this function may return 0.\r
++ * @returns\r
++ *\r
++ * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value\r
++ * of *count is not defined\r
++\r
++ * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
++ * value of *count is not defined.\r
+ */\r
+-unsigned\r
++notmuch_status_t\r
++notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
++\r
++/**\r
++ * like notmuch_query_count_threads, but without a status return.\r
++ *\r
++ * May return 0 in case of errors.\r
++ *\r
++ * @deprecated Deprecated as of libnotmuch 4.2 (notmuch 0.20). Please\r
++ * use notmuch_query_count_threads_st instead.\r
++ */\r
++NOTMUCH_DEPRECATED(4,2)\r
++unsigned int\r
+ notmuch_query_count_threads (notmuch_query_t *query);\r
+ \r
++\r
+ /**\r
+ * Get the thread ID of 'thread'.\r
+ *\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 1871a81..984f577 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -538,9 +538,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
+ talloc_free (threads);\r
+ }\r
+ \r
+-unsigned\r
++unsigned int\r
+ notmuch_query_count_messages (notmuch_query_t *query)\r
+ {\r
++ notmuch_status_t status;\r
++ unsigned int count;\r
++\r
++ status = notmuch_query_count_messages_st (query, &count);\r
++ return status ? 0 : count;\r
++}\r
++\r
++notmuch_status_t\r
++notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
++{\r
+ notmuch_database_t *notmuch = query->notmuch;\r
+ const char *query_string = query->query_string;\r
+ Xapian::doccount count = 0;\r
+@@ -595,18 +605,30 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+ fprintf (stderr, "A Xapian exception occurred: %s\n",\r
+ error.get_msg().c_str());\r
+ fprintf (stderr, "Query string was: %s\n", query->query_string);\r
++ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+ }\r
+ \r
+- return count;\r
++ *count_out = count;\r
++ return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
+ \r
+ unsigned\r
+ notmuch_query_count_threads (notmuch_query_t *query)\r
+ {\r
++ notmuch_status_t status;\r
++ unsigned int count;\r
++\r
++ status = notmuch_query_count_threads_st (query, &count);\r
++ return status ? 0 : count;\r
++}\r
++ \r
++notmuch_status_t\r
++notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)\r
++{\r
+ notmuch_messages_t *messages;\r
+ GHashTable *hash;\r
+- unsigned int count;\r
+ notmuch_sort_t sort;\r
++ notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
+ \r
+ sort = query->sort;\r
+ query->sort = NOTMUCH_SORT_UNSORTED;\r
+@@ -615,12 +637,12 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
+ return ret;\r
+ query->sort = sort;\r
+ if (messages == NULL)\r
+- return 0;\r
++ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+ \r
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
+ if (hash == NULL) {\r
+ talloc_free (messages);\r
+- return 0;\r
++ return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+ }\r
+ \r
+ while (notmuch_messages_valid (messages)) {\r
+@@ -629,7 +651,7 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
+ char *thread_id_copy = talloc_strdup (messages, thread_id);\r
+ if (unlikely (thread_id_copy == NULL)) {\r
+ notmuch_message_destroy (message);\r
+- count = 0;\r
++ ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+ goto DONE;\r
+ }\r
+ g_hash_table_insert (hash, thread_id_copy, NULL);\r
+@@ -637,11 +659,11 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
+ notmuch_messages_move_to_next (messages);\r
+ }\r
+ \r
+- count = g_hash_table_size (hash);\r
++ *count = g_hash_table_size (hash);\r
+ \r
+ DONE:\r
+ g_hash_table_unref (hash);\r
+ talloc_free (messages);\r
+ \r
+- return count;\r
++ return ret;\r
+ }\r
+-- \r
+2.1.4\r
+\r