[PATCH 4/4] Update NEWS for user.other_name
[notmuch-archives.git] / 8a / 795dabc5f1da2e4f85f4b171ec546caa69b75d
1 Return-Path: <amdragon@mit.edu>\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 EE8AF431FD0\r
6         for <notmuch@notmuchmail.org>; Tue,  5 Jul 2011 14:42:47 -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: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id UdcDcrTaTf-R for <notmuch@notmuchmail.org>;\r
16         Tue,  5 Jul 2011 14:42:47 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id 26639431FB6\r
20         for <notmuch@notmuchmail.org>; Tue,  5 Jul 2011 14:42:47 -0700 (PDT)\r
21 X-AuditID: 12074422-b7b19ae000000a1c-73-4e13854a7c62\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id A9.BE.02588.A45831E4; Tue,  5 Jul 2011 17:42:34 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p65LgkYh032021; \r
27         Tue, 5 Jul 2011 17:42:46 -0400\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p65LgiC5024765\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Tue, 5 Jul 2011 17:42:45 -0400 (EDT)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1QeDO7-00040f-00; Tue, 05 Jul 2011 17:42:35 -0400\r
37 Date: Tue, 5 Jul 2011 17:42:34 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Pieter Praet <pieter@praet.org>\r
40 Subject: Re: [PROTO] possible solution for "Race condition for '*' command"\r
41 Message-ID: <20110705214234.GA15360@mit.edu>\r
42 References: <20110703171743.GL15901@mit.edu>\r
43         <1309762318-4530-1-git-send-email-pieter@praet.org>\r
44         <e8c5fbf4-4dfa-461a-8f5c-6c696291a270@email.android.com>\r
45         <87sjqldgr7.fsf@praet.org> <87iprg7dm0.fsf@praet.org>\r
46 MIME-Version: 1.0\r
47 Content-Type: text/plain; charset=us-ascii\r
48 Content-Disposition: inline\r
49 In-Reply-To: <87iprg7dm0.fsf@praet.org>\r
50 User-Agent: Mutt/1.5.20 (2009-06-14)\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IR4hRV1vVqFfYz2D9L2uL6zZnMFr9f32B2\r
53         YPJ4tuoWs0fHvsusAUxRXDYpqTmZZalF+nYJXBn3L35jLbioUzH/SnQD4w2lLkZODgkBE4kX\r
54         nz8yQ9hiEhfurWfrYuTiEBLYxyhxfno/E4SznlGi+WMPK4Rzgkni8NlbjCAtQgJLGCUmrDMF\r
55         sVkEVCT6/m0HG8UmoCGxbf9ysBoRAWWJ009+soPYzAJaEls3fgCLCwt4S3x6OpcFxOYV0JFo\r
56         3f6dDWLmdUaJufcsIeKCEidnPmGB6b3x7yXQRRxAtrTE8n8cIGFOAXWJjf/3go0UBTrh2v52\r
57         tgmMQrOQdM9C0j0LoXsBI/MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXVO93MwSvdSU0k2MoKBm\r
58         d1HawfjzoNIhRgEORiUe3hVGwn5CrIllxZW5hxglOZiURHkNWoBCfEn5KZUZicUZ8UWlOanF\r
59         hxglOJiVRHgjLYByvCmJlVWpRfkwKWkOFiVx3hLv/75CAumJJanZqakFqUUwWRkODiUJ3tUg\r
60         QwWLUtNTK9Iyc0oQ0kwcnCDDeYCGh4LU8BYXJOYWZ6ZD5E8xKkqJ814ESQiAJDJK8+B6YUnn\r
61         FaM40CvCvNdBqniACQuu+xXQYCagwVaJgiCDSxIRUlINjOFpr69I71fiXHbX8K5tkVFX/1TO\r
62         tXeT1ObaZOUzP/Od86Mn3nKZmeLrO1uuhPnxNLP+mu6+lkHq8CJNZeOe+TKb8lmjS4NWXj7y\r
63         YptPGNvGB5yv16ZqbPaaN+P6bbkqteY+zdU7+I/dPb73hWAnb7Plt7dTD2VUdIZdOzxnd4/+\r
64         WYcZ/GmVn5VYijMSDbWYi4oTAdx/9UMVAwAA\r
65 Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.13\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70         <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
77         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Tue, 05 Jul 2011 21:42:48 -0000\r
79 \r
80 Quoth Pieter Praet on Jul 05 at  9:04 pm:\r
81 > On Mon, 04 Jul 2011 20:48:12 +0200, Pieter Praet <pieter@praet.org> wrote:\r
82 > > On Mon, 04 Jul 2011 13:56:26 -0400, Austin Clements <amdragon@MIT.EDU> wrote:\r
83 > > > I should probably emit two lists per thread: one of matched IDs and\r
84 > > > one of unmatched IDs. Tagging a region can then operate on the\r
85 > > > concatenation of these, while * can operate only on the matched\r
86 > > > lists. This should be easy to do. I'll send an updated patch when I'm\r
87 > > > back at a computer.\r
88 > > \r
89 > > The matched MsgIds will be sufficient, as we'll want to operate on\r
90 > > either the matched messages or the entire thread (for which the\r
91 > > `thread-id' property is already present).\r
92 > > \r
93 > > Can't think of a use case for non-matched messages right now,\r
94 > > but if required, we'll just use `set-exclusive-or'.\r
95\r
96 > Wasn't thinking clearly:\r
97\r
98 > You're right, we *will* be needing both a list of matched as well as one\r
99 > of unmatched Message-Id's per result. Otherwise there would still be a\r
100 > potential race condition when tagging with +/-.\r
101 \r
102 Yes, exactly.  (I had originally thought this race was a strict\r
103 superset of the '*' race; I now realize that's not the case, but\r
104 they're related enough that they might as well be addressed together.)\r
105 \r
106 Below is an updated patch that separates the matched and unmatched\r
107 ID's (it's ugly, but no point in cleaning it up since it's a\r
108 prototype).  Now the tag list on each search line is followed by\r
109 something that looks like\r
110 \r
111   (id:x or id:y) or id:z\r
112 \r
113 or just\r
114 \r
115   (id:x or id:y)\r
116 \r
117 where the parenthesized part of the query is for the matched messages\r
118 and the (possibly empty) unparenthesized part is for the non-matched\r
119 messages.  This is designed to be easy for emacs to parse: grab just\r
120 the parenthesized part for the queries used by '*' and the whole thing\r
121 for region tagging queries.  This should also eliminate corner cases\r
122 for pasting together multiple queries with "or".\r
123 \r
124 diff --git a/notmuch-search.c b/notmuch-search.c\r
125 index faccaf7..2288eb7 100644\r
126 --- a/notmuch-search.c\r
127 +++ b/notmuch-search.c\r
128 @@ -190,6 +190,28 @@ format_thread_json (const void *ctx,\r
129      talloc_free (ctx_quote);\r
130  }\r
131  \r
132 +static void\r
133 +show_message_ids (notmuch_messages_t *messages, const char **first,\r
134 +                 notmuch_bool_t match)\r
135 +{\r
136 +    notmuch_message_t *message;\r
137 +\r
138 +    for (;\r
139 +        notmuch_messages_valid (messages);\r
140 +        notmuch_messages_move_to_next (messages)) {\r
141 +       message = notmuch_messages_get (messages);\r
142 +       if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) == match) {\r
143 +           if (*first)\r
144 +               fputs (*first, stdout);\r
145 +           else\r
146 +               fputs (" or ", stdout);\r
147 +           *first = NULL;\r
148 +           printf ("id:\"%s\"", notmuch_message_get_message_id (message));\r
149 +       }\r
150 +       show_message_ids (notmuch_message_get_replies (message), first, match);\r
151 +    }\r
152 +}\r
153 +\r
154  static int\r
155  do_search_threads (const search_format_t *format,\r
156                    notmuch_query_t *query,\r
157 @@ -252,6 +274,22 @@ do_search_threads (const search_format_t *format,\r
158  \r
159             fputs (format->tag_end, stdout);\r
160  \r
161 +           if (format == &format_text) {\r
162 +               notmuch_messages_t *toplevel;\r
163 +               const char *first;\r
164 +\r
165 +               toplevel = notmuch_thread_get_toplevel_messages (thread);\r
166 +               first = " (";\r
167 +               show_message_ids (toplevel, &first, TRUE);\r
168 +               if (first)\r
169 +                   INTERNAL_ERROR ("No matched messages");\r
170 +               fputs (")", stdout);\r
171 +\r
172 +               toplevel = notmuch_thread_get_toplevel_messages (thread);\r
173 +               first = " or ";\r
174 +               show_message_ids (toplevel, &first, FALSE);\r
175 +           }\r
176 +\r
177             fputs (format->item_end, stdout);\r
178         }\r
179  \r
180 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
181 index 6204ae3..5609d02 100644\r
182 --- a/notmuch-tag.c\r
183 +++ b/notmuch-tag.c\r
184 @@ -30,6 +30,36 @@ handle_sigint (unused (int sig))\r
185      interrupted = 1;\r
186  }\r
187  \r
188 +static char*\r
189 +query_string_from_stdin (void *ctx)\r
190 +{\r
191 +    char *query_string = talloc_strdup (ctx, "");\r
192 +    char buf[4096];\r
193 +\r
194 +    if (query_string == NULL) {\r
195 +       fprintf (stderr, "Out of memory.\n");\r
196 +       return NULL;\r
197 +    }\r
198 +\r
199 +    while (1) {\r
200 +       ssize_t r = read(0, buf, sizeof (buf));\r
201 +       if (r < 0) {\r
202 +           fprintf (stderr, "Error reading from stdin: %s\n",\r
203 +                    strerror (errno));\r
204 +           return NULL;\r
205 +       } else if (r == 0) {\r
206 +           break;\r
207 +       }\r
208 +       query_string = talloc_strndup_append (query_string, buf, r);\r
209 +       if (!query_string) {\r
210 +           fprintf (stderr, "Out of memory.\n");\r
211 +           return NULL;\r
212 +       }\r
213 +    }\r
214 +\r
215 +    return query_string;\r
216 +}\r
217 +\r
218  int\r
219  notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
220  {\r
221 @@ -44,6 +74,7 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
222      notmuch_message_t *message;\r
223      struct sigaction action;\r
224      notmuch_bool_t synchronize_flags;\r
225 +    notmuch_bool_t use_stdin = FALSE;\r
226      int i;\r
227  \r
228      /* Setup our handler for SIGINT */\r
229 @@ -70,7 +101,9 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
230             i++;\r
231             break;\r
232         }\r
233 -       if (argv[i][0] == '+') {\r
234 +       if (STRNCMP_LITERAL (argv[i], "--stdin") == 0) {\r
235 +           use_stdin = TRUE;\r
236 +       } else if (argv[i][0] == '+') {\r
237             add_tags[add_tags_count++] = i;\r
238         } else if (argv[i][0] == '-') {\r
239             remove_tags[remove_tags_count++] = i;\r
240 @@ -84,7 +117,13 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
241         return 1;\r
242      }\r
243  \r
244 -    query_string = query_string_from_args (ctx, argc - i, &argv[i]);\r
245 +    if (use_stdin)\r
246 +       query_string = query_string_from_stdin (ctx);\r
247 +    else\r
248 +       query_string = query_string_from_args (ctx, argc - i, &argv[i]);\r
249 +\r
250 +    if (!query_string)\r
251 +       return 1;\r
252  \r
253      if (*query_string == '\0') {\r
254         fprintf (stderr, "Error: notmuch tag requires at least one search term.\n");\r
255 \r