Re: [PATCH 2/2] lib: introduce notmuch_database_new for initializing a database handle
authorDavid Bremner <david@tethera.net>
Tue, 14 Jan 2014 13:22:06 +0000 (09:22 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:59:02 +0000 (09:59 -0800)
ba/083e1a7c242640c1ea436bf23133cc59600967 [new file with mode: 0644]

diff --git a/ba/083e1a7c242640c1ea436bf23133cc59600967 b/ba/083e1a7c242640c1ea436bf23133cc59600967
new file mode 100644 (file)
index 0000000..07b65e7
--- /dev/null
@@ -0,0 +1,120 @@
+Return-Path: <david@tethera.net>\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 10D9A431FAF\r
+       for <notmuch@notmuchmail.org>; Tue, 14 Jan 2014 05:22:25 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 v-ttB9gRtSrc for <notmuch@notmuchmail.org>;\r
+       Tue, 14 Jan 2014 05:22:17 -0800 (PST)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+       (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 2421B431FAE\r
+       for <notmuch@notmuchmail.org>; Tue, 14 Jan 2014 05:22:17 -0800 (PST)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+       (envelope-from <david@tethera.net>)\r
+       id 1W33wY-0006l2-6M; Tue, 14 Jan 2014 09:22:10 -0400\r
+Received: (nullmailer pid 27441 invoked by uid 1000); Tue, 14 Jan 2014\r
+       13:22:06 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: Jani Nikula <jani@nikula.org>, Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH 2/2] lib: introduce notmuch_database_new for initializing\r
+       a database handle\r
+In-Reply-To: <87mwkf40x5.fsf@nikula.org>\r
+References: <cover.1385903109.git.jani@nikula.org>\r
+       <fc7ecd990e55fcfba17de4d71e8823c98760f9ce.1385903109.git.jani@nikula.org>\r
+       <20131204231113.GD8854@mit.edu> <87mwkf40x5.fsf@nikula.org>\r
+User-Agent: Notmuch/0.17 (http://notmuchmail.org) Emacs/24.3.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Tue, 14 Jan 2014 09:22:06 -0400\r
+Message-ID: <87a9eyk8ap.fsf@zancas.localnet>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+Cc: notmuch@notmuchmail.org\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: Tue, 14 Jan 2014 13:22:25 -0000\r
+\r
+Jani Nikula <jani@nikula.org> writes:\r
+>> Austin Wrote:\r
+>>\r
+>> Orthogonally -- and this may be a complete pipe dream of mine -- if we\r
+>> just had a way to return more detailed error information than a simple\r
+>> error code from notmuch_database_{create,open}, I think we wouldn't\r
+>> need any of this.  Everything that these functions currently log\r
+>> (modulo one warning) is error details, so if we could return the error\r
+>> details *with the error* or somehow make them accessible, we wouldn't\r
+>> need a logger at this point (or at several other points in the\r
+>> library).\r
+>\r
+> Agreed. I tried to look into this earlier, but was hitting dead ends\r
+> *if* we want to keep reporting user friendly error status in\r
+> open/create. Obviously any concrete suggestions would be most welcome!\r
+>\r
+\r
+I'm not sure if this is also a dead end, but I was trying to sketch out\r
+an api that returned something more detailed as status and came up with\r
+the following.  The general idea is to replace notmuch_status_t with a\r
+pointer to struct.  This will require pretty noisy source changes,\r
+unless we're comfortable with using NULL pointer to indicate success.\r
+In either case we'd rename the existing enum to something like\r
+notmuch_status_code_t.\r
+\r
+/* pseudo-C follows */\r
+\r
+typedef struct notmuch_status_struct * notmuch_status_t;\r
+\r
+/* we can just tell external users to pass NULL as the first argument */\r
+\r
+notmuch_status_t notmuch_status_new (void *ctx, size_t bufsiz);\r
+void notmuch_error_destroy (notuch_error_desc_t *victim);\r
+\r
+/* printf equivalent */\r
+notmuch_status_t *notmuch_status_format(notmuch_status_t dest,\r
+                                       notmuch_status_code_t code,\r
+                                       const char *format, ...);\r
+/* case 1, caller allocates */\r
+status = notmuch_status_new (BUFSIZ);\r
+if (!status) {\r
+    halt_and_catch_fire();\r
+}\r
+\r
+/* open could continue to return notmuch_status_code_t, or just 0/1 */\r
+if (notmuch_database_open (notmuch_config_get_database_path (config),\r
+                          NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch, status)) {\r
+    fprintf (stderr, "oops: %s\n", notmuch_status_to_string (status));\r
+    notmuch_error_destroy(error_details);\r
+    return 1;\r
+}\r
+\r
+/* case 2, callee allocates */\r
+\r
+status = notmuch_message_freeze (message);\r
+if (notmuch_status_to_code (status)) {  /* every check needs to be changed, unless NULL=OK */\r
+    message_error (message, status, "freezing message");\r
+    return status;\r
+}\r
+\r
+/* some existing code is left alone */\r
+\r
+fprintf (stderr, "Message-ID: %s\n", notmuch_message_get_message_id (message));\r
+fprintf (stderr, "Status: %s\n", notmuch_status_to_string (status));\r
+\r