1 Return-Path: <jani@nikula.org>
\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 A521B431FBC
\r
6 for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:14:17 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 RL+MdqzoNBZC for <notmuch@notmuchmail.org>;
\r
16 Sat, 15 Dec 2012 15:14:17 -0800 (PST)
\r
17 Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com
\r
18 [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id A57DE431FB6
\r
21 for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:14:16 -0800 (PST)
\r
22 Received: by mail-lb0-f181.google.com with SMTP id ge1so3675627lbb.26
\r
23 for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:14:15 -0800 (PST)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=from:to:subject:in-reply-to:references:user-agent:date:message-id
\r
27 :mime-version:content-type:x-gm-message-state;
\r
28 bh=PhiNTEsdr4naal0JV8ExT3nNl7g6gnMPKbDojI8wv7c=;
\r
29 b=KDmMeVMDHTyaNVM04V4s13ImiE8ZBxA4Z7C/1aQULQNeOGlkehAkB+GOjA9jLl6o19
\r
30 7ix1Mp8u0eX0J4idC2XYly4SgcjLcT8oZ4T9aLsP2NI0Y397qPr7oYDCz+imLyfvszyC
\r
31 eAN+ZKXcHGVCbV4SfWTsVnC2ejSo8zxElrN//+Xq/dwwY4+SYD9Q+uKradGhIdylj/8B
\r
32 Qtmqm8EuUYGACaI/CN37ISkOChQT6Xtd34l5Y9wGKm3Ax5s1lz411wakxH2TGZfXyhEo
\r
33 LGqKNUsZJTccOinBeqrdZ136blev8HxQQ1AOSX2QeIL0GwPYLQXgS63iyLw+UB4d99Ot
\r
35 Received: by 10.152.114.65 with SMTP id je1mr6630159lab.33.1355613255147;
\r
36 Sat, 15 Dec 2012 15:14:15 -0800 (PST)
\r
37 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
39 by mx.google.com with ESMTPS id lr20sm3225480lab.17.2012.12.15.15.14.13
\r
40 (version=SSLv3 cipher=OTHER); Sat, 15 Dec 2012 15:14:14 -0800 (PST)
\r
41 From: Jani Nikula <jani@nikula.org>
\r
42 To: david@tethera.net, notmuch@notmuchmail.org
\r
43 Subject: Re: [Patch v7 07/14] cli: add support for batch tagging operations to
\r
45 In-Reply-To: <1355492062-7546-8-git-send-email-david@tethera.net>
\r
46 References: <1355492062-7546-1-git-send-email-david@tethera.net>
\r
47 <1355492062-7546-8-git-send-email-david@tethera.net>
\r
48 User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1
\r
50 Date: Sun, 16 Dec 2012 01:14:07 +0200
\r
51 Message-ID: <87pq2aq56o.fsf@nikula.org>
\r
53 Content-Type: text/plain; charset=us-ascii
\r
55 ALoCoQnEbHTUS7B7ijZOL03mGMXk9vQtvw0xvZDKQ34XtdejnlG2hO7IiPnGbqrY+xJb3wLuvdQ5
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\r
59 List-Id: "Use and development of the notmuch mail system."
\r
60 <notmuch.notmuchmail.org>
\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
64 List-Post: <mailto:notmuch@notmuchmail.org>
\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
68 X-List-Received-Date: Sat, 15 Dec 2012 23:14:17 -0000
\r
70 On Fri, 14 Dec 2012, david@tethera.net wrote:
\r
71 > From: Jani Nikula <jani@nikula.org>
\r
73 > Add support for batch tagging operations through stdin to "notmuch
\r
74 > tag". This can be enabled with the new --batch command line option to
\r
75 > "notmuch tag". The input must consist of lines of the format:
\r
77 > +<tag>|-<tag> [...] [--] <search-term> [...]
\r
79 > Each line is interpreted similarly to "notmuch tag" command line
\r
80 > arguments. The delimiter is one or more spaces ' '. Any characters in
\r
81 > <tag> and <search-term> MAY be hex encoded with %NN where NN is the
\r
82 > hexadecimal value of the character. Any ' ' and '%' characters in
\r
83 > <tag> and <search-term> MUST be hex encoded (using %20 and %25,
\r
84 > respectively). Any characters that are not part of <tag> or
\r
85 > <search-term> MUST NOT be hex encoded.
\r
87 > Leading and trailing space ' ' is ignored. Empty lines and lines
\r
88 > beginning with '#' are ignored.
\r
90 > Signed-off-by: Jani Nikula <jani@nikula.org>
\r
92 > Hacked-like-crazy-by: David Bremner <david@tethera.net>
\r
94 > notmuch-tag.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++------
\r
95 > 1 file changed, 80 insertions(+), 8 deletions(-)
\r
97 > diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
98 > index 13f2268..a81d911 100644
\r
99 > --- a/notmuch-tag.c
\r
100 > +++ b/notmuch-tag.c
\r
101 > @@ -130,6 +130,43 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
\r
102 > return interrupted;
\r
106 > +tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,
\r
109 > + char *line = NULL;
\r
110 > + char *query_string = NULL;
\r
111 > + size_t line_size = 0;
\r
112 > + ssize_t line_len;
\r
114 > + tag_op_list_t *tag_ops;
\r
116 > + tag_ops = tag_op_list_create (ctx);
\r
117 > + if (tag_ops == NULL) {
\r
118 > + fprintf (stderr, "Out of memory.\n");
\r
122 > + while ((line_len = getline (&line, &line_size, input)) != -1 &&
\r
123 > + ! interrupted) {
\r
125 > + ret = parse_tag_line (ctx, line, TAG_FLAG_NONE,
\r
126 > + &query_string, tag_ops);
\r
131 > + if (ret < 0 || tag_query (ctx, notmuch, query_string,
\r
132 > + tag_ops, flags))
\r
135 Hey, your changelog in the cover letter says you fixed the tag_query
\r
136 return value propagation, but it's not here?
\r
151 > notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
153 > @@ -139,6 +176,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
154 > notmuch_database_t *notmuch;
\r
155 > struct sigaction action;
\r
156 > tag_op_flag_t tag_flags = TAG_FLAG_NONE;
\r
157 > + notmuch_bool_t batch = FALSE;
\r
158 > + FILE *input = stdin;
\r
159 > + char *input_file_name = NULL;
\r
163 > /* Setup our handler for SIGINT */
\r
164 > @@ -148,15 +189,43 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
165 > action.sa_flags = SA_RESTART;
\r
166 > sigaction (SIGINT, &action, NULL);
\r
168 > - tag_ops = tag_op_list_create (ctx);
\r
169 > - if (tag_ops == NULL) {
\r
170 > - fprintf (stderr, "Out of memory.\n");
\r
171 > + notmuch_opt_desc_t options[] = {
\r
172 > + { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
\r
173 > + { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
\r
174 > + { 0, 0, 0, 0, 0 }
\r
177 > + opt_index = parse_arguments (argc, argv, options, 1);
\r
178 > + if (opt_index < 0)
\r
181 > + if (input_file_name) {
\r
183 > + input = fopen (input_file_name, "r");
\r
184 > + if (input == NULL) {
\r
185 > + fprintf (stderr, "Error opening %s for reading: %s\n",
\r
186 > + input_file_name, strerror (errno));
\r
191 > - if (parse_tag_command_line (ctx, argc - 1, argv + 1,
\r
192 > - &query_string, tag_ops))
\r
195 > + if (opt_index != argc) {
\r
196 > + fprintf (stderr, "Can't specify both cmdline and stdin!\n");
\r
201 > + tag_ops = tag_op_list_create (ctx);
\r
202 > + if (tag_ops == NULL) {
\r
203 > + fprintf (stderr, "Out of memory.\n");
\r
207 > + if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,
\r
208 > + &query_string, tag_ops))
\r
212 > config = notmuch_config_open (ctx, NULL, NULL);
\r
213 > if (config == NULL)
\r
214 > @@ -169,9 +238,12 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
215 > if (notmuch_config_get_maildir_synchronize_flags (config))
\r
216 > tag_flags |= TAG_FLAG_MAILDIR_SYNC;
\r
218 > - ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);
\r
220 > + ret = tag_file (ctx, notmuch, tag_flags, input);
\r
222 > + ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);
\r
224 > notmuch_database_destroy (notmuch);
\r
227 > + return ret || interrupted;
\r