[Patch v3 6/6] lib: eliminate fprintf from _notmuch_message_file_open
authorDavid Bremner <david@tethera.net>
Sun, 28 Dec 2014 17:33:50 +0000 (18:33 +0100)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:47:06 +0000 (14:47 -0700)
55/0169c601b71cd66f499a43ea9a7e534e2a62f1 [new file with mode: 0644]

diff --git a/55/0169c601b71cd66f499a43ea9a7e534e2a62f1 b/55/0169c601b71cd66f499a43ea9a7e534e2a62f1
new file mode 100644 (file)
index 0000000..121695b
--- /dev/null
@@ -0,0 +1,145 @@
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 E0976429E41\r
+       for <notmuch@notmuchmail.org>; Sun, 28 Dec 2014 09:38:06 -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 p10hhQr9xYFu for <notmuch@notmuchmail.org>;\r
+       Sun, 28 Dec 2014 09:38:02 -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 241AD429E3E\r
+       for <notmuch@notmuchmail.org>; Sun, 28 Dec 2014 09:38:01 -0800 (PST)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+       (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+       id 1Y5Hmv-0002fj-Mx; Sun, 28 Dec 2014 13:37:57 -0400\r
+Received: (nullmailer pid 11504 invoked by uid 1000); Sun, 28 Dec 2014\r
+       17:37:40 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v3 6/6] lib: eliminate fprintf from _notmuch_message_file_open\r
+Date: Sun, 28 Dec 2014 18:33:50 +0100\r
+Message-Id: <1419788030-10567-7-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.3\r
+In-Reply-To: <1419788030-10567-1-git-send-email-david@tethera.net>\r
+References: <1419788030-10567-1-git-send-email-david@tethera.net>\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: Sun, 28 Dec 2014 17:38:07 -0000\r
+\r
+You may wonder why _notmuch_message_file_open_ctx has two parameters.\r
+This is because we need sometime to use a ctx which is a\r
+notmuch_message_t. While we could get the database from this, there is\r
+no easy way in C to tell type we are getting. The remaining fprintf is\r
+removed by Jani's series un-deprecating single message mboxes.\r
+---\r
+ lib/database.cc       |  2 +-\r
+ lib/message-file.c    | 11 +++++++----\r
+ lib/message.cc        |  3 ++-\r
+ lib/notmuch-private.h |  5 +++--\r
+ 4 files changed, 13 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 19f5f0e..b144885 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -2298,7 +2298,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
+     if (ret)\r
+       return ret;\r
\r
+-    message_file = _notmuch_message_file_open (filename);\r
++    message_file = _notmuch_message_file_open (notmuch, filename);\r
+     if (message_file == NULL)\r
+       return NOTMUCH_STATUS_FILE_ERROR;\r
\r
+diff --git a/lib/message-file.c b/lib/message-file.c\r
+index eda1b74..1f55cdf 100644\r
+--- a/lib/message-file.c\r
++++ b/lib/message-file.c\r
+@@ -76,7 +76,8 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)\r
+ /* Create a new notmuch_message_file_t for 'filename' with 'ctx' as\r
+  * the talloc owner. */\r
+ notmuch_message_file_t *\r
+-_notmuch_message_file_open_ctx (void *ctx, const char *filename)\r
++_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,\r
++                              void *ctx, const char *filename)\r
+ {\r
+     notmuch_message_file_t *message;\r
\r
+@@ -98,16 +99,18 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)\r
+     return message;\r
\r
+   FAIL:\r
+-    fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));\r
++    _notmuch_database_log (notmuch, "Error opening %s: %s\n",\r
++                        filename, strerror (errno));\r
+     _notmuch_message_file_close (message);\r
\r
+     return NULL;\r
+ }\r
\r
+ notmuch_message_file_t *\r
+-_notmuch_message_file_open (const char *filename)\r
++_notmuch_message_file_open (notmuch_database_t *notmuch,\r
++                          const char *filename)\r
+ {\r
+-    return _notmuch_message_file_open_ctx (NULL, filename);\r
++    return _notmuch_message_file_open_ctx (notmuch, NULL, filename);\r
+ }\r
\r
+ void\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 541eabc..4251b44 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -437,7 +437,8 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)\r
+     if (unlikely (filename == NULL))\r
+       return;\r
\r
+-    message->message_file = _notmuch_message_file_open_ctx (message, filename);\r
++    message->message_file = _notmuch_message_file_open_ctx (\r
++      _notmuch_message_database (message), message, filename);\r
+ }\r
\r
+ const char *\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index fad3a92..76a2f33 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -359,11 +359,12 @@ typedef struct _notmuch_message_file notmuch_message_file_t;\r
+  * Returns NULL if any error occurs.\r
+  */\r
+ notmuch_message_file_t *\r
+-_notmuch_message_file_open (const char *filename);\r
++_notmuch_message_file_open (notmuch_database_t *notmuch, const char *filename);\r
\r
+ /* Like notmuch_message_file_open but with 'ctx' as the talloc owner. */\r
+ notmuch_message_file_t *\r
+-_notmuch_message_file_open_ctx (void *ctx, const char *filename);\r
++_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,\r
++                              void *ctx, const char *filename);\r
\r
+ /* Close a notmuch message previously opened with notmuch_message_open. */\r
+ void\r
+-- \r
+2.1.3\r
+\r