[PATCH v2 08/14] cli/reply: reduce the reply format abstractions
[notmuch-archives.git] / a9 / a6f1b6c017cdd32e52d99a8d0b879f5c44a2ea
1 Return-Path: <m.walters@qmul.ac.uk>\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 olra.theworths.org (Postfix) with ESMTP id 0CE1F431FB6\r
6         for <notmuch@notmuchmail.org>; Wed, 19 Jun 2013 14:02:19 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.401\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.401 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         FREEMAIL_REPLY=2.499, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3]\r
14         autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id KLLfK6sD0wdB for <notmuch@notmuchmail.org>;\r
18         Wed, 19 Jun 2013 14:02:11 -0700 (PDT)\r
19 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
20         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id EAE59431FAE\r
23         for <notmuch@notmuchmail.org>; Wed, 19 Jun 2013 14:02:10 -0700 (PDT)\r
24 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
25         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
26         (envelope-from <m.walters@qmul.ac.uk>)\r
27         id 1UpPW1-0002BS-GG; Wed, 19 Jun 2013 22:02:06 +0100\r
28 Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1UpPW0-0002J9-MC; Wed, 19 Jun 2013 22:02:05 +0100\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: notmuch@notmuchmail.org\r
34 Subject: Re: [PATCH v3 7/8] lib: add NOTMUCH_EXCLUDE_FLAG to notmuch_exclude_t\r
35 In-Reply-To: <87bo8edif8.fsf@qmul.ac.uk>\r
36 References: <1368301809-12532-1-git-send-email-markwalters1009@gmail.com>\r
37         <1368301809-12532-8-git-send-email-markwalters1009@gmail.com>\r
38         <87bo8edif8.fsf@qmul.ac.uk>\r
39 User-Agent: Notmuch/0.15.2+171~ge2f30a2 (http://notmuchmail.org) Emacs/23.4.1\r
40         (x86_64-pc-linux-gnu)\r
41 Date: Wed, 19 Jun 2013 22:02:02 +0100\r
42 Message-ID: <87fvwdx19x.fsf@qmul.ac.uk>\r
43 MIME-Version: 1.0\r
44 Content-Type: text/plain; charset=us-ascii\r
45 X-Sender-Host-Address: 93.97.24.31\r
46 X-QM-SPAM-Info: Sender has good ham record.  :)\r
47 X-QM-Body-MD5: 1b03f602faee308225184f651c57fe55 (of first 20000 bytes)\r
48 X-SpamAssassin-Score: 0.6\r
49 X-SpamAssassin-SpamBar: /\r
50 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
51         determine if it is\r
52         spam. We require at least 5.0 points to mark a message as spam.\r
53         This message scored 0.6 points. Summary of the scoring: \r
54         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
55         provider *      (markwalters1009[at]gmail.com)\r
56         *  1.0 FREEMAIL_REPLY From and body contain different freemails\r
57         * -0.4 AWL AWL: From: address is in the auto white-list\r
58 X-QM-Scan-Virus: ClamAV says the message is clean\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Wed, 19 Jun 2013 21:02:19 -0000\r
72 \r
73 \r
74 I think we should decide before 0.16 whether to go with this patch and\r
75 patch 8/8 or for Peter's suggestion at\r
76 id:1368454815-1854-1-git-send-email-novalazy@gmail.com\r
77 \r
78 Now we have an enum for the NOTMUCH_EXCLUDE possibilities (rather than a\r
79 bool) I think it makes sense to implement NOTMUCH_EXCLUDE_FALSE properly\r
80 but I am happy with either choice.\r
81 \r
82 Best wishes\r
83 \r
84 Mark\r
85 \r
86 \r
87 \r
88 On Mon, 13 May 2013, Mark Walters <markwalters1009@gmail.com> wrote:\r
89 > Add NOTMUCH_EXCLUDE_FLAG to notmuch_exclude_t so that it can\r
90 > cover all four values of search --exclude in the cli.\r
91 >\r
92 > Previously the way to avoid any message being marked excluded was to\r
93 > pass in an empty list of excluded tags: since we now have an explicit\r
94 > option we might as well honour it.\r
95 >\r
96 > The enum is in a slightly strange order as the existing FALSE/TRUE\r
97 > options correspond to the new\r
98 > NOTMUCH_EXCLUDE_FLAG/NOTMUCH_EXCLUDE_TRUE options so this means we do\r
99 > not need to bump the version number.\r
100 >\r
101 > Indeed, an example of this is that the cli count and show still use\r
102 > FALSE/TRUE and still work.\r
103 > ---\r
104 >\r
105 > This is a new version of this single patch. In Peter's version\r
106 > NOTMUCH_EXCLUDE_FLAG and NOTMUCH_EXCLUDE_FALSE were treated as synonyms:\r
107 > this makes them behave in the obvious way and documents them.\r
108 >\r
109 > I think the only subtlety is the enum order mentioned in the commit\r
110 > message. Additionally it would be good to update cli count and show and,\r
111 > at for the latter, it would be good to add an option exclude=all too (so\r
112 > excluded messages are completely omitted). Those should both be simple\r
113 > but we need to decide whether to allow all four options\r
114 > (false/flag/true/all) always or not. Always allowing all 4 is nicely\r
115 > consistent but sometimes redundant. Additionally we would need some\r
116 > tests.\r
117 >\r
118 > I think this patch should go in with the main series as I think it is\r
119 > worth reserving the NOTMUCH_EXCLUDE_FALSE #define/value so that we don't\r
120 > break code in future if we do wish to add it.\r
121 >\r
122 > Best wishes\r
123 >\r
124 > Mark\r
125 >\r
126 >\r
127 >  \r
128 >  lib/notmuch.h    |   18 ++++++++++++++++--\r
129 >  lib/query.cc     |    8 +++++---\r
130 >  lib/thread.cc    |   28 +++++++++++++++-------------\r
131 >  notmuch-search.c |    2 +-\r
132 >  4 files changed, 37 insertions(+), 19 deletions(-)\r
133 >\r
134 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
135 > index 27b43ff..73c85a4 100644\r
136 > --- a/lib/notmuch.h\r
137 > +++ b/lib/notmuch.h\r
138 > @@ -500,10 +500,15 @@ typedef enum {\r
139 >  const char *\r
140 >  notmuch_query_get_query_string (notmuch_query_t *query);\r
141 >  \r
142 > -/* Exclude values for notmuch_query_set_omit_excluded */\r
143 > +/* Exclude values for notmuch_query_set_omit_excluded. The strange\r
144 > + * order is to maintain backward compatibility: the old FALSE/TRUE\r
145 > + * options correspond to the new\r
146 > + * NOTMUCH_EXCLUDE_FLAG/NOTMUCH_EXCLUDE_TRUE options.\r
147 > + */\r
148 >  typedef enum {\r
149 > -    NOTMUCH_EXCLUDE_FALSE,\r
150 > +    NOTMUCH_EXCLUDE_FLAG,\r
151 >      NOTMUCH_EXCLUDE_TRUE,\r
152 > +    NOTMUCH_EXCLUDE_FALSE,\r
153 >      NOTMUCH_EXCLUDE_ALL\r
154 >  } notmuch_exclude_t;\r
155 >  \r
156 > @@ -517,6 +522,15 @@ typedef enum {\r
157 >   * match in at least one non-excluded message.  Otherwise, if set to ALL,\r
158 >   * notmuch_query_search_threads will omit excluded messages from all threads.\r
159 >   *\r
160 > + * If set to FALSE or FLAG then both notmuch_query_search_messages and\r
161 > + * notmuch_query_search_threads will return all matching\r
162 > + * messages/threads regardless of exclude status. If set to FLAG then\r
163 > + * the exclude flag will be set for any excluded message that is\r
164 > + * returned by notmuch_query_search_messages, and the thread counts\r
165 > + * for threads returned by notmuch_query_search_threads will be the\r
166 > + * number of non-excluded messages/matches. Otherwise, if set to\r
167 > + * FALSE, then the exclude status is completely ignored.\r
168 > + *\r
169 >   * The performance difference when calling\r
170 >   * notmuch_query_search_messages should be relatively small (and both\r
171 >   * should be very fast).  However, in some cases,\r
172 > diff --git a/lib/query.cc b/lib/query.cc\r
173 > index 1cc768f..69668a4 100644\r
174 > --- a/lib/query.cc\r
175 > +++ b/lib/query.cc\r
176 > @@ -218,13 +218,15 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
177 >       }\r
178 >       messages->base.excluded_doc_ids = NULL;\r
179 >  \r
180 > -     if (query->exclude_terms) {\r
181 > +     if ((query->omit_excluded != NOTMUCH_EXCLUDE_FALSE) && (query->exclude_terms)) {\r
182 >           exclude_query = _notmuch_exclude_tags (query, final_query);\r
183 >  \r
184 > -         if (query->omit_excluded != NOTMUCH_EXCLUDE_FALSE)\r
185 > +         if (query->omit_excluded == NOTMUCH_EXCLUDE_TRUE ||\r
186 > +             query->omit_excluded == NOTMUCH_EXCLUDE_ALL)\r
187 > +         {\r
188 >               final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
189 >                                            final_query, exclude_query);\r
190 > -         else {\r
191 > +         } else { /* NOTMUCH_EXCLUDE_FLAG */\r
192 >               exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
193 >                                          exclude_query, final_query);\r
194 >  \r
195 > diff --git a/lib/thread.cc b/lib/thread.cc\r
196 > index bc07877..4dcf705 100644\r
197 > --- a/lib/thread.cc\r
198 > +++ b/lib/thread.cc\r
199 > @@ -238,20 +238,22 @@ _thread_add_message (notmuch_thread_t *thread,\r
200 >      char *clean_author;\r
201 >      notmuch_bool_t message_excluded = FALSE;\r
202 >  \r
203 > -    for (tags = notmuch_message_get_tags (message);\r
204 > -      notmuch_tags_valid (tags);\r
205 > -      notmuch_tags_move_to_next (tags))\r
206 > -    {\r
207 > -     tag = notmuch_tags_get (tags);\r
208 > -     /* Is message excluded? */\r
209 > -     for (notmuch_string_node_t *term = exclude_terms->head;\r
210 > -          term != NULL;\r
211 > -          term = term->next)\r
212 > +    if (omit_exclude != NOTMUCH_EXCLUDE_FALSE) {\r
213 > +     for (tags = notmuch_message_get_tags (message);\r
214 > +          notmuch_tags_valid (tags);\r
215 > +          notmuch_tags_move_to_next (tags))\r
216 >       {\r
217 > -         /* We ignore initial 'K'. */\r
218 > -         if (strcmp(tag, (term->string + 1)) == 0) {\r
219 > -             message_excluded = TRUE;\r
220 > -             break;\r
221 > +         tag = notmuch_tags_get (tags);\r
222 > +         /* Is message excluded? */\r
223 > +         for (notmuch_string_node_t *term = exclude_terms->head;\r
224 > +              term != NULL;\r
225 > +              term = term->next)\r
226 > +         {\r
227 > +             /* We ignore initial 'K'. */\r
228 > +             if (strcmp(tag, (term->string + 1)) == 0) {\r
229 > +                 message_excluded = TRUE;\r
230 > +                 break;\r
231 > +             }\r
232 >           }\r
233 >       }\r
234 >      }\r
235 > diff --git a/notmuch-search.c b/notmuch-search.c\r
236 > index 4323201..a20791a 100644\r
237 > --- a/notmuch-search.c\r
238 > +++ b/notmuch-search.c\r
239 > @@ -411,7 +411,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
240 >       for (i = 0; i < search_exclude_tags_length; i++)\r
241 >           notmuch_query_add_tag_exclude (query, search_exclude_tags[i]);\r
242 >       if (exclude == EXCLUDE_FLAG)\r
243 > -         notmuch_query_set_omit_excluded (query, NOTMUCH_EXCLUDE_FALSE);\r
244 > +         notmuch_query_set_omit_excluded (query, NOTMUCH_EXCLUDE_FLAG);\r
245 >       if (exclude == EXCLUDE_ALL)\r
246 >           notmuch_query_set_omit_excluded (query, NOTMUCH_EXCLUDE_ALL);\r
247 >      }\r
248 > -- \r
249 > 1.7.9.1\r