1 Return-Path: <jani@nikula.org>
\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 CA0A3431FBC
\r
6 for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 05:56:53 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=1.738 tagged_above=-999 required=5
\r
12 tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7]
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id EMKrDKcGxhdA for <notmuch@notmuchmail.org>;
\r
17 Sat, 7 Mar 2015 05:56:50 -0800 (PST)
\r
18 Received: from mail-we0-f176.google.com (mail-we0-f176.google.com
\r
19 [74.125.82.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 3D9F9431FAE
\r
22 for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 05:56:50 -0800 (PST)
\r
23 Received: by wesw55 with SMTP id w55so1818361wes.2
\r
24 for <notmuch@notmuchmail.org>; Sat, 07 Mar 2015 05:56:49 -0800 (PST)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=1e100.net; s=20130820;
\r
27 h=x-gm-message-state:from:to:subject:in-reply-to:references
\r
28 :user-agent:date:message-id:mime-version:content-type;
\r
29 bh=C2OcpB5z8BzYAn05Cre1UZauYjX8OKLVmWif22t4t+8=;
\r
30 b=P12wS/D2R8i9LQWwytN6UXUTEN3xgVs3yIAM2A10gSgvh8ktXyVJdI+gH4hcjgyler
\r
31 LU2SH3WJLBWsF4iCw8N3iCNAvUSBpxCW/xtBvzIoqz4QIEqWTTKLVnGERQ40qXmvZLBF
\r
32 Nly4q6aKCyE/9plY8tsA3JVgqhqjAHShSKNTDDhlPEqAz2PLWn8UCDiBEjkvw6Me0HYd
\r
33 G6tErUfZcw3/ZTf341OqvWae71qj4g1c7hVSrJruoQzvPleQmalzCebttZfWm9H/Sj5q
\r
34 7TyxmqQTIlXCTyUdvlABkfu0L/C8Fp/TZK5RrzIQPOrf/WV6o/u9DVe2m6OAW/RnP60o
\r
37 ALoCoQmCEFAa/NMX+xO//NG/cujMCrVrotrSdfngfmNm2MbA39qmif+mprXuEZFV6AV7ZxIkBqEG
\r
38 X-Received: by 10.195.11.73 with SMTP id eg9mr38904056wjd.62.1425736609241;
\r
39 Sat, 07 Mar 2015 05:56:49 -0800 (PST)
\r
40 Received: from localhost (mobile-internet-bcee3b-76.dhcp.inet.fi.
\r
41 [188.238.59.76]) by mx.google.com with ESMTPSA id
\r
42 md2sm10644777wic.19.2015.03.07.05.56.47
\r
43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
\r
44 Sat, 07 Mar 2015 05:56:48 -0800 (PST)
\r
45 From: Jani Nikula <jani@nikula.org>
\r
46 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
\r
47 Subject: Re: [PATCH 1/4] lib: add versions of notmuch_query_count_{message,
\r
48 threads} with status return
\r
49 In-Reply-To: <1425717797-19990-2-git-send-email-david@tethera.net>
\r
50 References: <1419971380-10307-6-git-send-email-david@tethera.net>
\r
51 <1425717797-19990-1-git-send-email-david@tethera.net>
\r
52 <1425717797-19990-2-git-send-email-david@tethera.net>
\r
53 User-Agent: Notmuch/0.19+74~g6aeef2e (http://notmuchmail.org) Emacs/24.4.1
\r
54 (x86_64-pc-linux-gnu)
\r
55 Date: Sat, 07 Mar 2015 15:57:08 +0200
\r
56 Message-ID: <87vbicj4gb.fsf@nikula.org>
\r
58 Content-Type: text/plain
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Sat, 07 Mar 2015 13:56:54 -0000
\r
73 On Sat, 07 Mar 2015, David Bremner <david@tethera.net> wrote:
\r
74 > Although I think it's a pretty bad idea to continue using the old API,
\r
75 > this allows both a more gentle transition for clients of the library,
\r
76 > and allows us to break one monolithic change into a series
\r
78 We should probably bump LIBNOTMUCH_MINOR_VERSION for this.
\r
80 See nitpicks inline below, up to you if you decide if they're worthwhile
\r
81 changes, generally LGTM.
\r
84 > lib/database.cc | 8 +++++++-
\r
85 > lib/notmuch.h | 34 ++++++++++++++++++++++++++++++----
\r
86 > lib/query.cc | 36 +++++++++++++++++++++++++++++-------
\r
87 > 3 files changed, 66 insertions(+), 12 deletions(-)
\r
89 > diff --git a/lib/database.cc b/lib/database.cc
\r
90 > index 3974e2e..d92eec0 100644
\r
91 > --- a/lib/database.cc
\r
92 > +++ b/lib/database.cc
\r
93 > @@ -1275,7 +1275,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
94 > if (new_features &
\r
95 > (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {
\r
96 > notmuch_query_t *query = notmuch_query_create (notmuch, "");
\r
97 > - total += notmuch_query_count_messages (query);
\r
98 > + unsigned msg_count;
\r
100 Personal preference, I always want to specify "unsigned int" instead of
\r
101 just "unsigned". Same all around patches 1 and 2.
\r
104 > + status = notmuch_query_count_messages_st (query, &msg_count);
\r
108 > + total += msg_count;
\r
109 > notmuch_query_destroy (query);
\r
111 > if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
\r
112 > diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
113 > index 3e326bf..a0fc276 100644
\r
114 > --- a/lib/notmuch.h
\r
115 > +++ b/lib/notmuch.h
\r
116 > @@ -914,12 +914,23 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
\r
117 > * This function performs a search and returns Xapian's best
\r
118 > * guess as to number of matching messages.
\r
120 > - * If a Xapian exception occurs, this function may return 0 (after
\r
121 > - * printing a message).
\r
122 > + * The version returning the count directly instead of a status value
\r
123 > + * is deprecated.
\r
125 > + * Return value (of the _st) version:
\r
127 > + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
\r
129 > + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
\r
130 > + * value of *count is not defined.
\r
133 I'd really like to have separate doc comments for both the
\r
134 functions. The original and now deprecated version can be be a brief
\r
135 one, with a reference to the _st version documentation. If you move the
\r
136 _st version declaration here, above the original declaration, the diff
\r
137 should remain small.
\r
139 Perhaps reference the library version number when this was added?
\r
143 > notmuch_query_count_messages (notmuch_query_t *query);
\r
145 > +notmuch_status_t
\r
146 > +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);
\r
149 > * Return the number of threads matching a search.
\r
151 > @@ -928,13 +939,28 @@ notmuch_query_count_messages (notmuch_query_t *query);
\r
154 > * Note that this is a significantly heavier operation than
\r
155 > - * notmuch_query_count_messages().
\r
156 > + * notmuch_query_count_messages{_st}().
\r
158 > + * The version returning the count directly instead of a status value
\r
159 > + * is deprecated.
\r
161 > - * If an error occurs, this function may return 0.
\r
162 > + * Return values (of the _st version):
\r
164 > + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
\r
165 > + * of *count is not defined
\r
167 > + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
\r
169 > + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
\r
170 > + * value of *count is not defined.
\r
177 > notmuch_query_count_threads (notmuch_query_t *query);
\r
179 > +notmuch_status_t
\r
180 > +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
\r
183 > * Get the thread ID of 'thread'.
\r
185 > diff --git a/lib/query.cc b/lib/query.cc
\r
186 > index 9279915..883d128 100644
\r
187 > --- a/lib/query.cc
\r
188 > +++ b/lib/query.cc
\r
189 > @@ -541,6 +541,16 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
\r
191 > notmuch_query_count_messages (notmuch_query_t *query)
\r
193 > + notmuch_status_t status;
\r
194 > + unsigned count;
\r
196 > + status = notmuch_query_count_messages_st (query, &count);
\r
197 > + return status ? 0 : count;
\r
200 > +notmuch_status_t
\r
201 > +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)
\r
203 > notmuch_database_t *notmuch = query->notmuch;
\r
204 > const char *query_string = query->query_string;
\r
205 > Xapian::doccount count = 0;
\r
206 > @@ -595,30 +605,42 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
207 > fprintf (stderr, "A Xapian exception occurred: %s\n",
\r
208 > error.get_msg().c_str());
\r
209 > fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
210 > + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
214 > + *count_out=count;
\r
218 > + return NOTMUCH_STATUS_SUCCESS;
\r
222 > notmuch_query_count_threads (notmuch_query_t *query)
\r
224 > + notmuch_status_t status;
\r
225 > + unsigned count;
\r
227 > + status = notmuch_query_count_threads_st (query, &count);
\r
228 > + return status ? 0 : count;
\r
231 > +notmuch_status_t
\r
232 > +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)
\r
234 > notmuch_messages_t *messages;
\r
235 > GHashTable *hash;
\r
236 > - unsigned int count;
\r
237 > notmuch_sort_t sort;
\r
238 > + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
240 > sort = query->sort;
\r
241 > query->sort = NOTMUCH_SORT_UNSORTED;
\r
242 > messages = notmuch_query_search_messages (query);
\r
243 > query->sort = sort;
\r
244 > if (messages == NULL)
\r
246 > + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
248 > hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
249 > if (hash == NULL) {
\r
250 > talloc_free (messages);
\r
252 > + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
255 > while (notmuch_messages_valid (messages)) {
\r
256 > @@ -627,7 +649,7 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
257 > char *thread_id_copy = talloc_strdup (messages, thread_id);
\r
258 > if (unlikely (thread_id_copy == NULL)) {
\r
259 > notmuch_message_destroy (message);
\r
261 > + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
264 > g_hash_table_insert (hash, thread_id_copy, NULL);
\r
265 > @@ -635,11 +657,11 @@ notmuch_query_count_threads (notmuch_query_t *query)
\r
266 > notmuch_messages_move_to_next (messages);
\r
269 > - count = g_hash_table_size (hash);
\r
270 > + *count = g_hash_table_size (hash);
\r
273 > g_hash_table_unref (hash);
\r
274 > talloc_free (messages);
\r
282 > _______________________________________________
\r
283 > notmuch mailing list
\r
284 > notmuch@notmuchmail.org
\r
285 > http://notmuchmail.org/mailman/listinfo/notmuch
\r