[PATCH 0/5] Move pick into mainline
[notmuch-archives.git] / 4d / 394d712a29747f6b9e21e492bb6794f6a7b582
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 50C57431FAF\r
6         for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 14:10:55 -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 ZO8g2gEUOwlL for <notmuch@notmuchmail.org>;\r
16         Sun, 25 Mar 2012 14:10:54 -0700 (PDT)\r
17 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-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 F4018431FAE\r
21         for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 14:10:53 -0700 (PDT)\r
22 Received: by lahc1 with SMTP id c1so3793358lah.26\r
23         for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 14:10:52 -0700 (PDT)\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=9hHmtG0snsLviFKubRbN/T7CeOjwgWpQm9ycyJDVLEI=;\r
29         b=mQ6P3qpT9zQrYUFolZcvLVd985gVGNkz0WCT7DsnIfZR938Izd6GIRK0xnrug0qJip\r
30         8yH33JkEdkCZXwC1+H+3t4KhpWjmmltoLmdVmIZ2i4PQoa5fQ/ERpxu/xkWFMW44VofL\r
31         K8GjmC+WoD+PBiZ2revfi+11wK1BaS/7XU7PZihIt9GQ3i0fFLr1E0Y0geWmQFFHGNJi\r
32         yRnTU6zd55GGt3vxqaDmWVp5/Msy0Vz/gJA8W9sHIbjN9G5I4GHA88auXJ/hyexKbpDf\r
33         8VkwrA24oHQxNdhXC4WyxjkWn8Q41wtvnTnMilpVUecYC26gf6ajFGFLD/sLtYV+ZtRe\r
34         F1/Q==\r
35 Received: by 10.112.39.169 with SMTP id q9mr7260399lbk.47.1332709852140;\r
36         Sun, 25 Mar 2012 14:10:52 -0700 (PDT)\r
37 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
38         [84.248.80.253])\r
39         by mx.google.com with ESMTPS id gn6sm19338860lbb.5.2012.03.25.14.10.49\r
40         (version=SSLv3 cipher=OTHER); Sun, 25 Mar 2012 14:10:50 -0700 (PDT)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org\r
43 Subject: Re: [PATCH v2 2/3] cli: refactor "notmuch tag" query tagging into a\r
44         separate function\r
45 In-Reply-To: <m262dse7f0.fsf@guru.guru-group.fi>\r
46 References: <cover.1332702915.git.jani@nikula.org>\r
47         <584067da00dd9f04a7f3982b76fd4b4918e4fe61.1332702915.git.jani@nikula.org>User-Agent:    Notmuch/0.12+71~gdacf76b (http://notmuchmail.org) Emacs/23.3.1\r
48         (x86_64-unknown-linux-gnu) <m262dse7f0.fsf@guru.guru-group.fi>\r
49 User-Agent: Notmuch/0.11.1+295~g780f284 (http://notmuchmail.org) Emacs/23.3.1\r
50         (i686-pc-linux-gnu)\r
51 Date: Mon, 26 Mar 2012 00:10:47 +0300\r
52 Message-ID: <87limo2xpk.fsf@nikula.org>\r
53 MIME-Version: 1.0\r
54 Content-Type: text/plain; charset=us-ascii\r
55 X-Gm-Message-State:\r
56  ALoCoQnMPoT6Xdvpr05QMUWU6EHaJpvE4fPv/jSjO4rjOxghfJqXI8hQsCkbclE1eCgLxz8qVqdl\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Sun, 25 Mar 2012 21:10:55 -0000\r
70 \r
71 On Sun, 25 Mar 2012 23:45:39 +0300, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
72 > Jani Nikula <jani@nikula.org> writes:\r
73\r
74 > > Refactor to make tagging code easier to reuse in the future. No\r
75 > > functional changes.\r
76 > >\r
77 > > Signed-off-by: Jani Nikula <jani@nikula.org>\r
78 > > ---\r
79\r
80 > tag_query() is pretty generic name for a function which (also) does\r
81 > tagging operations (adds and removes tags based on tag_ops).\r
82 \r
83 Mmmh, if you think of "tag" as a verb, it fairly accurately describes\r
84 what the function does: tag (messages matching this) query (according\r
85 given arguments). I don't mind changing, but can't come up with anything\r
86 better right now either. notmuch_{search,query}_change_tags()? Meh?\r
87 \r
88 > If, however, tag_opts != NULL (as is needs to be) but tag_opts[0] == NULL\r
89 > (now tag_query() would not do any tagging operations, but\r
90 > optimize_tag_query would mangle query string ( '*' to '()' and \r
91 > 'any_other' to '( any_other ) and ()' )\r
92 \r
93 I'm not sure I follow you. AFAICT the behaviour does not change from\r
94 what it was before, apart from the tag addition and removal being mixed\r
95 together.\r
96 \r
97 > I.e. IMO the function name should be more spesific & the fact that this\r
98 > function needs tag changing data in tag_ops array should be documented.\r
99 \r
100 Documentation good. :)\r
101 \r
102 > Minor thing in patch #1:\r
103\r
104 >  +        tag_ops[tag_ops_count].remove = argv[i][0] == '-';\r
105\r
106 > would be more clearer as:\r
107\r
108 >  +        tag_ops[tag_ops_count].remove = (argv[i][0] == '-');\r
109 \r
110 I usually don't add braces where they aren't needed, but can do here.\r
111 \r
112 > Everything else LGTM.\r
113 \r
114 Thanks for the review,\r
115 Jani.\r
116 \r
117 \r
118\r
119 > Tomi\r
120\r
121\r
122 > >  notmuch-tag.c |  101 ++++++++++++++++++++++++++++++++-------------------------\r
123 > >  1 files changed, 57 insertions(+), 44 deletions(-)\r
124 > >\r
125 > > diff --git a/notmuch-tag.c b/notmuch-tag.c\r
126 > > index c39b235..edbfdec 100644\r
127 > > --- a/notmuch-tag.c\r
128 > > +++ b/notmuch-tag.c\r
129 > > @@ -106,6 +106,60 @@ _optimize_tag_query (void *ctx, const char *orig_query_string,\r
130 > >      return query_string;\r
131 > >  }\r
132 > >  \r
133 > > +static int\r
134 > > +tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
135 > > +      tag_operation_t *tag_ops, notmuch_bool_t synchronize_flags)\r
136 > > +{\r
137 > > +    notmuch_query_t *query;\r
138 > > +    notmuch_messages_t *messages;\r
139 > > +    notmuch_message_t *message;\r
140 > > +    int i;\r
141 > > +\r
142 > > +    /* Optimize the query so it excludes messages that already have\r
143 > > +     * the specified set of tags. */\r
144 > > +    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
145 > > +    if (query_string == NULL) {\r
146 > > +   fprintf (stderr, "Out of memory.\n");\r
147 > > +   return 1;\r
148 > > +    }\r
149 > > +\r
150 > > +    query = notmuch_query_create (notmuch, query_string);\r
151 > > +    if (query == NULL) {\r
152 > > +   fprintf (stderr, "Out of memory.\n");\r
153 > > +   return 1;\r
154 > > +    }\r
155 > > +\r
156 > > +    /* tagging is not interested in any special sort order */\r
157 > > +    notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
158 > > +\r
159 > > +    for (messages = notmuch_query_search_messages (query);\r
160 > > +    notmuch_messages_valid (messages) && !interrupted;\r
161 > > +    notmuch_messages_move_to_next (messages))\r
162 > > +    {\r
163 > > +   message = notmuch_messages_get (messages);\r
164 > > +\r
165 > > +   notmuch_message_freeze (message);\r
166 > > +\r
167 > > +   for (i = 0; tag_ops[i].tag; i++) {\r
168 > > +       if (tag_ops[i].remove)\r
169 > > +           notmuch_message_remove_tag (message, tag_ops[i].tag);\r
170 > > +       else\r
171 > > +           notmuch_message_add_tag (message, tag_ops[i].tag);\r
172 > > +   }\r
173 > > +\r
174 > > +   notmuch_message_thaw (message);\r
175 > > +\r
176 > > +   if (synchronize_flags)\r
177 > > +       notmuch_message_tags_to_maildir_flags (message);\r
178 > > +\r
179 > > +   notmuch_message_destroy (message);\r
180 > > +    }\r
181 > > +\r
182 > > +    notmuch_query_destroy (query);\r
183 > > +\r
184 > > +    return interrupted;\r
185 > > +}\r
186 > > +\r
187 > >  int\r
188 > >  notmuch_tag_command (void *ctx, int argc, char *argv[])\r
189 > >  {\r
190 > > @@ -114,12 +168,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
191 > >      char *query_string;\r
192 > >      notmuch_config_t *config;\r
193 > >      notmuch_database_t *notmuch;\r
194 > > -    notmuch_query_t *query;\r
195 > > -    notmuch_messages_t *messages;\r
196 > > -    notmuch_message_t *message;\r
197 > >      struct sigaction action;\r
198 > >      notmuch_bool_t synchronize_flags;\r
199 > >      int i;\r
200 > > +    int ret;\r
201 > >  \r
202 > >      /* Setup our handler for SIGINT */\r
203 > >      memset (&action, 0, sizeof (struct sigaction));\r
204 > > @@ -166,14 +218,6 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
205 > >     return 1;\r
206 > >      }\r
207 > >  \r
208 > > -    /* Optimize the query so it excludes messages that already have\r
209 > > -     * the specified set of tags. */\r
210 > > -    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
211 > > -    if (query_string == NULL) {\r
212 > > -   fprintf (stderr, "Out of memory.\n");\r
213 > > -   return 1;\r
214 > > -    }\r
215 > > -\r
216 > >      config = notmuch_config_open (ctx, NULL, NULL);\r
217 > >      if (config == NULL)\r
218 > >     return 1;\r
219 > > @@ -185,40 +229,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
220 > >  \r
221 > >      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
222 > >  \r
223 > > -    query = notmuch_query_create (notmuch, query_string);\r
224 > > -    if (query == NULL) {\r
225 > > -   fprintf (stderr, "Out of memory.\n");\r
226 > > -   return 1;\r
227 > > -    }\r
228 > > -\r
229 > > -    /* tagging is not interested in any special sort order */\r
230 > > -    notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
231 > > +    ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);\r
232 > >  \r
233 > > -    for (messages = notmuch_query_search_messages (query);\r
234 > > -    notmuch_messages_valid (messages) && !interrupted;\r
235 > > -    notmuch_messages_move_to_next (messages))\r
236 > > -    {\r
237 > > -   message = notmuch_messages_get (messages);\r
238 > > -\r
239 > > -   notmuch_message_freeze (message);\r
240 > > -\r
241 > > -   for (i = 0; tag_ops[i].tag; i++) {\r
242 > > -       if (tag_ops[i].remove)\r
243 > > -           notmuch_message_remove_tag (message, tag_ops[i].tag);\r
244 > > -       else\r
245 > > -           notmuch_message_add_tag (message, tag_ops[i].tag);\r
246 > > -   }\r
247 > > -\r
248 > > -   notmuch_message_thaw (message);\r
249 > > -\r
250 > > -   if (synchronize_flags)\r
251 > > -       notmuch_message_tags_to_maildir_flags (message);\r
252 > > -\r
253 > > -   notmuch_message_destroy (message);\r
254 > > -    }\r
255 > > -\r
256 > > -    notmuch_query_destroy (query);\r
257 > >      notmuch_database_close (notmuch);\r
258 > >  \r
259 > > -    return interrupted;\r
260 > > +    return ret;\r
261 > >  }\r
262 > > -- \r
263 > > 1.7.5.4\r
264 > >\r
265 > > _______________________________________________\r
266 > > notmuch mailing list\r
267 > > notmuch@notmuchmail.org\r
268 > > http://notmuchmail.org/mailman/listinfo/notmuch\r