[PATCH v2] cli: abstract dump file open from the dump command
[notmuch-archives.git] / f0 / 4eacfc61d2c00caf51e2e58051cc0352bb1ec5
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 795CC431FBD\r
6         for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 13:48:20 -0800 (PST)\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 ZlZWMFG1c0Cb for <notmuch@notmuchmail.org>;\r
16         Sun, 16 Dec 2012 13:48:19 -0800 (PST)\r
17 Received: from mail-la0-f53.google.com (mail-la0-f53.google.com\r
18         [209.85.215.53]) (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 6F5FF431FAE\r
21         for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 13:48:19 -0800 (PST)\r
22 Received: by mail-la0-f53.google.com with SMTP id w12so4059950lag.26\r
23         for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 13:48:18 -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=eyJai2mtLLAKnWyPMdxZJxsMfADnx7mTUnasHYdQ1lU=;\r
29         b=ewzpzCYAsBHWXNxmprsRC6+xgR5sLuyH1+9a2X0bGRZtU+zCwNwTqMAuOKyRCOEulo\r
30         eYpiWxtW7wgzu0lZ7CsZQQt34fOvtAtm8eKQ+h5k+JLHgiLfrOQ8TbRMsl+fNJzGfPHv\r
31         g8aDJx0WtLiZH/l7R0swkBY03517b1vujr9tpAC/YrdEZ83reg1F8gmrJqTY5b1KR/lX\r
32         iVks08nWI8epJ5Zru1vlbG1T/gkmIGvoVDrx9Fftl8KAdqCsvQUnI1iGC3238Zg8eyc4\r
33         cu99wkl43sjTYfNrx8y6kaXD5YYDqbehJVWKRjm8pJCHXpLpghxqFjH1pnG1BbV6R+Uc\r
34         ecxw==\r
35 Received: by 10.112.29.229 with SMTP id n5mr5150374lbh.130.1355694497595;\r
36         Sun, 16 Dec 2012 13:48:17 -0800 (PST)\r
37 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
38         [80.223.81.27])\r
39         by mx.google.com with ESMTPS id lr20sm4100098lab.17.2012.12.16.13.48.15\r
40         (version=SSLv3 cipher=OTHER); Sun, 16 Dec 2012 13:48:16 -0800 (PST)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
43 Subject: Re: [RFC PATCH] cli: add --remove-all option to "notmuch tag"\r
44 In-Reply-To: <87fw35enmv.fsf@qmul.ac.uk>\r
45 References: <1354572764-28701-1-git-send-email-jani@nikula.org>\r
46         <87fw35enmv.fsf@qmul.ac.uk>\r
47 User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1\r
48         (i686-pc-linux-gnu)\r
49 Date: Sun, 16 Dec 2012 23:48:14 +0200\r
50 Message-ID: <87licxpt29.fsf@nikula.org>\r
51 MIME-Version: 1.0\r
52 Content-Type: text/plain; charset=us-ascii\r
53 X-Gm-Message-State:\r
54  ALoCoQmCOxZYtcZKI2tUdMbHHxWVeCbd+HpmyrlID6OcwTHz71hyTWqIHAoP2m+BJuz0CUBHdOKV\r
55 X-BeenThere: notmuch@notmuchmail.org\r
56 X-Mailman-Version: 2.1.13\r
57 Precedence: list\r
58 List-Id: "Use and development of the notmuch mail system."\r
59         <notmuch.notmuchmail.org>\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
63 List-Post: <mailto:notmuch@notmuchmail.org>\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
67 X-List-Received-Date: Sun, 16 Dec 2012 21:48:20 -0000\r
68 \r
69 On Sun, 16 Dec 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
70 > On Mon, 03 Dec 2012, Jani Nikula <jani@nikula.org> wrote:\r
71 >> Add --remove-all option to "notmuch tag" to remove all tags matching\r
72 >> query before applying the tag changes. This allows removal and\r
73 >> unconditional setting of the tags of a message:\r
74 >>\r
75 >> $ notmuch tag --remove-all id:foo@example.com\r
76 >> $ notmuch tag --remove-all +foo +bar id:foo@example.com\r
77 >>\r
78 >> without having to resort to the complicated (and still quoting broken):\r
79 >>\r
80 >> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') id:foo@example.com\r
81 >> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') +foo +bar id:foo@example.com\r
82 >>\r
83 >> ---\r
84 >>\r
85 >> It's completely untested...\r
86 >>\r
87 >> This is on top of David's batch tagging branch new-tagging at\r
88 >> git://pivot.cs.unb.ca/notmuch.git\r
89 >>\r
90 >> If there's interest, I'll spin a new version with tests and man page\r
91 >> changes after David's stuff has been merged.\r
92 >\r
93 > I like this: the possibility of setting the tags to something seems\r
94 > nice. \r
95 \r
96 Thanks for the feedback; I'll rebase once we're done with the batch\r
97 tagging stuff.\r
98 \r
99 > I am not very keen on the option name but don't have anything much\r
100 > better: maybe --remove-all-first or --set-to? \r
101 \r
102 I still like --remove-all, and, like you say, those aren't much\r
103 better. But we can bikeshed this later. ;)\r
104 \r
105 > Incidentally, does this (or should this) give an error if the user calls\r
106 > --remove-all with -some_tag (as opposed to +some_tag)?\r
107 \r
108 I think not. There are no errors if you do -foo -foo, or remove a tag\r
109 that isn't in any of the messages matching query.\r
110 \r
111 BR,\r
112 Jani.\r
113 \r
114 \r
115 >\r
116 > Best wishes\r
117 >\r
118 > Mark\r
119 >\r
120 >\r
121 >> ---\r
122 >>  notmuch-tag.c |   32 ++++++++++++++++++++------------\r
123 >>  1 file changed, 20 insertions(+), 12 deletions(-)\r
124 >>\r
125 >> diff --git a/notmuch-tag.c b/notmuch-tag.c\r
126 >> index e4fca67..67624cc 100644\r
127 >> --- a/notmuch-tag.c\r
128 >> +++ b/notmuch-tag.c\r
129 >> @@ -119,12 +119,15 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
130 >>      notmuch_messages_t *messages;\r
131 >>      notmuch_message_t *message;\r
132 >>  \r
133 >> -    /* Optimize the query so it excludes messages that already have\r
134 >> -     * the specified set of tags. */\r
135 >> -    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
136 >> -    if (query_string == NULL) {\r
137 >> -    fprintf (stderr, "Out of memory.\n");\r
138 >> -    return 1;\r
139 >> +    if (! (flags & TAG_FLAG_REMOVE_ALL)) {\r
140 >> +    /* Optimize the query so it excludes messages that already\r
141 >> +     * have the specified set of tags. */\r
142 >> +    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
143 >> +    if (query_string == NULL) {\r
144 >> +        fprintf (stderr, "Out of memory.\n");\r
145 >> +        return 1;\r
146 >> +    }\r
147 >> +    flags |= TAG_FLAG_PRE_OPTIMIZED;\r
148 >>      }\r
149 >>  \r
150 >>      query = notmuch_query_create (notmuch, query_string);\r
151 >> @@ -140,7 +143,7 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
152 >>       notmuch_messages_valid (messages) && ! interrupted;\r
153 >>       notmuch_messages_move_to_next (messages)) {\r
154 >>      message = notmuch_messages_get (messages);\r
155 >> -    tag_op_list_apply (message, tag_ops, flags | TAG_FLAG_PRE_OPTIMIZED);\r
156 >> +    tag_op_list_apply (message, tag_ops, flags);\r
157 >>      notmuch_message_destroy (message);\r
158 >>      }\r
159 >>  \r
160 >> @@ -157,8 +160,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
161 >>      notmuch_config_t *config;\r
162 >>      notmuch_database_t *notmuch;\r
163 >>      struct sigaction action;\r
164 >> -    tag_op_flag_t synchronize_flags = TAG_FLAG_NONE;\r
165 >> +    tag_op_flag_t flags = TAG_FLAG_NONE;\r
166 >>      notmuch_bool_t batch = FALSE;\r
167 >> +    notmuch_bool_t remove_all = FALSE;\r
168 >>      FILE *input = stdin;\r
169 >>      char *input_file_name = NULL;\r
170 >>      int i, opt_index;\r
171 >> @@ -174,6 +178,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
172 >>      notmuch_opt_desc_t options[] = {\r
173 >>      { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
174 >>      { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
175 >> +    { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },\r
176 >>      { 0, 0, 0, 0, 0 }\r
177 >>      };\r
178 >>  \r
179 >> @@ -230,7 +235,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
180 >>          }\r
181 >>      }\r
182 >>  \r
183 >> -    if (tag_op_list_size (tag_ops) == 0) {\r
184 >> +    if (tag_op_list_size (tag_ops) == 0 && !remove_all) {\r
185 >>          fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");\r
186 >>          return 1;\r
187 >>      }\r
188 >> @@ -252,7 +257,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
189 >>      return 1;\r
190 >>  \r
191 >>      if (notmuch_config_get_maildir_synchronize_flags (config))\r
192 >> -    synchronize_flags = TAG_FLAG_MAILDIR_SYNC;\r
193 >> +    flags |= TAG_FLAG_MAILDIR_SYNC;\r
194 >> +\r
195 >> +    if (remove_all)\r
196 >> +    flags |= TAG_FLAG_REMOVE_ALL;\r
197 >>  \r
198 >>      if (batch) {\r
199 >>  \r
200 >> @@ -280,14 +288,14 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
201 >>              continue;\r
202 >>  \r
203 >>          if (ret < 0 || tag_query (ctx, notmuch, query_string,\r
204 >> -                                  tag_ops, synchronize_flags))\r
205 >> +                                  tag_ops, flags))\r
206 >>              break;\r
207 >>      }\r
208 >>  \r
209 >>      if (line)\r
210 >>          free (line);\r
211 >>      } else\r
212 >> -    ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);\r
213 >> +    ret = tag_query (ctx, notmuch, query_string, tag_ops, flags);\r
214 >>  \r
215 >>      notmuch_database_destroy (notmuch);\r
216 >>  \r
217 >> -- \r
218 >> 1.7.10.4\r
219 >>\r
220 >> _______________________________________________\r
221 >> notmuch mailing list\r
222 >> notmuch@notmuchmail.org\r
223 >> http://notmuchmail.org/mailman/listinfo/notmuch\r