Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / d1 / 56c8c8612e5c1b6e650d72bba2db540c1b805c
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 2.438\r
10 X-Spam-Level: **\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
18         [87.98.215.224])\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
27         08:43:23 -0000\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
40 Precedence: list\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
51 \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
55 ---\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
60 \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
66      if (new_features &\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
71 +\r
72 +       status = notmuch_query_count_messages_st (query, &msg_count);\r
73 +       if (status)\r
74 +           goto DONE;\r
75 +\r
76 +       total += msg_count;\r
77         notmuch_query_destroy (query);\r
78      }\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
82 --- a/lib/notmuch.h\r
83 +++ b/lib/notmuch.h\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
87   *\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
91 + * is deprecated.\r
92 + *\r
93 + * Return value (of the _st) version:\r
94 + *\r
95 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
96 + *\r
97 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
98 + *      value of *count is not defined.\r
99   */\r
100 +\r
101  unsigned\r
102  notmuch_query_count_messages (notmuch_query_t *query);\r
103  \r
104 +notmuch_status_t\r
105 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
106 +\r
107  /**\r
108   * Return the number of threads matching a search.\r
109   *\r
110 @@ -928,13 +939,28 @@ notmuch_query_count_messages (notmuch_query_t *query);\r
111   * search.\r
112   *\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
116 + *\r
117 + * The version returning the count directly instead of a status value \r
118 + * is deprecated.\r
119   *\r
120 - * If an error occurs, this function may return 0.\r
121 + * Return values (of the _st version):\r
122 + *\r
123 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value\r
124 + *      of *count is not defined\r
125 +\r
126 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
127 + *\r
128 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
129 + *      value of *count is not defined.\r
130   */\r
131 +\r
132  unsigned\r
133  notmuch_query_count_threads (notmuch_query_t *query);\r
134  \r
135 +notmuch_status_t\r
136 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
137 +\r
138  /**\r
139   * Get the thread ID of 'thread'.\r
140   *\r
141 diff --git a/lib/query.cc b/lib/query.cc\r
142 index 9279915..883d128 100644\r
143 --- a/lib/query.cc\r
144 +++ b/lib/query.cc\r
145 @@ -541,6 +541,16 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
146  unsigned\r
147  notmuch_query_count_messages (notmuch_query_t *query)\r
148  {\r
149 +    notmuch_status_t status;\r
150 +    unsigned count;\r
151 +\r
152 +    status = notmuch_query_count_messages_st (query, &count);\r
153 +    return status ? 0 : count;\r
154 +}\r
155 +\r
156 +notmuch_status_t\r
157 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
158 +{\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
167      }\r
168  \r
169 -    return count;\r
170 +    *count_out=count;\r
171 +    return NOTMUCH_STATUS_SUCCESS;\r
172  }\r
173  \r
174  unsigned\r
175  notmuch_query_count_threads (notmuch_query_t *query)\r
176  {\r
177 +    notmuch_status_t status;\r
178 +    unsigned count;\r
179 +\r
180 +    status = notmuch_query_count_threads_st (query, &count);\r
181 +    return status ? 0 : count;\r
182 +}\r
183 +    \r
184 +notmuch_status_t\r
185 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)\r
186 +{\r
187      notmuch_messages_t *messages;\r
188      GHashTable *hash;\r
189 -    unsigned int count;\r
190      notmuch_sort_t sort;\r
191 +    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
192  \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
198 -       return 0;\r
199 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
200  \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
204 -       return 0;\r
205 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
206      }\r
207  \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
213 -           count = 0;\r
214 +           ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
215             goto DONE;\r
216         }\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
220      }\r
221  \r
222 -    count = g_hash_table_size (hash);\r
223 +    *count = g_hash_table_size (hash);\r
224  \r
225    DONE:\r
226      g_hash_table_unref (hash);\r
227      talloc_free (messages);\r
228  \r
229 -    return count;\r
230 +    return ret;\r
231  }\r
232 -- \r
233 2.1.4\r
234 \r