Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f6 / 88008a598b1485618f9df9960a81b7697fd94c
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
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 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
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 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
27         19:23:13 -0000\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
39 Precedence: list\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
50 \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
54 ---\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
59 \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
65      if (new_features &\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
70 +\r
71 +       status = notmuch_query_count_messages_st (query, &msg_count);\r
72 +       if (status)\r
73 +           goto DONE;\r
74 +\r
75 +       total += msg_count;\r
76         notmuch_query_destroy (query);\r
77      }\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
81 --- a/lib/notmuch.h\r
82 +++ b/lib/notmuch.h\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
86   *\r
87 - * If a Xapian exception occurs, this function may return 0 (after\r
88 - * printing a message).\r
89 + * @returns\r
90 + *\r
91 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
92 + *\r
93 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
94 + *      value of *count is not defined.\r
95   */\r
96 -unsigned\r
97 +notmuch_status_t\r
98 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
99 +\r
100 +/**\r
101 + * like notmuch_query_count_messages_st, but without a status return\r
102 + *\r
103 + * May return 0 in the case of errors.\r
104 + *\r
105 + * @deprecated Deprecated since libnotmuch 4.2 (notmuch 0.20). Please\r
106 + * use notmuch_query_count_messages_st instead.\r
107 + */\r
108 +NOTMUCH_DEPRECATED(4,2)\r
109 +unsigned int\r
110  notmuch_query_count_messages (notmuch_query_t *query);\r
111  \r
112 +\r
113 +\r
114 +\r
115  /**\r
116   * Return the number of threads matching a search.\r
117   *\r
118 @@ -941,13 +960,34 @@ notmuch_query_count_messages (notmuch_query_t *query);\r
119   * search.\r
120   *\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
124   *\r
125 - * If an error occurs, this function may return 0.\r
126 + * @returns\r
127 + *\r
128 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value\r
129 + *      of *count is not defined\r
130 +\r
131 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
132 + *\r
133 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
134 + *      value of *count is not defined.\r
135   */\r
136 -unsigned\r
137 +notmuch_status_t\r
138 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
139 +\r
140 +/**\r
141 + * like notmuch_query_count_threads, but without a status return.\r
142 + *\r
143 + * May return 0 in case of errors.\r
144 + *\r
145 + * @deprecated Deprecated as of libnotmuch 4.2 (notmuch 0.20). Please\r
146 + * use notmuch_query_count_threads_st instead.\r
147 + */\r
148 +NOTMUCH_DEPRECATED(4,2)\r
149 +unsigned int\r
150  notmuch_query_count_threads (notmuch_query_t *query);\r
151  \r
152 +\r
153  /**\r
154   * Get the thread ID of 'thread'.\r
155   *\r
156 diff --git a/lib/query.cc b/lib/query.cc\r
157 index 1871a81..984f577 100644\r
158 --- a/lib/query.cc\r
159 +++ b/lib/query.cc\r
160 @@ -538,9 +538,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
161      talloc_free (threads);\r
162  }\r
163  \r
164 -unsigned\r
165 +unsigned int\r
166  notmuch_query_count_messages (notmuch_query_t *query)\r
167  {\r
168 +    notmuch_status_t status;\r
169 +    unsigned int count;\r
170 +\r
171 +    status = notmuch_query_count_messages_st (query, &count);\r
172 +    return status ? 0 : count;\r
173 +}\r
174 +\r
175 +notmuch_status_t\r
176 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
177 +{\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
186      }\r
187  \r
188 -    return count;\r
189 +    *count_out = count;\r
190 +    return NOTMUCH_STATUS_SUCCESS;\r
191  }\r
192  \r
193  unsigned\r
194  notmuch_query_count_threads (notmuch_query_t *query)\r
195  {\r
196 +    notmuch_status_t status;\r
197 +    unsigned int count;\r
198 +\r
199 +    status = notmuch_query_count_threads_st (query, &count);\r
200 +    return status ? 0 : count;\r
201 +}\r
202 +    \r
203 +notmuch_status_t\r
204 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)\r
205 +{\r
206      notmuch_messages_t *messages;\r
207      GHashTable *hash;\r
208 -    unsigned int count;\r
209      notmuch_sort_t sort;\r
210 +    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
211  \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
215         return ret;\r
216      query->sort = sort;\r
217      if (messages == NULL)\r
218 -       return 0;\r
219 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
220  \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
224 -       return 0;\r
225 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
226      }\r
227  \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
233 -           count = 0;\r
234 +           ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
235             goto DONE;\r
236         }\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
240      }\r
241  \r
242 -    count = g_hash_table_size (hash);\r
243 +    *count = g_hash_table_size (hash);\r
244  \r
245    DONE:\r
246      g_hash_table_unref (hash);\r
247      talloc_free (messages);\r
248  \r
249 -    return count;\r
250 +    return ret;\r
251  }\r
252 -- \r
253 2.1.4\r
254 \r