Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / a6 / 476cecded14fc6c8e0775e4c45d075fc292b7d
1 Return-Path: <bremner@tethera.net>\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 arlo.cworth.org (Postfix) with ESMTP id A270B6DE17A0\r
6  for <notmuch@notmuchmail.org>; Sat, 26 Sep 2015 19:52:26 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.112\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.112 tagged_above=-999 required=5 tests=[AWL=0.112]\r
12  autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id ZESmrcOZUuwY for <notmuch@notmuchmail.org>;\r
16  Sat, 26 Sep 2015 19:52:24 -0700 (PDT)\r
17 Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
18  by arlo.cworth.org (Postfix) with ESMTPS id AF4AE6DE176C\r
19  for <notmuch@notmuchmail.org>; Sat, 26 Sep 2015 19:52:24 -0700 (PDT)\r
20 Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
21  (envelope-from <bremner@tethera.net>)\r
22  id 1Zg23y-0005bi-Of; Sun, 27 Sep 2015 02:51:42 +0000\r
23 Received: (nullmailer pid 31135 invoked by uid 1000); Sun, 27 Sep 2015\r
24  02:50:26 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [Patch v3 2/4] lib: add versions of n_q_count_{message, threads} with\r
28  status return\r
29 Date: Sat, 26 Sep 2015 23:50:11 -0300\r
30 Message-Id: <1443322213-31075-3-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.5.3\r
32 In-Reply-To: <1443322213-31075-1-git-send-email-david@tethera.net>\r
33 References: <1443322213-31075-1-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.18\r
36 Precedence: list\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: Sun, 27 Sep 2015 02:52:26 -0000\r
47 \r
48 Although I think it's a pretty bad idea to continue using the old API,\r
49 this allows both a more gentle transition for clients of the library,\r
50 and allows us to break one monolithic change into a series\r
51 ---\r
52  lib/database.cc |  8 +++++++-\r
53  lib/notmuch.h   | 52 ++++++++++++++++++++++++++++++++++++++++++++++------\r
54  lib/query.cc    | 47 +++++++++++++++++++++++++++++++++--------------\r
55  3 files changed, 86 insertions(+), 21 deletions(-)\r
56 \r
57 diff --git a/lib/database.cc b/lib/database.cc\r
58 index 6d0e5a6..cf93533 100644\r
59 --- a/lib/database.cc\r
60 +++ b/lib/database.cc\r
61 @@ -1409,7 +1409,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
62         (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |\r
63          NOTMUCH_FEATURE_LAST_MOD)) {\r
64         notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
65 -       total += notmuch_query_count_messages (query);\r
66 +       unsigned msg_count;\r
67 +\r
68 +       status = notmuch_query_count_messages_st (query, &msg_count);\r
69 +       if (status)\r
70 +           goto DONE;\r
71 +\r
72 +       total += msg_count;\r
73         notmuch_query_destroy (query);\r
74      }\r
75      if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
76 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
77 index 8775683..5832f89 100644\r
78 --- a/lib/notmuch.h\r
79 +++ b/lib/notmuch.h\r
80 @@ -984,12 +984,31 @@ notmuch_threads_destroy (notmuch_threads_t *threads);\r
81   * This function performs a search and returns the number of matching\r
82   * messages.\r
83   *\r
84 - * If a Xapian exception occurs, this function may return 0 (after\r
85 - * printing a message).\r
86 + * @returns\r
87 + *\r
88 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
89 + *\r
90 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
91 + *      value of *count is not defined.\r
92   */\r
93 -unsigned\r
94 +notmuch_status_t\r
95 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
96 +\r
97 +/**\r
98 + * like notmuch_query_count_messages_st, but without a status return\r
99 + *\r
100 + * May return 0 in the case of errors.\r
101 + *\r
102 + * @deprecated Deprecated since libnotmuch 4.3 (notmuch 0.21). Please\r
103 + * use notmuch_query_count_messages_st instead.\r
104 + */\r
105 +NOTMUCH_DEPRECATED(4,3)\r
106 +unsigned int\r
107  notmuch_query_count_messages (notmuch_query_t *query);\r
108  \r
109 +\r
110 +\r
111 +\r
112  /**\r
113   * Return the number of threads matching a search.\r
114   *\r
115 @@ -998,13 +1017,34 @@ notmuch_query_count_messages (notmuch_query_t *query);\r
116   * search.\r
117   *\r
118   * Note that this is a significantly heavier operation than\r
119 - * notmuch_query_count_messages().\r
120 + * notmuch_query_count_messages{_st}().\r
121   *\r
122 - * If an error occurs, this function may return 0.\r
123 + * @returns\r
124 + *\r
125 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value\r
126 + *      of *count is not defined\r
127 +\r
128 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
129 + *\r
130 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
131 + *      value of *count is not defined.\r
132   */\r
133 -unsigned\r
134 +notmuch_status_t\r
135 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
136 +\r
137 +/**\r
138 + * like notmuch_query_count_threads, but without a status return.\r
139 + *\r
140 + * May return 0 in case of errors.\r
141 + *\r
142 + * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please\r
143 + * use notmuch_query_count_threads_st instead.\r
144 + */\r
145 +NOTMUCH_DEPRECATED(4,3)\r
146 +unsigned int\r
147  notmuch_query_count_threads (notmuch_query_t *query);\r
148  \r
149 +\r
150  /**\r
151   * Get the thread ID of 'thread'.\r
152   *\r
153 diff --git a/lib/query.cc b/lib/query.cc\r
154 index 8cf0a07..8419b2e 100644\r
155 --- a/lib/query.cc\r
156 +++ b/lib/query.cc\r
157 @@ -541,9 +541,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
158      talloc_free (threads);\r
159  }\r
160  \r
161 -unsigned\r
162 +unsigned int\r
163  notmuch_query_count_messages (notmuch_query_t *query)\r
164  {\r
165 +    notmuch_status_t status;\r
166 +    unsigned int count;\r
167 +\r
168 +    status = notmuch_query_count_messages_st (query, &count);\r
169 +    return status ? 0 : count;\r
170 +}\r
171 +\r
172 +notmuch_status_t\r
173 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
174 +{\r
175      notmuch_database_t *notmuch = query->notmuch;\r
176      const char *query_string = query->query_string;\r
177      Xapian::doccount count = 0;\r
178 @@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
179                                "Query string was: %s\n",\r
180                                error.get_msg().c_str(),\r
181                                query->query_string);\r
182 -\r
183 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
184      }\r
185  \r
186 -    return count;\r
187 +    *count_out = count;\r
188 +    return NOTMUCH_STATUS_SUCCESS;\r
189  }\r
190  \r
191  unsigned\r
192  notmuch_query_count_threads (notmuch_query_t *query)\r
193  {\r
194 +    notmuch_status_t status;\r
195 +    unsigned int count;\r
196 +\r
197 +    status = notmuch_query_count_threads_st (query, &count);\r
198 +    return status ? 0 : count;\r
199 +}\r
200 +    \r
201 +notmuch_status_t\r
202 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)\r
203 +{\r
204      notmuch_messages_t *messages;\r
205      GHashTable *hash;\r
206 -    unsigned int count;\r
207      notmuch_sort_t sort;\r
208 -    notmuch_status_t status;\r
209 +    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
210  \r
211      sort = query->sort;\r
212      query->sort = NOTMUCH_SORT_UNSORTED;\r
213 -    status = notmuch_query_search_messages_st (query, &messages);\r
214 -    if (status)\r
215 -       return 0;\r
216 -\r
217 +    ret = notmuch_query_search_messages_st (query, &messages);\r
218 +    if (ret)\r
219 +       return ret;\r
220      query->sort = sort;\r
221      if (messages == NULL)\r
222 -       return 0;\r
223 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
224  \r
225      hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
226      if (hash == NULL) {\r
227         talloc_free (messages);\r
228 -       return 0;\r
229 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
230      }\r
231  \r
232      while (notmuch_messages_valid (messages)) {\r
233 @@ -642,7 +661,7 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
234         char *thread_id_copy = talloc_strdup (messages, thread_id);\r
235         if (unlikely (thread_id_copy == NULL)) {\r
236             notmuch_message_destroy (message);\r
237 -           count = 0;\r
238 +           ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
239             goto DONE;\r
240         }\r
241         g_hash_table_insert (hash, thread_id_copy, NULL);\r
242 @@ -650,13 +669,13 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
243         notmuch_messages_move_to_next (messages);\r
244      }\r
245  \r
246 -    count = g_hash_table_size (hash);\r
247 +    *count = g_hash_table_size (hash);\r
248  \r
249    DONE:\r
250      g_hash_table_unref (hash);\r
251      talloc_free (messages);\r
252  \r
253 -    return count;\r
254 +    return ret;\r
255  }\r
256  \r
257  notmuch_database_t *\r
258 -- \r
259 2.5.3\r
260 \r