--- /dev/null
+Return-Path: <bremner@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 arlo.cworth.org (Postfix) with ESMTP id 058056DE00F5\r
+ for <notmuch@notmuchmail.org>; Fri, 15 Jul 2016 03:27:16 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.011\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.011 tagged_above=-999 required=5 tests=[AWL=0.000,\r
+ SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 3fgdAaTsH2TT for <notmuch@notmuchmail.org>;\r
+ Fri, 15 Jul 2016 03:27:07 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 26D856DE00C9\r
+ for <notmuch@notmuchmail.org>; Fri, 15 Jul 2016 03:27:07 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1bO0KP-00019c-Qz; Fri, 15 Jul 2016 06:26:41 -0400\r
+Received: (nullmailer pid 7749 invoked by uid 1000);\r
+ Fri, 15 Jul 2016 10:27:03 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] lib: provide _notmuch_database_log_append\r
+Date: Fri, 15 Jul 2016 07:25:41 -0300\r
+Message-Id: <1468578341-7705-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.1\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 15 Jul 2016 10:27:16 -0000\r
+\r
+_notmuch_database_log clears the log buffer each time. Rather than\r
+introducing more complicated semantics about for this function, provide\r
+a second function that does not clear the buffer. This is mainly a\r
+convenience function for callers constructing complex or multi-line log\r
+messages.\r
+\r
+The changes to query.cc are to make sure that the common code path of\r
+the new function is tested.\r
+---\r
+ lib/database.cc | 16 ++++++++++++++++\r
+ lib/notmuch-private.h | 4 ++++\r
+ lib/query.cc | 14 ++++++++------\r
+ 3 files changed, 28 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 66ee267..57a98c9 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -383,6 +383,22 @@ _notmuch_database_log (notmuch_database_t *notmuch,\r
+ talloc_free (notmuch->status_string);\r
+ \r
+ notmuch->status_string = talloc_vasprintf (notmuch, format, va_args);\r
++ va_end (va_args);\r
++}\r
++\r
++void\r
++_notmuch_database_log_append (notmuch_database_t *notmuch,\r
++ const char *format,\r
++ ...)\r
++{\r
++ va_list va_args;\r
++\r
++ va_start (va_args, format);\r
++\r
++ if (notmuch->status_string)\r
++ notmuch->status_string = talloc_vasprintf_append (notmuch->status_string, format, va_args);\r
++ else\r
++ notmuch->status_string = talloc_vasprintf (notmuch, format, va_args);\r
+ \r
+ va_end (va_args);\r
+ }\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 3721431..643d9dd 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -196,6 +196,10 @@ void\r
+ _notmuch_database_log (notmuch_database_t *notmuch,\r
+ const char *format, ...);\r
+ \r
++void\r
++_notmuch_database_log_append (notmuch_database_t *notmuch,\r
++ const char *format, ...);\r
++\r
+ unsigned long\r
+ _notmuch_database_new_revision (notmuch_database_t *notmuch);\r
+ \r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 7eb73a1..53efd4e 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -299,9 +299,10 @@ _notmuch_query_search_documents (notmuch_query_t *query,\r
+ \r
+ } catch (const Xapian::Error &error) {\r
+ _notmuch_database_log (notmuch,\r
+- "A Xapian exception occurred performing query: %s\n"\r
++ "A Xapian exception occurred performing query: %s\n",\r
++ error.get_msg().c_str());\r
++ _notmuch_database_log_append (notmuch,\r
+ "Query string was: %s\n",\r
+- error.get_msg().c_str(),\r
+ query->query_string);\r
+ \r
+ notmuch->exception_reported = TRUE;\r
+@@ -613,10 +614,11 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign\r
+ \r
+ } catch (const Xapian::Error &error) {\r
+ _notmuch_database_log (notmuch,\r
+- "A Xapian exception occurred performing query: %s\n"\r
+- "Query string was: %s\n",\r
+- error.get_msg().c_str(),\r
+- query->query_string);\r
++ "A Xapian exception occurred performing query: %s\n",\r
++ error.get_msg().c_str());\r
++ _notmuch_database_log_append (notmuch,\r
++ "Query string was: %s\n",\r
++ query->query_string);\r
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+ }\r
+ \r
+-- \r
+2.8.1\r
+\r