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