1 Return-Path: <bremner@tesseract.cs.unb.ca>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 28664431FC2
\r
6 for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 00:44:47 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=2.438 tagged_above=-999 required=5
\r
12 tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 9B6jDQ2ECDho for <notmuch@notmuchmail.org>;
\r
16 Sat, 7 Mar 2015 00:44:45 -0800 (PST)
\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net
\r
19 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id E22FE431FC0
\r
22 for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 00:44:44 -0800 (PST)
\r
23 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim
\r
24 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
25 id 1YUAL5-0002Jw-SF; Sat, 07 Mar 2015 08:44:03 +0000
\r
26 Received: (nullmailer pid 20408 invoked by uid 1000); Sat, 07 Mar 2015
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: [PATCH 1/4] lib: add versions of
\r
31 notmuch_query_count_{message,threads} with status return
\r
32 Date: Sat, 7 Mar 2015 09:43:14 +0100
\r
33 Message-Id: <1425717797-19990-2-git-send-email-david@tethera.net>
\r
34 X-Mailer: git-send-email 2.1.4
\r
35 In-Reply-To: <1425717797-19990-1-git-send-email-david@tethera.net>
\r
36 References: <1419971380-10307-6-git-send-email-david@tethera.net>
\r
37 <1425717797-19990-1-git-send-email-david@tethera.net>
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Sat, 07 Mar 2015 08:44:47 -0000
\r
52 Although I think it's a pretty bad idea to continue using the old API,
\r
53 this allows both a more gentle transition for clients of the library,
\r
54 and allows us to break one monolithic change into a series
\r
56 lib/database.cc | 8 +++++++-
\r
57 lib/notmuch.h | 34 ++++++++++++++++++++++++++++++----
\r
58 lib/query.cc | 36 +++++++++++++++++++++++++++++-------
\r
59 3 files changed, 66 insertions(+), 12 deletions(-)
\r
61 diff --git a/lib/database.cc b/lib/database.cc
\r
62 index 3974e2e..d92eec0 100644
\r
63 --- a/lib/database.cc
\r
64 +++ b/lib/database.cc
\r
65 @@ -1275,7 +1275,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
67 (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {
\r
68 notmuch_query_t *query = notmuch_query_create (notmuch, "");
\r
69 - total += notmuch_query_count_messages (query);
\r
70 + unsigned msg_count;
\r
72 + status = notmuch_query_count_messages_st (query, &msg_count);
\r
76 + total += msg_count;
\r
77 notmuch_query_destroy (query);
\r
79 if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
\r
80 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
81 index 3e326bf..a0fc276 100644
\r
84 @@ -914,12 +914,23 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
\r
85 * This function performs a search and returns Xapian's best
\r
86 * guess as to number of matching messages.
\r
88 - * If a Xapian exception occurs, this function may return 0 (after
\r
89 - * printing a message).
\r
90 + * The version returning the count directly instead of a status value
\r
93 + * Return value (of the _st) version:
\r
95 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
\r
97 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
\r
98 + * value of *count is not defined.
\r
102 notmuch_query_count_messages (notmuch_query_t *query);
\r
105 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);
\r
108 * Return the number of threads matching a search.
\r
110 @@ -928,13 +939,28 @@ notmuch_query_count_messages (notmuch_query_t *query);
\r
113 * Note that this is a significantly heavier operation than
\r
114 - * notmuch_query_count_messages().
\r
115 + * notmuch_query_count_messages{_st}().
\r
117 + * The version returning the count directly instead of a status value
\r
120 - * If an error occurs, this function may return 0.
\r
121 + * Return values (of the _st version):
\r
123 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
\r
124 + * of *count is not defined
\r
126 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
\r
128 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
\r
129 + * value of *count is not defined.
\r
133 notmuch_query_count_threads (notmuch_query_t *query);
\r
136 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
\r
139 * Get the thread ID of 'thread'.
\r
141 diff --git a/lib/query.cc b/lib/query.cc
\r
142 index 9279915..883d128 100644
\r
145 @@ -541,6 +541,16 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
\r
147 notmuch_query_count_messages (notmuch_query_t *query)
\r
149 + notmuch_status_t status;
\r
152 + status = notmuch_query_count_messages_st (query, &count);
\r
153 + return status ? 0 : count;
\r
157 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)
\r
159 notmuch_database_t *notmuch = query->notmuch;
\r
160 const char *query_string = query->query_string;
\r
161 Xapian::doccount count = 0;
\r
162 @@ -595,30 +605,42 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
163 fprintf (stderr, "A Xapian exception occurred: %s\n",
\r
164 error.get_msg().c_str());
\r
165 fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
166 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
170 + *count_out=count;
\r
171 + return NOTMUCH_STATUS_SUCCESS;
\r
175 notmuch_query_count_threads (notmuch_query_t *query)
\r
177 + notmuch_status_t status;
\r
180 + status = notmuch_query_count_threads_st (query, &count);
\r
181 + return status ? 0 : count;
\r
185 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)
\r
187 notmuch_messages_t *messages;
\r
189 - unsigned int count;
\r
190 notmuch_sort_t sort;
\r
191 + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
193 sort = query->sort;
\r
194 query->sort = NOTMUCH_SORT_UNSORTED;
\r
195 messages = notmuch_query_search_messages (query);
\r
196 query->sort = sort;
\r
197 if (messages == NULL)
\r
199 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
201 hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
202 if (hash == NULL) {
\r
203 talloc_free (messages);
\r
205 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
208 while (notmuch_messages_valid (messages)) {
\r
209 @@ -627,7 +649,7 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
210 char *thread_id_copy = talloc_strdup (messages, thread_id);
\r
211 if (unlikely (thread_id_copy == NULL)) {
\r
212 notmuch_message_destroy (message);
\r
214 + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
217 g_hash_table_insert (hash, thread_id_copy, NULL);
\r
218 @@ -635,11 +657,11 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
219 notmuch_messages_move_to_next (messages);
\r
222 - count = g_hash_table_size (hash);
\r
223 + *count = g_hash_table_size (hash);
\r
226 g_hash_table_unref (hash);
\r
227 talloc_free (messages);
\r