Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 0e / 7f9dfbde64bac80f8c6dad3f528933c8e595d6
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 6F3BB6DE1003\r
6  for <notmuch@notmuchmail.org>; Sun, 27 Sep 2015 08:34:10 -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.109\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.109 tagged_above=-999 required=5 tests=[AWL=0.109]\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 jpQMOoaQtPjT for <notmuch@notmuchmail.org>;\r
16  Sun, 27 Sep 2015 08:34:08 -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 771606DE1413\r
19  for <notmuch@notmuchmail.org>; Sun, 27 Sep 2015 08:34:08 -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 1ZgDx8-0008Ec-SU; Sun, 27 Sep 2015 15:33:26 +0000\r
23 Received: (nullmailer pid 11933 invoked by uid 1000); Sun, 27 Sep 2015\r
24  15:32:11 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [Patch v4 3/9] lib: add versions of n_q_count_{message, threads} with\r
28  status return\r
29 Date: Sun, 27 Sep 2015 12:31:57 -0300\r
30 Message-Id: <1443367923-11867-4-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.5.3\r
32 In-Reply-To: <1443367923-11867-1-git-send-email-david@tethera.net>\r
33 References: <1443367923-11867-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 15:34:10 -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 | 13 ++++++++++++-\r
53  lib/notmuch.h   | 48 ++++++++++++++++++++++++++++++++++++++++++------\r
54  lib/query.cc    | 47 +++++++++++++++++++++++++++++++++--------------\r
55  3 files changed, 87 insertions(+), 21 deletions(-)\r
56 \r
57 diff --git a/lib/database.cc b/lib/database.cc\r
58 index dcfad8c..f39d448 100644\r
59 --- a/lib/database.cc\r
60 +++ b/lib/database.cc\r
61 @@ -1410,8 +1410,15 @@ 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         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 +       query = NULL;\r
75      }\r
76      if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
77         t_end = db->allterms_end ("XTIMESTAMP");\r
78 @@ -1492,6 +1499,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
79         }\r
80  \r
81         notmuch_query_destroy (query);\r
82 +       query = NULL;\r
83      }\r
84  \r
85      /* Perform per-directory upgrades. */\r
86 @@ -1612,6 +1620,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
87         sigaction (SIGALRM, &action, NULL);\r
88      }\r
89  \r
90 +    if (query)\r
91 +       notmuch_query_destroy (query);\r
92 +\r
93      talloc_free (local);\r
94      return status;\r
95  }\r
96 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
97 index 8775683..2fb778b 100644\r
98 --- a/lib/notmuch.h\r
99 +++ b/lib/notmuch.h\r
100 @@ -984,10 +984,26 @@ notmuch_threads_destroy (notmuch_threads_t *threads);\r
101   * This function performs a search and returns the number of matching\r
102   * messages.\r
103   *\r
104 - * If a Xapian exception occurs, this function may return 0 (after\r
105 - * printing a message).\r
106 + * @returns\r
107 + *\r
108 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
109 + *\r
110 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
111 + *      value of *count is not defined.\r
112   */\r
113 -unsigned\r
114 +notmuch_status_t\r
115 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
116 +\r
117 +/**\r
118 + * like notmuch_query_count_messages_st, but without a status return\r
119 + *\r
120 + * May return 0 in the case of errors.\r
121 + *\r
122 + * @deprecated Deprecated since libnotmuch 4.3 (notmuch 0.21). Please\r
123 + * use notmuch_query_count_messages_st instead.\r
124 + */\r
125 +NOTMUCH_DEPRECATED(4,3)\r
126 +unsigned int\r
127  notmuch_query_count_messages (notmuch_query_t *query);\r
128  \r
129  /**\r
130 @@ -998,11 +1014,31 @@ notmuch_query_count_messages (notmuch_query_t *query);\r
131   * search.\r
132   *\r
133   * Note that this is a significantly heavier operation than\r
134 - * notmuch_query_count_messages().\r
135 + * notmuch_query_count_messages{_st}().\r
136 + *\r
137 + * @returns\r
138   *\r
139 - * If an error occurs, this function may return 0.\r
140 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value\r
141 + *      of *count is not defined\r
142 +\r
143 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
144 + *\r
145 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
146 + *      value of *count is not defined.\r
147   */\r
148 -unsigned\r
149 +notmuch_status_t\r
150 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
151 +\r
152 +/**\r
153 + * like notmuch_query_count_threads, but without a status return.\r
154 + *\r
155 + * May return 0 in case of errors.\r
156 + *\r
157 + * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please\r
158 + * use notmuch_query_count_threads_st instead.\r
159 + */\r
160 +NOTMUCH_DEPRECATED(4,3)\r
161 +unsigned int\r
162  notmuch_query_count_threads (notmuch_query_t *query);\r
163  \r
164  /**\r
165 diff --git a/lib/query.cc b/lib/query.cc\r
166 index 8cf0a07..e627bfc 100644\r
167 --- a/lib/query.cc\r
168 +++ b/lib/query.cc\r
169 @@ -541,9 +541,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
170      talloc_free (threads);\r
171  }\r
172  \r
173 -unsigned\r
174 +unsigned int\r
175  notmuch_query_count_messages (notmuch_query_t *query)\r
176  {\r
177 +    notmuch_status_t status;\r
178 +    unsigned int count;\r
179 +\r
180 +    status = notmuch_query_count_messages_st (query, &count);\r
181 +    return status ? 0 : count;\r
182 +}\r
183 +\r
184 +notmuch_status_t\r
185 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
186 +{\r
187      notmuch_database_t *notmuch = query->notmuch;\r
188      const char *query_string = query->query_string;\r
189      Xapian::doccount count = 0;\r
190 @@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
191                                "Query string was: %s\n",\r
192                                error.get_msg().c_str(),\r
193                                query->query_string);\r
194 -\r
195 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
196      }\r
197  \r
198 -    return count;\r
199 +    *count_out = count;\r
200 +    return NOTMUCH_STATUS_SUCCESS;\r
201  }\r
202  \r
203  unsigned\r
204  notmuch_query_count_threads (notmuch_query_t *query)\r
205  {\r
206 +    notmuch_status_t status;\r
207 +    unsigned int count;\r
208 +\r
209 +    status = notmuch_query_count_threads_st (query, &count);\r
210 +    return status ? 0 : count;\r
211 +}\r
212 +\r
213 +notmuch_status_t\r
214 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)\r
215 +{\r
216      notmuch_messages_t *messages;\r
217      GHashTable *hash;\r
218 -    unsigned int count;\r
219      notmuch_sort_t sort;\r
220 -    notmuch_status_t status;\r
221 +    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
222  \r
223      sort = query->sort;\r
224      query->sort = NOTMUCH_SORT_UNSORTED;\r
225 -    status = notmuch_query_search_messages_st (query, &messages);\r
226 -    if (status)\r
227 -       return 0;\r
228 -\r
229 +    ret = notmuch_query_search_messages_st (query, &messages);\r
230 +    if (ret)\r
231 +       return ret;\r
232      query->sort = sort;\r
233      if (messages == NULL)\r
234 -       return 0;\r
235 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
236  \r
237      hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
238      if (hash == NULL) {\r
239         talloc_free (messages);\r
240 -       return 0;\r
241 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
242      }\r
243  \r
244      while (notmuch_messages_valid (messages)) {\r
245 @@ -642,7 +661,7 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
246         char *thread_id_copy = talloc_strdup (messages, thread_id);\r
247         if (unlikely (thread_id_copy == NULL)) {\r
248             notmuch_message_destroy (message);\r
249 -           count = 0;\r
250 +           ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
251             goto DONE;\r
252         }\r
253         g_hash_table_insert (hash, thread_id_copy, NULL);\r
254 @@ -650,13 +669,13 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
255         notmuch_messages_move_to_next (messages);\r
256      }\r
257  \r
258 -    count = g_hash_table_size (hash);\r
259 +    *count = g_hash_table_size (hash);\r
260  \r
261    DONE:\r
262      g_hash_table_unref (hash);\r
263      talloc_free (messages);\r
264  \r
265 -    return count;\r
266 +    return ret;\r
267  }\r
268  \r
269  notmuch_database_t *\r
270 -- \r
271 2.5.3\r
272 \r