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 00FE0431FD2
\r
6 for <notmuch@notmuchmail.org>; Mon, 29 Dec 2014 04:15:20 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 X9JGzWiQ2AMP for <notmuch@notmuchmail.org>;
\r
16 Mon, 29 Dec 2014 04:15:16 -0800 (PST)
\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])
\r
18 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 791CE431FC9
\r
21 for <notmuch@notmuchmail.org>; Mon, 29 Dec 2014 04:15:16 -0800 (PST)
\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)
\r
23 (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
24 id 1Y5ZE8-0007Xf-Da; Mon, 29 Dec 2014 08:15:12 -0400
\r
25 Received: (nullmailer pid 32219 invoked by uid 1000); Mon, 29 Dec 2014
\r
27 From: David Bremner <david@tethera.net>
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [PATCH] lib: add status return to
\r
30 notmuch_query_count_{message,threads}
\r
31 Date: Mon, 29 Dec 2014 13:14:51 +0100
\r
32 Message-Id: <1419855291-31972-1-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 2.1.3
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.13
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Mon, 29 Dec 2014 12:15:20 -0000
\r
48 We follow many other notmuch_ functions by having a status return and
\r
49 an output parameter. I decided not to add compatibility wrappers but
\r
50 just to break the API because the old API seems particularly awful.
\r
52 I guess this breaks all of the bindings, which serves them right for not having adequate test suites ;).
\r
54 lib/Makefile.local | 4 ++--
\r
55 lib/database.cc | 8 +++++++-
\r
56 lib/notmuch.h | 26 +++++++++++++++++++-------
\r
57 lib/query.cc | 24 +++++++++++++-----------
\r
58 notmuch-count.c | 14 ++++++++++++--
\r
59 notmuch-reply.c | 8 +++++++-
\r
60 notmuch-search.c | 14 ++++++++++++--
\r
61 notmuch-show.c | 8 +++++++-
\r
62 8 files changed, 79 insertions(+), 27 deletions(-)
\r
64 diff --git a/lib/Makefile.local b/lib/Makefile.local
\r
65 index 4120390..4bf8116 100644
\r
66 --- a/lib/Makefile.local
\r
67 +++ b/lib/Makefile.local
\r
69 # the library interface, (such as the deletion of an API or a major
\r
70 # semantic change that breaks formerly functioning code).
\r
72 -LIBNOTMUCH_VERSION_MAJOR = 4
\r
73 +LIBNOTMUCH_VERSION_MAJOR = 5
\r
75 # The minor version of the library interface. This should be incremented at
\r
76 # the time of release for any additions to the library interface,
\r
77 # (and when it is incremented, the release version of the library should
\r
79 -LIBNOTMUCH_VERSION_MINOR = 1
\r
80 +LIBNOTMUCH_VERSION_MINOR = 0
\r
82 # The release version the library interface. This should be incremented at
\r
83 # the time of release if there have been no changes to the interface, (but
\r
84 diff --git a/lib/database.cc b/lib/database.cc
\r
85 index 3601f9d..b7fbc63 100644
\r
86 --- a/lib/database.cc
\r
87 +++ b/lib/database.cc
\r
88 @@ -1268,7 +1268,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
90 (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {
\r
91 notmuch_query_t *query = notmuch_query_create (notmuch, "");
\r
92 - total += notmuch_query_count_messages (query);
\r
93 + unsigned msg_count;
\r
95 + status = notmuch_query_count_messages (query, &msg_count);
\r
99 + total += msg_count;
\r
100 notmuch_query_destroy (query);
\r
102 if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
\r
103 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
104 index 220839b..37bf0bd 100644
\r
105 --- a/lib/notmuch.h
\r
106 +++ b/lib/notmuch.h
\r
107 @@ -898,11 +898,15 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
\r
108 * This function performs a search and returns Xapian's best
\r
109 * guess as to number of matching messages.
\r
111 - * If a Xapian exception occurs, this function may return 0 (after
\r
112 - * printing a message).
\r
115 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
\r
117 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
\r
118 + * value of *count is not defined.
\r
121 -notmuch_query_count_messages (notmuch_query_t *query);
\r
123 +notmuch_query_count_messages (notmuch_query_t *query, unsigned *count);
\r
126 * Return the number of threads matching a search.
\r
127 @@ -914,10 +918,18 @@ notmuch_query_count_messages (notmuch_query_t *query);
\r
128 * Note that this is a significantly heavier operation than
\r
129 * notmuch_query_count_messages().
\r
131 - * If an error occurs, this function may return 0.
\r
134 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
\r
135 + * of *count is not defined
\r
137 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
\r
139 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
\r
140 + * value of *count is not defined.
\r
143 -notmuch_query_count_threads (notmuch_query_t *query);
\r
145 +notmuch_query_count_threads (notmuch_query_t *query, unsigned *count);
\r
148 * Get the thread ID of 'thread'.
\r
149 diff --git a/lib/query.cc b/lib/query.cc
\r
150 index 60ff8bd..10ecf2e 100644
\r
153 @@ -508,8 +508,8 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
\r
154 talloc_free (threads);
\r
158 -notmuch_query_count_messages (notmuch_query_t *query)
\r
160 +notmuch_query_count_messages (notmuch_query_t *query, unsigned *count_out)
\r
162 notmuch_database_t *notmuch = query->notmuch;
\r
163 const char *query_string = query->query_string;
\r
164 @@ -565,30 +565,32 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
165 fprintf (stderr, "A Xapian exception occurred: %s\n",
\r
166 error.get_msg().c_str());
\r
167 fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
168 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
172 + *count_out=count;
\r
173 + return NOTMUCH_STATUS_SUCCESS;
\r
177 -notmuch_query_count_threads (notmuch_query_t *query)
\r
179 +notmuch_query_count_threads (notmuch_query_t *query, unsigned *count)
\r
181 notmuch_messages_t *messages;
\r
183 - unsigned int count;
\r
184 notmuch_sort_t sort;
\r
185 + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
187 sort = query->sort;
\r
188 query->sort = NOTMUCH_SORT_UNSORTED;
\r
189 messages = notmuch_query_search_messages (query);
\r
190 query->sort = sort;
\r
191 if (messages == NULL)
\r
193 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
195 hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
196 if (hash == NULL) {
\r
197 talloc_free (messages);
\r
199 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
202 while (notmuch_messages_valid (messages)) {
\r
203 @@ -597,7 +599,7 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
204 char *thread_id_copy = talloc_strdup (messages, thread_id);
\r
205 if (unlikely (thread_id_copy == NULL)) {
\r
206 notmuch_message_destroy (message);
\r
208 + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
211 g_hash_table_insert (hash, thread_id_copy, NULL);
\r
212 @@ -605,11 +607,11 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
213 notmuch_messages_move_to_next (messages);
\r
216 - count = g_hash_table_size (hash);
\r
217 + *count = g_hash_table_size (hash);
\r
220 g_hash_table_unref (hash);
\r
221 talloc_free (messages);
\r
226 diff --git a/notmuch-count.c b/notmuch-count.c
\r
227 index 6058f7c..7e3c1b7 100644
\r
228 --- a/notmuch-count.c
\r
229 +++ b/notmuch-count.c
\r
230 @@ -71,6 +71,8 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
232 notmuch_query_t *query;
\r
235 + notmuch_status_t status;
\r
237 query = notmuch_query_create (notmuch, query_str);
\r
238 if (query == NULL) {
\r
239 @@ -83,10 +85,18 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
242 case OUTPUT_MESSAGES:
\r
243 - printf ("%u\n", notmuch_query_count_messages (query));
\r
244 + if ((status = notmuch_query_count_messages (query, &count))) {
\r
245 + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status));
\r
248 + printf ("%u\n", count);
\r
250 case OUTPUT_THREADS:
\r
251 - printf ("%u\n", notmuch_query_count_threads (query));
\r
252 + if ((status = notmuch_query_count_threads (query, &count))) {
\r
253 + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status));
\r
256 + printf ("%u\n", count);
\r
259 printf ("%u\n", count_files (query));
\r
260 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
261 index 7c1c809..c5f1b92 100644
\r
262 --- a/notmuch-reply.c
\r
263 +++ b/notmuch-reply.c
\r
264 @@ -650,8 +650,14 @@ notmuch_reply_format_sprinter(void *ctx,
\r
265 notmuch_messages_t *messages;
\r
266 notmuch_message_t *message;
\r
269 + notmuch_status_t status;
\r
271 - if (notmuch_query_count_messages (query) != 1) {
\r
272 + if ((status = notmuch_query_count_messages (query, &count))) {
\r
273 + fprintf (stderr, "Error: %s.\n", notmuch_status_to_string (status));
\r
276 + if (count != 1) {
\r
277 fprintf (stderr, "Error: search term did not match precisely one message.\n");
\r
280 diff --git a/notmuch-search.c b/notmuch-search.c
\r
281 index 14b9f01..cadfc0c 100644
\r
282 --- a/notmuch-search.c
\r
283 +++ b/notmuch-search.c
\r
284 @@ -113,7 +113,14 @@ do_search_threads (search_context_t *ctx)
\r
287 if (ctx->offset < 0) {
\r
288 - ctx->offset += notmuch_query_count_threads (ctx->query);
\r
290 + notmuch_status_t status;
\r
291 + if ((status = notmuch_query_count_threads (ctx->query, &count))) {
\r
292 + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status));
\r
296 + ctx->offset += count;
\r
297 if (ctx->offset < 0)
\r
300 @@ -414,7 +421,10 @@ do_search_messages (search_context_t *ctx)
\r
303 if (ctx->offset < 0) {
\r
304 - ctx->offset += notmuch_query_count_messages (ctx->query);
\r
306 + if (notmuch_query_count_messages (ctx->query, &count))
\r
308 + ctx->offset += count;
\r
309 if (ctx->offset < 0)
\r
312 diff --git a/notmuch-show.c b/notmuch-show.c
\r
313 index d416fbd..16835a3 100644
\r
314 --- a/notmuch-show.c
\r
315 +++ b/notmuch-show.c
\r
316 @@ -982,8 +982,14 @@ do_show_single (void *ctx,
\r
318 notmuch_messages_t *messages;
\r
319 notmuch_message_t *message;
\r
321 + notmuch_status_t status;
\r
322 + if ((status = notmuch_query_count_messages (query, &count))) {
\r
323 + fprintf (stderr, "Error: %s\n", notmuch_status_to_string (status));
\r
327 - if (notmuch_query_count_messages (query) != 1) {
\r
328 + if (count != 1) {
\r
329 fprintf (stderr, "Error: search term did not match precisely one message.\n");
\r