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 191B6431FBC
\r
6 for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 11:24:25 -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 lJnqICRGaIxG for <notmuch@notmuchmail.org>;
\r
16 Sat, 7 Mar 2015 11:24:22 -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 0D5C0431FAE
\r
22 for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 11:24:22 -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 1YUKK4-0004DC-8O; Sat, 07 Mar 2015 19:23:40 +0000
\r
26 Received: (nullmailer pid 28727 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 4/5] lib: add versions of
\r
31 notmuch_query_count_{message,threads} with status return
\r
32 Date: Sat, 7 Mar 2015 20:23:01 +0100
\r
33 Message-Id: <1425756182-28468-5-git-send-email-david@tethera.net>
\r
34 X-Mailer: git-send-email 2.1.4
\r
35 In-Reply-To: <1425756182-28468-1-git-send-email-david@tethera.net>
\r
36 References: <1425756182-28468-1-git-send-email-david@tethera.net>
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Sat, 07 Mar 2015 19:24:25 -0000
\r
51 Although I think it's a pretty bad idea to continue using the old API,
\r
52 this allows both a more gentle transition for clients of the library,
\r
53 and allows us to break one monolithic change into a series
\r
55 lib/database.cc | 8 +++++++-
\r
56 lib/notmuch.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
\r
57 lib/query.cc | 38 ++++++++++++++++++++++++++++++--------
\r
58 3 files changed, 83 insertions(+), 15 deletions(-)
\r
60 diff --git a/lib/database.cc b/lib/database.cc
\r
61 index 8680963..b8fb7f7 100644
\r
62 --- a/lib/database.cc
\r
63 +++ b/lib/database.cc
\r
64 @@ -1275,7 +1275,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
66 (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {
\r
67 notmuch_query_t *query = notmuch_query_create (notmuch, "");
\r
68 - total += notmuch_query_count_messages (query);
\r
69 + unsigned msg_count;
\r
71 + status = notmuch_query_count_messages_st (query, &msg_count);
\r
75 + total += msg_count;
\r
76 notmuch_query_destroy (query);
\r
78 if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
\r
79 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
80 index 087f3f0..2acfbb5 100644
\r
83 @@ -927,12 +927,31 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
\r
84 * This function performs a search and returns Xapian's best
\r
85 * guess as to number of matching messages.
\r
87 - * If a Xapian exception occurs, this function may return 0 (after
\r
88 - * printing a message).
\r
91 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
\r
93 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
\r
94 + * value of *count is not defined.
\r
98 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);
\r
101 + * like notmuch_query_count_messages_st, but without a status return
\r
103 + * May return 0 in the case of errors.
\r
105 + * @deprecated Deprecated since libnotmuch 4.2 (notmuch 0.20). Please
\r
106 + * use notmuch_query_count_messages_st instead.
\r
108 +NOTMUCH_DEPRECATED(4,2)
\r
110 notmuch_query_count_messages (notmuch_query_t *query);
\r
116 * Return the number of threads matching a search.
\r
118 @@ -941,13 +960,34 @@ notmuch_query_count_messages (notmuch_query_t *query);
\r
121 * Note that this is a significantly heavier operation than
\r
122 - * notmuch_query_count_messages().
\r
123 + * notmuch_query_count_messages{_st}().
\r
125 - * If an error occurs, this function may return 0.
\r
128 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
\r
129 + * of *count is not defined
\r
131 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
\r
133 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
\r
134 + * value of *count is not defined.
\r
138 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
\r
141 + * like notmuch_query_count_threads, but without a status return.
\r
143 + * May return 0 in case of errors.
\r
145 + * @deprecated Deprecated as of libnotmuch 4.2 (notmuch 0.20). Please
\r
146 + * use notmuch_query_count_threads_st instead.
\r
148 +NOTMUCH_DEPRECATED(4,2)
\r
150 notmuch_query_count_threads (notmuch_query_t *query);
\r
154 * Get the thread ID of 'thread'.
\r
156 diff --git a/lib/query.cc b/lib/query.cc
\r
157 index 1871a81..984f577 100644
\r
160 @@ -538,9 +538,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
\r
161 talloc_free (threads);
\r
166 notmuch_query_count_messages (notmuch_query_t *query)
\r
168 + notmuch_status_t status;
\r
169 + unsigned int count;
\r
171 + status = notmuch_query_count_messages_st (query, &count);
\r
172 + return status ? 0 : count;
\r
176 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)
\r
178 notmuch_database_t *notmuch = query->notmuch;
\r
179 const char *query_string = query->query_string;
\r
180 Xapian::doccount count = 0;
\r
181 @@ -595,18 +605,30 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
182 fprintf (stderr, "A Xapian exception occurred: %s\n",
\r
183 error.get_msg().c_str());
\r
184 fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
185 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
189 + *count_out = count;
\r
190 + return NOTMUCH_STATUS_SUCCESS;
\r
194 notmuch_query_count_threads (notmuch_query_t *query)
\r
196 + notmuch_status_t status;
\r
197 + unsigned int count;
\r
199 + status = notmuch_query_count_threads_st (query, &count);
\r
200 + return status ? 0 : count;
\r
204 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)
\r
206 notmuch_messages_t *messages;
\r
208 - unsigned int count;
\r
209 notmuch_sort_t sort;
\r
210 + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
212 sort = query->sort;
\r
213 query->sort = NOTMUCH_SORT_UNSORTED;
\r
214 @@ -615,12 +637,12 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
216 query->sort = sort;
\r
217 if (messages == NULL)
\r
219 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
221 hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
222 if (hash == NULL) {
\r
223 talloc_free (messages);
\r
225 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
228 while (notmuch_messages_valid (messages)) {
\r
229 @@ -629,7 +651,7 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
230 char *thread_id_copy = talloc_strdup (messages, thread_id);
\r
231 if (unlikely (thread_id_copy == NULL)) {
\r
232 notmuch_message_destroy (message);
\r
234 + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
237 g_hash_table_insert (hash, thread_id_copy, NULL);
\r
238 @@ -637,11 +659,11 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
239 notmuch_messages_move_to_next (messages);
\r
242 - count = g_hash_table_size (hash);
\r
243 + *count = g_hash_table_size (hash);
\r
246 g_hash_table_unref (hash);
\r
247 talloc_free (messages);
\r