--- /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 28664431FC2\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 00:44:47 -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 9B6jDQ2ECDho for <notmuch@notmuchmail.org>;\r
+ Sat, 7 Mar 2015 00:44:45 -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 E22FE431FC0\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 00:44:44 -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 1YUAL5-0002Jw-SF; Sat, 07 Mar 2015 08:44:03 +0000\r
+Received: (nullmailer pid 20408 invoked by uid 1000); Sat, 07 Mar 2015\r
+ 08:43:23 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/4] lib: add versions of\r
+ notmuch_query_count_{message,threads} with status return\r
+Date: Sat, 7 Mar 2015 09:43:14 +0100\r
+Message-Id: <1425717797-19990-2-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1425717797-19990-1-git-send-email-david@tethera.net>\r
+References: <1419971380-10307-6-git-send-email-david@tethera.net>\r
+ <1425717797-19990-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 08:44:47 -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 | 34 ++++++++++++++++++++++++++++++----\r
+ lib/query.cc | 36 +++++++++++++++++++++++++++++-------\r
+ 3 files changed, 66 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 3974e2e..d92eec0 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 3e326bf..a0fc276 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -914,12 +914,23 @@ 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
++ * The version returning the count directly instead of a status value \r
++ * is deprecated.\r
++ *\r
++ * Return value (of the _st) version:\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
++\r
+ unsigned\r
+ notmuch_query_count_messages (notmuch_query_t *query);\r
+ \r
++notmuch_status_t\r
++notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
++\r
+ /**\r
+ * Return the number of threads matching a search.\r
+ *\r
+@@ -928,13 +939,28 @@ 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
++ * The version returning the count directly instead of a status value \r
++ * is deprecated.\r
+ *\r
+- * If an error occurs, this function may return 0.\r
++ * Return values (of the _st version):\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
++\r
+ unsigned\r
+ notmuch_query_count_threads (notmuch_query_t *query);\r
+ \r
++notmuch_status_t\r
++notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
++\r
+ /**\r
+ * Get the thread ID of 'thread'.\r
+ *\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 9279915..883d128 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -541,6 +541,16 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
+ unsigned\r
+ notmuch_query_count_messages (notmuch_query_t *query)\r
+ {\r
++ notmuch_status_t status;\r
++ unsigned 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,30 +605,42 @@ 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 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
+ messages = notmuch_query_search_messages (query);\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
+@@ -627,7 +649,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
+@@ -635,11 +657,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