Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 99 / 082673ed8e3083bf25e49020ee4ced1c60f08a
1 Return-Path: <amthrax@drake.mit.edu>\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 D73F7429E3F\r
6         for <notmuch@notmuchmail.org>; Mon, 30 Apr 2012 09:25:46 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 gfkNyQd+7Zcj for <notmuch@notmuchmail.org>;\r
16         Mon, 30 Apr 2012 09:25:44 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
18         [18.9.25.13])\r
19         by olra.theworths.org (Postfix) with ESMTP id 8DBE2431FAE\r
20         for <notmuch@notmuchmail.org>; Mon, 30 Apr 2012 09:25:44 -0700 (PDT)\r
21 X-AuditID: 1209190d-b7fbf6d0000008ba-d8-4f9ebd08a8e4\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id F7.17.02234.80DBE9F4; Mon, 30 Apr 2012 12:25:44 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q3UGPhkr029834; \r
27         Mon, 30 Apr 2012 12:25:43 -0400\r
28 Received: from drake.mit.edu\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3UGPgf9005255\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Mon, 30 Apr 2012 12:25:43 -0400 (EDT)\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
36         (envelope-from <amthrax@drake.mit.edu>)\r
37         id 1SOtPx-0006H4-Dw; Mon, 30 Apr 2012 12:25:41 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v2 1/6] lib/cli: Make notmuch_database_open return a status\r
41         code\r
42 Date: Mon, 30 Apr 2012 12:25:33 -0400\r
43 Message-Id: <1335803138-24024-2-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.9.1\r
45 In-Reply-To: <1335803138-24024-1-git-send-email-amdragon@mit.edu>\r
46 References: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
47         <1335803138-24024-1-git-send-email-amdragon@mit.edu>\r
48 X-Brightmail-Tracker:\r
49  H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixCmqrcuxd56/wb6FrBbXb85kdmD0eLbq\r
50         FnMAYxSXTUpqTmZZapG+XQJXxtVXK9gKPgdWLOtbzNjAONmxi5GTQ0LAROLxowOMELaYxIV7\r
51         69m6GLk4hAT2MUrMu36UHcLZwCjx+OlVFgjnPpNE+6zLTBDOfEaJtZ/esYH0swloSGzbvxxs\r
52         loiAtMTOu7NZuxg5OJgF1CT+dKmAhIUFAiSOTfkPVsIioCrR8PEuWCuvgIPEqu0T2SDOUJB4\r
53         tu44E4jNKeAocevANxYQW0igXGLjhU+MExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI1\r
54         0svNLNFLTSndxAgOG0neHYzvDiodYhTgYFTi4Z00f56/EGtiWXFl7iFGSQ4mJVHe9buBQnxJ\r
55         +SmVGYnFGfFFpTmpxYcYJTiYlUR4SycC5XhTEiurUovyYVLSHCxK4ryqWu/8hATSE0tSs1NT\r
56         C1KLYLIyHBxKErx/QYYKFqWmp1akZeaUIKSZODhBhvMADT8OUsNbXJCYW5yZDpE/xagoJc67\r
57         ACQhAJLIKM2D64XF9StGcaBXhHmvgVTxAFMCXPcroMFMQIPzzcEGlyQipKQaGJtX/hRJPfuY\r
58         +/rry6+amRo3rZ9wenuf3sGlK/jLN6/O3Jije1R186stWjllhgc/Ts7QObLfWfz6jYrVK6+X\r
59         z4iXSTuceWDhn2ub5H5f+f7M/FaPTf7DDfKTdvjO0lK+4TRb79fuVfdlKxN8DDcwfLi+fJsF\r
60         Z87UrWE7n1ltLkxTTHzJVSxsK3JCiaU4I9FQi7moOBEAYk6UZMYCAAA=\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Mon, 30 Apr 2012 16:25:47 -0000\r
74 \r
75 It has been a long-standing issue that notmuch_database_open doesn't\r
76 return any indication of why it failed.  This patch changes its\r
77 prototype to return a notmuch_status_t and set an out-argument to the\r
78 database itself, like other functions that return both a status and an\r
79 object.\r
80 \r
81 In the interest of atomicity, this also updates every use in the CLI\r
82 so that notmuch still compiles.  Since this patch does not update the\r
83 bindings, the Python bindings test fails.\r
84 ---\r
85  lib/database.cc     |   28 +++++++++++++++++++++++-----\r
86  lib/notmuch.h       |   26 +++++++++++++++++++-------\r
87  notmuch-count.c     |    5 ++---\r
88  notmuch-dump.c      |    5 ++---\r
89  notmuch-new.c       |    5 ++---\r
90  notmuch-reply.c     |    5 ++---\r
91  notmuch-restore.c   |    5 ++---\r
92  notmuch-search.c    |    5 ++---\r
93  notmuch-show.c      |    5 ++---\r
94  notmuch-tag.c       |    5 ++---\r
95  test/symbol-test.cc |    3 ++-\r
96  11 files changed, 60 insertions(+), 37 deletions(-)\r
97 \r
98 diff --git a/lib/database.cc b/lib/database.cc\r
99 index 2fefcad..1e66599 100644\r
100 --- a/lib/database.cc\r
101 +++ b/lib/database.cc\r
102 @@ -556,8 +556,9 @@ notmuch_database_create (const char *path)\r
103         goto DONE;\r
104      }\r
105  \r
106 -    notmuch = notmuch_database_open (path,\r
107 -                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
108 +    notmuch_database_open (path,\r
109 +                          NOTMUCH_DATABASE_MODE_READ_WRITE,\r
110 +                          &notmuch);\r
111      notmuch_database_upgrade (notmuch, NULL, NULL);\r
112  \r
113    DONE:\r
114 @@ -578,10 +579,12 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)\r
115      return NOTMUCH_STATUS_SUCCESS;\r
116  }\r
117  \r
118 -notmuch_database_t *\r
119 +notmuch_status_t\r
120  notmuch_database_open (const char *path,\r
121 -                      notmuch_database_mode_t mode)\r
122 +                      notmuch_database_mode_t mode,\r
123 +                      notmuch_database_t **database)\r
124  {\r
125 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
126      void *local = talloc_new (NULL);\r
127      notmuch_database_t *notmuch = NULL;\r
128      char *notmuch_path, *xapian_path;\r
129 @@ -590,8 +593,15 @@ notmuch_database_open (const char *path,\r
130      unsigned int i, version;\r
131      static int initialized = 0;\r
132  \r
133 +    if (path == NULL) {\r
134 +       fprintf (stderr, "Error: Cannot open a database for a NULL path.\n");\r
135 +       status = NOTMUCH_STATUS_NULL_POINTER;\r
136 +       goto DONE;\r
137 +    }\r
138 +\r
139      if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {\r
140         fprintf (stderr, "Out of memory\n");\r
141 +       status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
142         goto DONE;\r
143      }\r
144  \r
145 @@ -599,11 +609,13 @@ notmuch_database_open (const char *path,\r
146      if (err) {\r
147         fprintf (stderr, "Error opening database at %s: %s\n",\r
148                  notmuch_path, strerror (errno));\r
149 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
150         goto DONE;\r
151      }\r
152  \r
153      if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {\r
154         fprintf (stderr, "Out of memory\n");\r
155 +       status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
156         goto DONE;\r
157      }\r
158  \r
159 @@ -644,6 +656,7 @@ notmuch_database_open (const char *path,\r
160                 notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
161                 notmuch_database_destroy (notmuch);\r
162                 notmuch = NULL;\r
163 +               status = NOTMUCH_STATUS_FILE_ERROR;\r
164                 goto DONE;\r
165             }\r
166  \r
167 @@ -704,12 +717,17 @@ notmuch_database_open (const char *path,\r
168                  error.get_msg().c_str());\r
169         notmuch_database_destroy (notmuch);\r
170         notmuch = NULL;\r
171 +       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
172      }\r
173  \r
174    DONE:\r
175      talloc_free (local);\r
176  \r
177 -    return notmuch;\r
178 +    if (database)\r
179 +       *database = notmuch;\r
180 +    else\r
181 +       talloc_free (notmuch);\r
182 +    return status;\r
183  }\r
184  \r
185  void\r
186 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
187 index 7d9e092..44b0c46 100644\r
188 --- a/lib/notmuch.h\r
189 +++ b/lib/notmuch.h\r
190 @@ -151,9 +151,6 @@ typedef enum {\r
191      NOTMUCH_DATABASE_MODE_READ_WRITE\r
192  } notmuch_database_mode_t;\r
193  \r
194 -/* XXX: I think I'd like this to take an extra argument of\r
195 - * notmuch_status_t* for returning a status value on failure. */\r
196 -\r
197  /* Open an existing notmuch database located at 'path'.\r
198   *\r
199   * The database should have been created at some time in the past,\r
200 @@ -168,12 +165,27 @@ typedef enum {\r
201   * The caller should call notmuch_database_destroy when finished with\r
202   * this database.\r
203   *\r
204 - * In case of any failure, this function returns NULL, (after printing\r
205 - * an error message on stderr).\r
206 + * In case of any failure, this function returns an error status and\r
207 + * sets *database to NULL (after printing an error message on stderr).\r
208 + *\r
209 + * Return value:\r
210 + *\r
211 + * NOTMUCH_STATUS_SUCCESS: Successfully opened the database.\r
212 + *\r
213 + * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL.\r
214 + *\r
215 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.\r
216 + *\r
217 + * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the\r
218 + *     database file (such as permission denied, or file not found,\r
219 + *     etc.), or the database version is unknown.\r
220 + *\r
221 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.\r
222   */\r
223 -notmuch_database_t *\r
224 +notmuch_status_t\r
225  notmuch_database_open (const char *path,\r
226 -                      notmuch_database_mode_t mode);\r
227 +                      notmuch_database_mode_t mode,\r
228 +                      notmuch_database_t **database);\r
229  \r
230  /* Close the given notmuch database.\r
231   *\r
232 diff --git a/notmuch-count.c b/notmuch-count.c\r
233 index 9c2ad7b..2f98128 100644\r
234 --- a/notmuch-count.c\r
235 +++ b/notmuch-count.c\r
236 @@ -66,9 +66,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
237      if (config == NULL)\r
238         return 1;\r
239  \r
240 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
241 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
242 -    if (notmuch == NULL)\r
243 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
244 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
245         return 1;\r
246  \r
247      query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
248 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
249 index 71ab0ea..3743214 100644\r
250 --- a/notmuch-dump.c\r
251 +++ b/notmuch-dump.c\r
252 @@ -36,9 +36,8 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
253      if (config == NULL)\r
254         return 1;\r
255  \r
256 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
257 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
258 -    if (notmuch == NULL)\r
259 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
260 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
261         return 1;\r
262  \r
263      char *output_file_name = NULL;\r
264 diff --git a/notmuch-new.c b/notmuch-new.c\r
265 index 3ff6304..7788743 100644\r
266 --- a/notmuch-new.c\r
267 +++ b/notmuch-new.c\r
268 @@ -903,9 +903,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
269         notmuch = notmuch_database_create (db_path);\r
270         add_files_state.total_files = count;\r
271      } else {\r
272 -       notmuch = notmuch_database_open (db_path,\r
273 -                                        NOTMUCH_DATABASE_MODE_READ_WRITE);\r
274 -       if (notmuch == NULL)\r
275 +       if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,\r
276 +                                  &notmuch))\r
277             return 1;\r
278  \r
279         if (notmuch_database_needs_upgrade (notmuch)) {\r
280 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
281 index da99a13..7184a5d 100644\r
282 --- a/notmuch-reply.c\r
283 +++ b/notmuch-reply.c\r
284 @@ -740,9 +740,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
285         return 1;\r
286      }\r
287  \r
288 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
289 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
290 -    if (notmuch == NULL)\r
291 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
292 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
293         return 1;\r
294  \r
295      query = notmuch_query_create (notmuch, query_string);\r
296 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
297 index 02b563c..4f4096e 100644\r
298 --- a/notmuch-restore.c\r
299 +++ b/notmuch-restore.c\r
300 @@ -115,9 +115,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
301      if (config == NULL)\r
302         return 1;\r
303  \r
304 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
305 -                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
306 -    if (notmuch == NULL)\r
307 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
308 +                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
309         return 1;\r
310  \r
311      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
312 diff --git a/notmuch-search.c b/notmuch-search.c\r
313 index 7dfd270..3be296d 100644\r
314 --- a/notmuch-search.c\r
315 +++ b/notmuch-search.c\r
316 @@ -486,9 +486,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
317      if (config == NULL)\r
318         return 1;\r
319  \r
320 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
321 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
322 -    if (notmuch == NULL)\r
323 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
324 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
325         return 1;\r
326  \r
327      query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);\r
328 diff --git a/notmuch-show.c b/notmuch-show.c\r
329 index 3b6667c..95427d4 100644\r
330 --- a/notmuch-show.c\r
331 +++ b/notmuch-show.c\r
332 @@ -1081,9 +1081,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
333         return 1;\r
334      }\r
335  \r
336 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
337 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
338 -    if (notmuch == NULL)\r
339 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
340 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
341         return 1;\r
342  \r
343      query = notmuch_query_create (notmuch, query_string);\r
344 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
345 index bd56fd1..7d18639 100644\r
346 --- a/notmuch-tag.c\r
347 +++ b/notmuch-tag.c\r
348 @@ -229,9 +229,8 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
349      if (config == NULL)\r
350         return 1;\r
351  \r
352 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
353 -                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
354 -    if (notmuch == NULL)\r
355 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
356 +                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
357         return 1;\r
358  \r
359      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
360 diff --git a/test/symbol-test.cc b/test/symbol-test.cc\r
361 index 1548ca4..3e96c03 100644\r
362 --- a/test/symbol-test.cc\r
363 +++ b/test/symbol-test.cc\r
364 @@ -4,7 +4,8 @@\r
365  \r
366  \r
367  int main() {\r
368 -  (void) notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY);\r
369 +  notmuch_database_t *notmuch;\r
370 +  notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch);\r
371  \r
372    try {\r
373      (void) new Xapian::WritableDatabase("./nonexistant", Xapian::DB_OPEN);\r
374 -- \r
375 1.7.9.1\r
376 \r