Re: [PATCH 1/2] Add Google Inc. to AUTHORS as a contributor.
[notmuch-archives.git] / 54 / bd89fd3aff18403a8df50fce7db300611bd16b
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 199E4431FAF\r
6         for <notmuch@notmuchmail.org>; Mon, 26 Mar 2012 00:38: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 lZu4Blej6gwZ for <notmuch@notmuchmail.org>;\r
16         Mon, 26 Mar 2012 00:38:53 -0700 (PDT)\r
17 Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com\r
18         [209.85.216.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 BED14431FAE\r
21         for <notmuch@notmuchmail.org>; Mon, 26 Mar 2012 00:38:53 -0700 (PDT)\r
22 Received: by qcsk26 with SMTP id k26so3922863qcs.26\r
23         for <notmuch@notmuchmail.org>; Mon, 26 Mar 2012 00:38: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=V7j4+ucUhifx3J1KTLdK4+EMoK6sy/GsEoEyPscaQLE=;\r
29         b=gUESWePjwYXxff94eBnJDvWZrKFDdZwMPJ6qLH4XP94i608mOMt133KC1Aqb71VTfu\r
30         MbVXRrTzKVwshxFERlZR+em4r4JluWMQWKeTSjPeaVo8choQGJLkZy56o17/ov/pG5/8\r
31         +m31WbLJ8nUuYqMV8ox8KbfjVZr7wtxf7vM70BdV9HxzMzF2IZy3922xlW+mJUdxcP9c\r
32         s+r4AIZM6Wt08iMjPc708OrkiSqPLfzG9oOMU756ZMpmoi6MGCspVDv6+Ck1F7RQQnFP\r
33         t/SM5AItaoqlxngyKy+X6xGThkYCHuO8rIZN0c0f7y+erHLIdTrXLIeN+488Q9GU8krS\r
34         Sk1A==\r
35 Received: by 10.224.187.2 with SMTP id cu2mr26045500qab.88.1332747531994;\r
36         Mon, 26 Mar 2012 00:38:51 -0700 (PDT)\r
37 Received: from localhost (nikula.org. [92.243.24.172])\r
38         by mx.google.com with ESMTPS id cv8sm358404qab.12.2012.03.26.00.38.49\r
39         (version=SSLv3 cipher=OTHER); Mon, 26 Mar 2012 00:38:51 -0700 (PDT)\r
40 From: Jani Nikula <jani@nikula.org>\r
41 To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org\r
42 Subject: Re: [PATCH v2 2/3] cli: refactor "notmuch tag" query tagging into a\r
43         separate function\r
44 In-Reply-To: <m2398we5id.fsf@guru.guru-group.fi>\r
45 References: <cover.1332702915.git.jani@nikula.org>\r
46         <584067da00dd9f04a7f3982b76fd4b4918e4fe61.1332702915.git.jani@nikula.org>\r
47         <m262dse7f0.fsf@guru.guru-group.fi>\r
48         <87limo2xpk.fsf@nikula.org>User-Agent: Notmuch/0.12+71~gdacf76b\r
49         (http://notmuchmail.org) Emacs/23.3.1\r
50         (x86_64-unknown-linux-gnu) <m2398we5id.fsf@guru.guru-group.fi>\r
51 User-Agent: Notmuch/0.11.1+222~ga47a98c (http://notmuchmail.org) Emacs/23.1.1\r
52         (i686-pc-linux-gnu)\r
53 Date: Mon, 26 Mar 2012 07:38:47 +0000\r
54 Message-ID: <87ty1b4xrs.fsf@nikula.org>\r
55 MIME-Version: 1.0\r
56 Content-Type: text/plain; charset=us-ascii\r
57 X-Gm-Message-State:\r
58  ALoCoQkemWZT0HI2+q2nD9ShizwmMfsODTc4VDhzWfcKaU6t+6L12Vf50nS3WmAXhXHd0PHJBjOd\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: Mon, 26 Mar 2012 07:38:55 -0000\r
72 \r
73 On Mon, 26 Mar 2012 00:26:50 +0300, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
74 > Jani Nikula <jani@nikula.org> writes:\r
75\r
76 > > On Sun, 25 Mar 2012 23:45:39 +0300, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
77 > >> Jani Nikula <jani@nikula.org> writes:\r
78 > >> \r
79 > >> > Refactor to make tagging code easier to reuse in the future. No\r
80 > >> > functional changes.\r
81 > >> >\r
82 > >> > Signed-off-by: Jani Nikula <jani@nikula.org>\r
83 > >> > ---\r
84 > >> \r
85 > >> tag_query() is pretty generic name for a function which (also) does\r
86 > >> tagging operations (adds and removes tags based on tag_ops).\r
87 > >\r
88 > > Mmmh, if you think of "tag" as a verb, it fairly accurately describes\r
89 > > what the function does: tag (messages matching this) query (according\r
90 > > given arguments). I don't mind changing, but can't come up with anything\r
91 > > better right now either. notmuch_{search,query}_change_tags()? Meh?\r
92\r
93 > Hmmm, yes... -- tag...query... ok, I can live with that if no-one\r
94 > else get same impression I got first...\r
95\r
96 > >\r
97 > >> If, however, tag_opts != NULL (as is needs to be) but tag_opts[0] == NULL\r
98 > >> (now tag_query() would not do any tagging operations, but\r
99 > >> optimize_tag_query would mangle query string ( '*' to '()' and \r
100 > >> 'any_other' to '( any_other ) and ()' )\r
101 > >\r
102 > > I'm not sure I follow you. AFAICT the behaviour does not change from\r
103 > > what it was before, apart from the tag addition and removal being mixed\r
104 > > together.\r
105\r
106 > The thing is that notmuch_tag_command () check that there is at least\r
107 > one tagging operation to be done, but tag_query () doesn't do such\r
108 > checking...\r
109\r
110 > >> I.e. IMO the function name should be more spesific & the fact that this\r
111 > >> function needs tag changing data in tag_ops array should be documented.\r
112 > >\r
113 > > Documentation good. :)\r
114\r
115 > ... therefore the requirement that there needs to tagging information\r
116 > in tag_ops is in place.\r
117 \r
118 Actually, no. In the future (the follow-up patches are in my local\r
119 tree...) tag_query() should work also when there are no tagging\r
120 operations. I'll either need to fix tag_query() or _optimize_tag_query()\r
121 to handle this gracefully. Thanks for spelling this out for me! :)\r
122 \r
123 > >> Minor thing in patch #1:\r
124 > >> \r
125 > >>  +     tag_ops[tag_ops_count].remove = argv[i][0] == '-';\r
126 > >> \r
127 > >> would be more clearer as:\r
128 > >> \r
129 > >>  +     tag_ops[tag_ops_count].remove = (argv[i][0] == '-');\r
130 > >\r
131 > > I usually don't add braces where they aren't needed, but can do here.\r
132\r
133 > Assigment is much lower in precedence than equality comparison -- but\r
134 > as this is so seldom-used construct, humans read (with understanding)\r
135 > the code faster with this added clarity.\r
136 \r
137 Sounds reasonable.\r
138 \r
139 BR,\r
140 Jani.\r
141 \r
142 \r
143 \r
144\r
145 > >> Everything else LGTM.\r
146 > >\r
147 > > Thanks for the review,\r
148 > > Jani.\r
149 > >\r
150 > >> \r
151 > >> Tomi\r
152\r
153 > Tomi\r
154\r
155 > >> \r
156 > >> \r
157 > >> >  notmuch-tag.c |  101 ++++++++++++++++++++++++++++++++-------------------------\r
158 > >> >  1 files changed, 57 insertions(+), 44 deletions(-)\r
159 > >> >\r
160 > >> > diff --git a/notmuch-tag.c b/notmuch-tag.c\r
161 > >> > index c39b235..edbfdec 100644\r
162 > >> > --- a/notmuch-tag.c\r
163 > >> > +++ b/notmuch-tag.c\r
164 > >> > @@ -106,6 +106,60 @@ _optimize_tag_query (void *ctx, const char *orig_query_string,\r
165 > >> >      return query_string;\r
166 > >> >  }\r
167 > >> >  \r
168 > >> > +static int\r
169 > >> > +tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
170 > >> > +           tag_operation_t *tag_ops, notmuch_bool_t synchronize_flags)\r
171 > >> > +{\r
172 > >> > +    notmuch_query_t *query;\r
173 > >> > +    notmuch_messages_t *messages;\r
174 > >> > +    notmuch_message_t *message;\r
175 > >> > +    int i;\r
176 > >> > +\r
177 > >> > +    /* Optimize the query so it excludes messages that already have\r
178 > >> > +     * the specified set of tags. */\r
179 > >> > +    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
180 > >> > +    if (query_string == NULL) {\r
181 > >> > +        fprintf (stderr, "Out of memory.\n");\r
182 > >> > +        return 1;\r
183 > >> > +    }\r
184 > >> > +\r
185 > >> > +    query = notmuch_query_create (notmuch, query_string);\r
186 > >> > +    if (query == NULL) {\r
187 > >> > +        fprintf (stderr, "Out of memory.\n");\r
188 > >> > +        return 1;\r
189 > >> > +    }\r
190 > >> > +\r
191 > >> > +    /* tagging is not interested in any special sort order */\r
192 > >> > +    notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
193 > >> > +\r
194 > >> > +    for (messages = notmuch_query_search_messages (query);\r
195 > >> > +         notmuch_messages_valid (messages) && !interrupted;\r
196 > >> > +         notmuch_messages_move_to_next (messages))\r
197 > >> > +    {\r
198 > >> > +        message = notmuch_messages_get (messages);\r
199 > >> > +\r
200 > >> > +        notmuch_message_freeze (message);\r
201 > >> > +\r
202 > >> > +        for (i = 0; tag_ops[i].tag; i++) {\r
203 > >> > +            if (tag_ops[i].remove)\r
204 > >> > +                notmuch_message_remove_tag (message, tag_ops[i].tag);\r
205 > >> > +            else\r
206 > >> > +                notmuch_message_add_tag (message, tag_ops[i].tag);\r
207 > >> > +        }\r
208 > >> > +\r
209 > >> > +        notmuch_message_thaw (message);\r
210 > >> > +\r
211 > >> > +        if (synchronize_flags)\r
212 > >> > +            notmuch_message_tags_to_maildir_flags (message);\r
213 > >> > +\r
214 > >> > +        notmuch_message_destroy (message);\r
215 > >> > +    }\r
216 > >> > +\r
217 > >> > +    notmuch_query_destroy (query);\r
218 > >> > +\r
219 > >> > +    return interrupted;\r
220 > >> > +}\r
221 > >> > +\r
222 > >> >  int\r
223 > >> >  notmuch_tag_command (void *ctx, int argc, char *argv[])\r
224 > >> >  {\r
225 > >> > @@ -114,12 +168,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
226 > >> >      char *query_string;\r
227 > >> >      notmuch_config_t *config;\r
228 > >> >      notmuch_database_t *notmuch;\r
229 > >> > -    notmuch_query_t *query;\r
230 > >> > -    notmuch_messages_t *messages;\r
231 > >> > -    notmuch_message_t *message;\r
232 > >> >      struct sigaction action;\r
233 > >> >      notmuch_bool_t synchronize_flags;\r
234 > >> >      int i;\r
235 > >> > +    int ret;\r
236 > >> >  \r
237 > >> >      /* Setup our handler for SIGINT */\r
238 > >> >      memset (&action, 0, sizeof (struct sigaction));\r
239 > >> > @@ -166,14 +218,6 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
240 > >> >          return 1;\r
241 > >> >      }\r
242 > >> >  \r
243 > >> > -    /* Optimize the query so it excludes messages that already have\r
244 > >> > -     * the specified set of tags. */\r
245 > >> > -    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
246 > >> > -    if (query_string == NULL) {\r
247 > >> > -        fprintf (stderr, "Out of memory.\n");\r
248 > >> > -        return 1;\r
249 > >> > -    }\r
250 > >> > -\r
251 > >> >      config = notmuch_config_open (ctx, NULL, NULL);\r
252 > >> >      if (config == NULL)\r
253 > >> >          return 1;\r
254 > >> > @@ -185,40 +229,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
255 > >> >  \r
256 > >> >      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
257 > >> >  \r
258 > >> > -    query = notmuch_query_create (notmuch, query_string);\r
259 > >> > -    if (query == NULL) {\r
260 > >> > -        fprintf (stderr, "Out of memory.\n");\r
261 > >> > -        return 1;\r
262 > >> > -    }\r
263 > >> > -\r
264 > >> > -    /* tagging is not interested in any special sort order */\r
265 > >> > -    notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
266 > >> > +    ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);\r
267 > >> >  \r
268 > >> > -    for (messages = notmuch_query_search_messages (query);\r
269 > >> > -         notmuch_messages_valid (messages) && !interrupted;\r
270 > >> > -         notmuch_messages_move_to_next (messages))\r
271 > >> > -    {\r
272 > >> > -        message = notmuch_messages_get (messages);\r
273 > >> > -\r
274 > >> > -        notmuch_message_freeze (message);\r
275 > >> > -\r
276 > >> > -        for (i = 0; tag_ops[i].tag; i++) {\r
277 > >> > -            if (tag_ops[i].remove)\r
278 > >> > -                notmuch_message_remove_tag (message, tag_ops[i].tag);\r
279 > >> > -            else\r
280 > >> > -                notmuch_message_add_tag (message, tag_ops[i].tag);\r
281 > >> > -        }\r
282 > >> > -\r
283 > >> > -        notmuch_message_thaw (message);\r
284 > >> > -\r
285 > >> > -        if (synchronize_flags)\r
286 > >> > -            notmuch_message_tags_to_maildir_flags (message);\r
287 > >> > -\r
288 > >> > -        notmuch_message_destroy (message);\r
289 > >> > -    }\r
290 > >> > -\r
291 > >> > -    notmuch_query_destroy (query);\r
292 > >> >      notmuch_database_close (notmuch);\r
293 > >> >  \r
294 > >> > -    return interrupted;\r
295 > >> > +    return ret;\r
296 > >> >  }\r
297 > >> > -- \r
298 > >> > 1.7.5.4\r
299 > >> >\r
300 > >> > _______________________________________________\r
301 > >> > notmuch mailing list\r
302 > >> > notmuch@notmuchmail.org\r
303 > >> > http://notmuchmail.org/mailman/listinfo/notmuch\r
304 > > _______________________________________________\r
305 > > notmuch mailing list\r
306 > > notmuch@notmuchmail.org\r
307 > > http://notmuchmail.org/mailman/listinfo/notmuch\r