--- /dev/null
+Return-Path: <amthrax@drake.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id DA802431FB6\r
+ for <notmuch@notmuchmail.org>; Sat, 28 Apr 2012 15:18:03 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id JLiq5t7m1cK9 for <notmuch@notmuchmail.org>;\r
+ Sat, 28 Apr 2012 15:18:01 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
+ [18.9.25.12])\r
+ by olra.theworths.org (Postfix) with ESMTP id 008FD431FC2\r
+ for <notmuch@notmuchmail.org>; Sat, 28 Apr 2012 15:17:59 -0700 (PDT)\r
+X-AuditID: 1209190c-b7fad6d000000920-ae-4f9c6c97ab96\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 20.19.02336.79C6C9F4; Sat, 28 Apr 2012 18:17:59 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q3SMHwFx005266; \r
+ Sat, 28 Apr 2012 18:17:58 -0400\r
+Received: from drake.mit.edu\r
+ (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [209.6.116.242]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3SMHvfi008918\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Sat, 28 Apr 2012 18:17:58 -0400 (EDT)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amthrax@drake.mit.edu>)\r
+ id 1SOFxk-00058D-UF; Sat, 28 Apr 2012 18:17:57 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/6] lib/cli: Make notmuch_database_open return a status code\r
+Date: Sat, 28 Apr 2012 18:17:48 -0400\r
+Message-Id: <1335651473-19652-2-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
+References: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrTs9Z46/wbwGRYvrN2cyOzB6PFt1\r
+ izmAMYrLJiU1J7MstUjfLoEro+uvT8E974rD+w6xNTAutuli5OSQEDCReHj6CDOELSZx4d56\r
+ ti5GLg4hgX2MEvvb37JDOBsYJe6v/Abl3GeS6N2+kxGkRUhgPqPE3gfuIDabgIbEtv3LweIi\r
+ AtISO+/OZu1i5OBgFlCT+NOlAhIWFvCV6L/dwwpiswioSjRdX88CYvMKOEjs7rrPCnGFgsSz\r
+ dceZQGxOAUeJ/5tPsEOscpDomDeBbQIj/wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6hnq5\r
+ mSV6qSmlmxjBISPJs4PxzUGlQ4wCHIxKPLwH18/yF2JNLCuuzD3EKMnBpCTKy5I1x1+ILyk/\r
+ pTIjsTgjvqg0J7X4EKMEB7OSCK+2OFCONyWxsiq1KB8mJc3BoiTOq6L1zk9IID2xJDU7NbUg\r
+ tQgmK8PBoSTB25oN1ChYlJqeWpGWmVOCkGbi4AQZzgM0fA9IDW9xQWJucWY6RP4Uo6KUOO96\r
+ kIQASCKjNA+uFxbTrxjFgV4R5p0OUsUDTAdw3a+ABjMBDWbynAUyuCQRISXVwDjhWIxX4R/T\r
+ fPUDRdyXtfv3/ZeuT1ffU1+0nPeKsPXsmsNftnVGHFn0VeAxf8Td+Yu/xPNY9Srv51byXjnd\r
+ 9OLbouS92xsC+lbcUVi++/8M9Z+X3/zJ6YkIOGS9US7DK1FLRCVkoxy7qGJA2dIPprZJGbfX\r
+ 1alsXMKqu6dW6m+CaHyFRNkWaSWW4oxEQy3mouJEADajNlLEAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 28 Apr 2012 22:18:04 -0000\r
+\r
+It has been a long-standing issue that notmuch_database_open doesn't\r
+return any indication of why it failed. This patch changes its\r
+prototype to return a notmuch_status_t and set an out-argument to the\r
+database itself, like other functions that return both a status and an\r
+object.\r
+\r
+In the interest of atomicity, this also updates every use in the CLI\r
+so that notmuch still compiles. Since this patch does not update the\r
+bindings, the Python bindings test fails.\r
+---\r
+ lib/database.cc | 19 ++++++++++++++-----\r
+ lib/notmuch.h | 12 +++++-------\r
+ notmuch-count.c | 5 ++---\r
+ notmuch-dump.c | 5 ++---\r
+ notmuch-new.c | 5 ++---\r
+ notmuch-reply.c | 5 ++---\r
+ notmuch-restore.c | 5 ++---\r
+ notmuch-search.c | 5 ++---\r
+ notmuch-show.c | 5 ++---\r
+ notmuch-tag.c | 5 ++---\r
+ test/symbol-test.cc | 3 ++-\r
+ 11 files changed, 37 insertions(+), 37 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 2fefcad..a29fe67 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -556,8 +556,9 @@ notmuch_database_create (const char *path)\r
+ goto DONE;\r
+ }\r
+ \r
+- notmuch = notmuch_database_open (path,\r
+- NOTMUCH_DATABASE_MODE_READ_WRITE);\r
++ notmuch_database_open (path,\r
++ NOTMUCH_DATABASE_MODE_READ_WRITE,\r
++ ¬much);\r
+ notmuch_database_upgrade (notmuch, NULL, NULL);\r
+ \r
+ DONE:\r
+@@ -578,10 +579,12 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)\r
+ return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
+ \r
+-notmuch_database_t *\r
++notmuch_status_t\r
+ notmuch_database_open (const char *path,\r
+- notmuch_database_mode_t mode)\r
++ notmuch_database_mode_t mode,\r
++ notmuch_database_t **database)\r
+ {\r
++ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
+ void *local = talloc_new (NULL);\r
+ notmuch_database_t *notmuch = NULL;\r
+ char *notmuch_path, *xapian_path;\r
+@@ -592,6 +595,7 @@ notmuch_database_open (const char *path,\r
+ \r
+ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {\r
+ fprintf (stderr, "Out of memory\n");\r
++ status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+ goto DONE;\r
+ }\r
+ \r
+@@ -599,11 +603,13 @@ notmuch_database_open (const char *path,\r
+ if (err) {\r
+ fprintf (stderr, "Error opening database at %s: %s\n",\r
+ notmuch_path, strerror (errno));\r
++ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+ if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {\r
+ fprintf (stderr, "Out of memory\n");\r
++ status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+ goto DONE;\r
+ }\r
+ \r
+@@ -644,6 +650,7 @@ notmuch_database_open (const char *path,\r
+ notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
+ notmuch_database_destroy (notmuch);\r
+ notmuch = NULL;\r
++ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+@@ -704,12 +711,14 @@ notmuch_database_open (const char *path,\r
+ error.get_msg().c_str());\r
+ notmuch_database_destroy (notmuch);\r
+ notmuch = NULL;\r
++ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+ }\r
+ \r
+ DONE:\r
+ talloc_free (local);\r
+ \r
+- return notmuch;\r
++ *database = notmuch;\r
++ return status;\r
+ }\r
+ \r
+ void\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 7d9e092..8a011f2 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -151,9 +151,6 @@ typedef enum {\r
+ NOTMUCH_DATABASE_MODE_READ_WRITE\r
+ } notmuch_database_mode_t;\r
+ \r
+-/* XXX: I think I'd like this to take an extra argument of\r
+- * notmuch_status_t* for returning a status value on failure. */\r
+-\r
+ /* Open an existing notmuch database located at 'path'.\r
+ *\r
+ * The database should have been created at some time in the past,\r
+@@ -168,12 +165,13 @@ typedef enum {\r
+ * The caller should call notmuch_database_destroy when finished with\r
+ * this database.\r
+ *\r
+- * In case of any failure, this function returns NULL, (after printing\r
+- * an error message on stderr).\r
++ * In case of any failure, this function returns an error status and\r
++ * sets *database to NULL (after printing an error message on stderr).\r
+ */\r
+-notmuch_database_t *\r
++notmuch_status_t\r
+ notmuch_database_open (const char *path,\r
+- notmuch_database_mode_t mode);\r
++ notmuch_database_mode_t mode,\r
++ notmuch_database_t **database);\r
+ \r
+ /* Close the given notmuch database.\r
+ *\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index 9c2ad7b..2f98128 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -66,9 +66,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+ if (config == NULL)\r
+ return 1;\r
+ \r
+- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
+- NOTMUCH_DATABASE_MODE_READ_ONLY);\r
+- if (notmuch == NULL)\r
++ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return 1;\r
+ \r
+ query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index 71ab0ea..3743214 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -36,9 +36,8 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+ if (config == NULL)\r
+ return 1;\r
+ \r
+- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
+- NOTMUCH_DATABASE_MODE_READ_ONLY);\r
+- if (notmuch == NULL)\r
++ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return 1;\r
+ \r
+ char *output_file_name = NULL;\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 3ff6304..7788743 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -903,9 +903,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ notmuch = notmuch_database_create (db_path);\r
+ add_files_state.total_files = count;\r
+ } else {\r
+- notmuch = notmuch_database_open (db_path,\r
+- NOTMUCH_DATABASE_MODE_READ_WRITE);\r
+- if (notmuch == NULL)\r
++ if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,\r
++ ¬much))\r
+ return 1;\r
+ \r
+ if (notmuch_database_needs_upgrade (notmuch)) {\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index da99a13..7184a5d 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -740,9 +740,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+ return 1;\r
+ }\r
+ \r
+- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
+- NOTMUCH_DATABASE_MODE_READ_ONLY);\r
+- if (notmuch == NULL)\r
++ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return 1;\r
+ \r
+ query = notmuch_query_create (notmuch, query_string);\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index 02b563c..4f4096e 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -115,9 +115,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+ if (config == NULL)\r
+ return 1;\r
+ \r
+- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
+- NOTMUCH_DATABASE_MODE_READ_WRITE);\r
+- if (notmuch == NULL)\r
++ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+ return 1;\r
+ \r
+ synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 7dfd270..3be296d 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -486,9 +486,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+ if (config == NULL)\r
+ return 1;\r
+ \r
+- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
+- NOTMUCH_DATABASE_MODE_READ_ONLY);\r
+- if (notmuch == NULL)\r
++ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return 1;\r
+ \r
+ query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 3b6667c..95427d4 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -1081,9 +1081,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ return 1;\r
+ }\r
+ \r
+- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
+- NOTMUCH_DATABASE_MODE_READ_ONLY);\r
+- if (notmuch == NULL)\r
++ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return 1;\r
+ \r
+ query = notmuch_query_create (notmuch, query_string);\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index bd56fd1..7d18639 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -229,9 +229,8 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+ if (config == NULL)\r
+ return 1;\r
+ \r
+- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
+- NOTMUCH_DATABASE_MODE_READ_WRITE);\r
+- if (notmuch == NULL)\r
++ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+ return 1;\r
+ \r
+ synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
+diff --git a/test/symbol-test.cc b/test/symbol-test.cc\r
+index 1548ca4..3e96c03 100644\r
+--- a/test/symbol-test.cc\r
++++ b/test/symbol-test.cc\r
+@@ -4,7 +4,8 @@\r
+ \r
+ \r
+ int main() {\r
+- (void) notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY);\r
++ notmuch_database_t *notmuch;\r
++ notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much);\r
+ \r
+ try {\r
+ (void) new Xapian::WritableDatabase("./nonexistant", Xapian::DB_OPEN);\r
+-- \r
+1.7.9.1\r
+\r