Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 3b / 067aca2a9a8628495d96a8f7890aafd7c94a9d
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5  by arlo.cworth.org (Postfix) with ESMTP id 058056DE00F5\r
6  for <notmuch@notmuchmail.org>; Fri, 15 Jul 2016 03:27:16 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.011\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.011 tagged_above=-999 required=5 tests=[AWL=0.000,\r
12   SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id 3fgdAaTsH2TT for <notmuch@notmuchmail.org>;\r
16  Fri, 15 Jul 2016 03:27:07 -0700 (PDT)\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
18  by arlo.cworth.org (Postfix) with ESMTPS id 26D856DE00C9\r
19  for <notmuch@notmuchmail.org>; Fri, 15 Jul 2016 03:27:07 -0700 (PDT)\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
21  (envelope-from <bremner@tethera.net>)\r
22  id 1bO0KP-00019c-Qz; Fri, 15 Jul 2016 06:26:41 -0400\r
23 Received: (nullmailer pid 7749 invoked by uid 1000);\r
24  Fri, 15 Jul 2016 10:27:03 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [PATCH] lib: provide _notmuch_database_log_append\r
28 Date: Fri, 15 Jul 2016 07:25:41 -0300\r
29 Message-Id: <1468578341-7705-1-git-send-email-david@tethera.net>\r
30 X-Mailer: git-send-email 2.8.1\r
31 X-BeenThere: notmuch@notmuchmail.org\r
32 X-Mailman-Version: 2.1.20\r
33 Precedence: list\r
34 List-Id: "Use and development of the notmuch mail system."\r
35  <notmuch.notmuchmail.org>\r
36 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
37  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
38 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
39 List-Post: <mailto:notmuch@notmuchmail.org>\r
40 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
41 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
42  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
43 X-List-Received-Date: Fri, 15 Jul 2016 10:27:16 -0000\r
44 \r
45 _notmuch_database_log clears the log buffer each time. Rather than\r
46 introducing more complicated semantics about for this function, provide\r
47 a second function that does not clear the buffer. This is mainly a\r
48 convenience function for callers constructing complex or multi-line log\r
49 messages.\r
50 \r
51 The changes to query.cc are to make sure that the common code path of\r
52 the new function is tested.\r
53 ---\r
54  lib/database.cc       | 16 ++++++++++++++++\r
55  lib/notmuch-private.h |  4 ++++\r
56  lib/query.cc          | 14 ++++++++------\r
57  3 files changed, 28 insertions(+), 6 deletions(-)\r
58 \r
59 diff --git a/lib/database.cc b/lib/database.cc\r
60 index 66ee267..57a98c9 100644\r
61 --- a/lib/database.cc\r
62 +++ b/lib/database.cc\r
63 @@ -383,6 +383,22 @@ _notmuch_database_log (notmuch_database_t *notmuch,\r
64         talloc_free (notmuch->status_string);\r
65  \r
66      notmuch->status_string = talloc_vasprintf (notmuch, format, va_args);\r
67 +    va_end (va_args);\r
68 +}\r
69 +\r
70 +void\r
71 +_notmuch_database_log_append (notmuch_database_t *notmuch,\r
72 +                     const char *format,\r
73 +                     ...)\r
74 +{\r
75 +    va_list va_args;\r
76 +\r
77 +    va_start (va_args, format);\r
78 +\r
79 +    if (notmuch->status_string)\r
80 +       notmuch->status_string = talloc_vasprintf_append (notmuch->status_string, format, va_args);\r
81 +    else\r
82 +       notmuch->status_string = talloc_vasprintf (notmuch, format, va_args);\r
83  \r
84      va_end (va_args);\r
85  }\r
86 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
87 index 3721431..643d9dd 100644\r
88 --- a/lib/notmuch-private.h\r
89 +++ b/lib/notmuch-private.h\r
90 @@ -196,6 +196,10 @@ void\r
91  _notmuch_database_log (notmuch_database_t *notmuch,\r
92                        const char *format, ...);\r
93  \r
94 +void\r
95 +_notmuch_database_log_append (notmuch_database_t *notmuch,\r
96 +                             const char *format, ...);\r
97 +\r
98  unsigned long\r
99  _notmuch_database_new_revision (notmuch_database_t *notmuch);\r
100  \r
101 diff --git a/lib/query.cc b/lib/query.cc\r
102 index 7eb73a1..53efd4e 100644\r
103 --- a/lib/query.cc\r
104 +++ b/lib/query.cc\r
105 @@ -299,9 +299,10 @@ _notmuch_query_search_documents (notmuch_query_t *query,\r
106  \r
107      } catch (const Xapian::Error &error) {\r
108         _notmuch_database_log (notmuch,\r
109 -                              "A Xapian exception occurred performing query: %s\n"\r
110 +                              "A Xapian exception occurred performing query: %s\n",\r
111 +                              error.get_msg().c_str());\r
112 +       _notmuch_database_log_append (notmuch,\r
113                                "Query string was: %s\n",\r
114 -                              error.get_msg().c_str(),\r
115                                query->query_string);\r
116  \r
117         notmuch->exception_reported = TRUE;\r
118 @@ -613,10 +614,11 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign\r
119  \r
120      } catch (const Xapian::Error &error) {\r
121         _notmuch_database_log (notmuch,\r
122 -                              "A Xapian exception occurred performing query: %s\n"\r
123 -                              "Query string was: %s\n",\r
124 -                              error.get_msg().c_str(),\r
125 -                              query->query_string);\r
126 +                              "A Xapian exception occurred performing query: %s\n",\r
127 +                              error.get_msg().c_str());\r
128 +       _notmuch_database_log_append (notmuch,\r
129 +                                     "Query string was: %s\n",\r
130 +                                     query->query_string);\r
131         return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
132      }\r
133  \r
134 -- \r
135 2.8.1\r
136 \r