1 Return-Path: <tomi.ollila@iki.fi>
\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 3CA5F431FAF
\r
6 for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 13:45:42 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 e-2IhMkHqoPm for <notmuch@notmuchmail.org>;
\r
16 Sun, 25 Mar 2012 13:45:41 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 317EB431FAE
\r
19 for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 13:45:41 -0700 (PDT)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id CD4E668055; Sun, 25 Mar 2012 23:45:39 +0300 (EEST)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org
\r
24 Subject: Re: [PATCH v2 2/3] cli: refactor "notmuch tag" query tagging into a
\r
27 <584067da00dd9f04a7f3982b76fd4b4918e4fe61.1332702915.git.jani@nikula.org>
\r
28 References: <cover.1332702915.git.jani@nikula.org>
\r
29 <584067da00dd9f04a7f3982b76fd4b4918e4fe61.1332702915.git.jani@nikula.org>User-Agent: Notmuch/0.12+71~gdacf76b (http://notmuchmail.org) Emacs/23.3.1
\r
30 (x86_64-unknown-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Sun, 25 Mar 2012 23:45:39 +0300
\r
35 Message-ID: <m262dse7f0.fsf@guru.guru-group.fi>
\r
37 Content-Type: text/plain; charset=us-ascii
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Sun, 25 Mar 2012 20:45:42 -0000
\r
52 Jani Nikula <jani@nikula.org> writes:
\r
54 > Refactor to make tagging code easier to reuse in the future. No
\r
55 > functional changes.
\r
57 > Signed-off-by: Jani Nikula <jani@nikula.org>
\r
60 tag_query() is pretty generic name for a function which (also) does
\r
61 tagging operations (adds and removes tags based on tag_ops).
\r
63 If, however, tag_opts != NULL (as is needs to be) but tag_opts[0] == NULL
\r
64 (now tag_query() would not do any tagging operations, but
\r
65 optimize_tag_query would mangle query string ( '*' to '()' and
\r
66 'any_other' to '( any_other ) and ()' )
\r
68 I.e. IMO the function name should be more spesific & the fact that this
\r
69 function needs tag changing data in tag_ops array should be documented.
\r
73 Minor thing in patch #1:
\r
75 + tag_ops[tag_ops_count].remove = argv[i][0] == '-';
\r
77 would be more clearer as:
\r
79 + tag_ops[tag_ops_count].remove = (argv[i][0] == '-');
\r
83 Everything else LGTM.
\r
88 > notmuch-tag.c | 101 ++++++++++++++++++++++++++++++++-------------------------
\r
89 > 1 files changed, 57 insertions(+), 44 deletions(-)
\r
91 > diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
92 > index c39b235..edbfdec 100644
\r
93 > --- a/notmuch-tag.c
\r
94 > +++ b/notmuch-tag.c
\r
95 > @@ -106,6 +106,60 @@ _optimize_tag_query (void *ctx, const char *orig_query_string,
\r
96 > return query_string;
\r
100 > +tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
\r
101 > + tag_operation_t *tag_ops, notmuch_bool_t synchronize_flags)
\r
103 > + notmuch_query_t *query;
\r
104 > + notmuch_messages_t *messages;
\r
105 > + notmuch_message_t *message;
\r
108 > + /* Optimize the query so it excludes messages that already have
\r
109 > + * the specified set of tags. */
\r
110 > + query_string = _optimize_tag_query (ctx, query_string, tag_ops);
\r
111 > + if (query_string == NULL) {
\r
112 > + fprintf (stderr, "Out of memory.\n");
\r
116 > + query = notmuch_query_create (notmuch, query_string);
\r
117 > + if (query == NULL) {
\r
118 > + fprintf (stderr, "Out of memory.\n");
\r
122 > + /* tagging is not interested in any special sort order */
\r
123 > + notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
\r
125 > + for (messages = notmuch_query_search_messages (query);
\r
126 > + notmuch_messages_valid (messages) && !interrupted;
\r
127 > + notmuch_messages_move_to_next (messages))
\r
129 > + message = notmuch_messages_get (messages);
\r
131 > + notmuch_message_freeze (message);
\r
133 > + for (i = 0; tag_ops[i].tag; i++) {
\r
134 > + if (tag_ops[i].remove)
\r
135 > + notmuch_message_remove_tag (message, tag_ops[i].tag);
\r
137 > + notmuch_message_add_tag (message, tag_ops[i].tag);
\r
140 > + notmuch_message_thaw (message);
\r
142 > + if (synchronize_flags)
\r
143 > + notmuch_message_tags_to_maildir_flags (message);
\r
145 > + notmuch_message_destroy (message);
\r
148 > + notmuch_query_destroy (query);
\r
150 > + return interrupted;
\r
154 > notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
156 > @@ -114,12 +168,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
157 > char *query_string;
\r
158 > notmuch_config_t *config;
\r
159 > notmuch_database_t *notmuch;
\r
160 > - notmuch_query_t *query;
\r
161 > - notmuch_messages_t *messages;
\r
162 > - notmuch_message_t *message;
\r
163 > struct sigaction action;
\r
164 > notmuch_bool_t synchronize_flags;
\r
168 > /* Setup our handler for SIGINT */
\r
169 > memset (&action, 0, sizeof (struct sigaction));
\r
170 > @@ -166,14 +218,6 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
174 > - /* Optimize the query so it excludes messages that already have
\r
175 > - * the specified set of tags. */
\r
176 > - query_string = _optimize_tag_query (ctx, query_string, tag_ops);
\r
177 > - if (query_string == NULL) {
\r
178 > - fprintf (stderr, "Out of memory.\n");
\r
182 > config = notmuch_config_open (ctx, NULL, NULL);
\r
183 > if (config == NULL)
\r
185 > @@ -185,40 +229,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
187 > synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
189 > - query = notmuch_query_create (notmuch, query_string);
\r
190 > - if (query == NULL) {
\r
191 > - fprintf (stderr, "Out of memory.\n");
\r
195 > - /* tagging is not interested in any special sort order */
\r
196 > - notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
\r
197 > + ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);
\r
199 > - for (messages = notmuch_query_search_messages (query);
\r
200 > - notmuch_messages_valid (messages) && !interrupted;
\r
201 > - notmuch_messages_move_to_next (messages))
\r
203 > - message = notmuch_messages_get (messages);
\r
205 > - notmuch_message_freeze (message);
\r
207 > - for (i = 0; tag_ops[i].tag; i++) {
\r
208 > - if (tag_ops[i].remove)
\r
209 > - notmuch_message_remove_tag (message, tag_ops[i].tag);
\r
211 > - notmuch_message_add_tag (message, tag_ops[i].tag);
\r
214 > - notmuch_message_thaw (message);
\r
216 > - if (synchronize_flags)
\r
217 > - notmuch_message_tags_to_maildir_flags (message);
\r
219 > - notmuch_message_destroy (message);
\r
222 > - notmuch_query_destroy (query);
\r
223 > notmuch_database_close (notmuch);
\r
225 > - return interrupted;
\r
231 > _______________________________________________
\r
232 > notmuch mailing list
\r
233 > notmuch@notmuchmail.org
\r
234 > http://notmuchmail.org/mailman/listinfo/notmuch
\r