[patch v3.1] lib: add versions of n_q_count_{message,threads} with status return
authorDavid Bremner <david@tethera.net>
Sun, 27 Sep 2015 12:16:26 +0000 (09:16 +2100)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:49:39 +0000 (14:49 -0700)
6e/7670a44109e120c29c1aa4e175ede6b7cfd91d [new file with mode: 0644]

diff --git a/6e/7670a44109e120c29c1aa4e175ede6b7cfd91d b/6e/7670a44109e120c29c1aa4e175ede6b7cfd91d
new file mode 100644 (file)
index 0000000..527b3c9
--- /dev/null
@@ -0,0 +1,262 @@
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 4D96D6DE1510\r
+ for <notmuch@notmuchmail.org>; Sun, 27 Sep 2015 05:17:53 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.11\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.11 tagged_above=-999 required=5 tests=[AWL=0.110]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id B3vyZ-KdSRtK for <notmuch@notmuchmail.org>;\r
+ Sun, 27 Sep 2015 05:17:51 -0700 (PDT)\r
+Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 25BA66DE141E\r
+ for <notmuch@notmuchmail.org>; Sun, 27 Sep 2015 05:17:51 -0700 (PDT)\r
+Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1ZgAt8-0007YZ-9h; Sun, 27 Sep 2015 12:17:06 +0000\r
+Received: (nullmailer pid 15557 invoked by uid 1000); Sun, 27 Sep 2015\r
+ 12:16:47 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: [patch v3.1] lib: add versions of n_q_count_{message,threads} with\r
+ status return\r
+Date: Sun, 27 Sep 2015 09:16:26 -0300\r
+Message-Id: <1443356186-15517-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.5.3\r
+In-Reply-To: <1443322213-31075-3-git-send-email-david@tethera.net>\r
+References: <1443322213-31075-3-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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: Sun, 27 Sep 2015 12:17:53 -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 | 11 ++++++++++-\r
+ lib/notmuch.h   | 48 ++++++++++++++++++++++++++++++++++++++++++------\r
+ lib/query.cc    | 47 +++++++++++++++++++++++++++++++++--------------\r
+ 3 files changed, 85 insertions(+), 21 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index dcfad8c..fbfb1af 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1410,7 +1410,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+       (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |\r
+        NOTMUCH_FEATURE_LAST_MOD)) {\r
+       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
+@@ -1612,6 +1618,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+       sigaction (SIGALRM, &action, NULL);\r
+     }\r
\r
++    if (query)\r
++      notmuch_query_destroy (query);\r
++\r
+     talloc_free (local);\r
+     return status;\r
+ }\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 8775683..2fb778b 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -984,10 +984,26 @@ notmuch_threads_destroy (notmuch_threads_t *threads);\r
+  * This function performs a search and returns the number of matching\r
+  * 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.3 (notmuch 0.21). Please\r
++ * use notmuch_query_count_messages_st instead.\r
++ */\r
++NOTMUCH_DEPRECATED(4,3)\r
++unsigned int\r
+ notmuch_query_count_messages (notmuch_query_t *query);\r
\r
+ /**\r
+@@ -998,11 +1014,31 @@ 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
++ * @returns\r
+  *\r
+- * If an error occurs, this function may return 0.\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.3 (notmuch 0.21). Please\r
++ * use notmuch_query_count_threads_st instead.\r
++ */\r
++NOTMUCH_DEPRECATED(4,3)\r
++unsigned int\r
+ notmuch_query_count_threads (notmuch_query_t *query);\r
\r
+ /**\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 8cf0a07..e627bfc 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -541,9 +541,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
+@@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+                              "Query string was: %s\n",\r
+                              error.get_msg().c_str(),\r
+                              query->query_string);\r
+-\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 status;\r
++    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
\r
+     sort = query->sort;\r
+     query->sort = NOTMUCH_SORT_UNSORTED;\r
+-    status = notmuch_query_search_messages_st (query, &messages);\r
+-    if (status)\r
+-      return 0;\r
+-\r
++    ret = notmuch_query_search_messages_st (query, &messages);\r
++    if (ret)\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
+@@ -642,7 +661,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
+@@ -650,13 +669,13 @@ 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
+ notmuch_database_t *\r
+-- \r
+2.5.3\r
+\r