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 68B6B431FAF
\r
6 for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 14:26:53 -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 uKOzCYjiU85q for <notmuch@notmuchmail.org>;
\r
16 Sun, 25 Mar 2012 14:26:52 -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 23A5B431FAE
\r
19 for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 14:26:52 -0700 (PDT)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 0D0F268055; Mon, 26 Mar 2012 00:26:50 +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
26 In-Reply-To: <87limo2xpk.fsf@nikula.org>
\r
27 References: <cover.1332702915.git.jani@nikula.org>
\r
28 <584067da00dd9f04a7f3982b76fd4b4918e4fe61.1332702915.git.jani@nikula.org>
\r
29 <m262dse7f0.fsf@guru.guru-group.fi>
\r
30 <87limo2xpk.fsf@nikula.org>User-Agent: Notmuch/0.12+71~gdacf76b
\r
31 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-unknown-linux-gnu)
\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
33 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
34 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
35 Date: Mon, 26 Mar 2012 00:26:50 +0300
\r
36 Message-ID: <m2398we5id.fsf@guru.guru-group.fi>
\r
38 Content-Type: text/plain; charset=us-ascii
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Sun, 25 Mar 2012 21:26:53 -0000
\r
53 Jani Nikula <jani@nikula.org> writes:
\r
55 > On Sun, 25 Mar 2012 23:45:39 +0300, Tomi Ollila <tomi.ollila@iki.fi> wrote:
\r
56 >> Jani Nikula <jani@nikula.org> writes:
\r
58 >> > Refactor to make tagging code easier to reuse in the future. No
\r
59 >> > functional changes.
\r
61 >> > Signed-off-by: Jani Nikula <jani@nikula.org>
\r
64 >> tag_query() is pretty generic name for a function which (also) does
\r
65 >> tagging operations (adds and removes tags based on tag_ops).
\r
67 > Mmmh, if you think of "tag" as a verb, it fairly accurately describes
\r
68 > what the function does: tag (messages matching this) query (according
\r
69 > given arguments). I don't mind changing, but can't come up with anything
\r
70 > better right now either. notmuch_{search,query}_change_tags()? Meh?
\r
72 Hmmm, yes... -- tag...query... ok, I can live with that if no-one
\r
73 else get same impression I got first...
\r
76 >> If, however, tag_opts != NULL (as is needs to be) but tag_opts[0] == NULL
\r
77 >> (now tag_query() would not do any tagging operations, but
\r
78 >> optimize_tag_query would mangle query string ( '*' to '()' and
\r
79 >> 'any_other' to '( any_other ) and ()' )
\r
81 > I'm not sure I follow you. AFAICT the behaviour does not change from
\r
82 > what it was before, apart from the tag addition and removal being mixed
\r
85 The thing is that notmuch_tag_command () check that there is at least
\r
86 one tagging operation to be done, but tag_query () doesn't do such
\r
89 >> I.e. IMO the function name should be more spesific & the fact that this
\r
90 >> function needs tag changing data in tag_ops array should be documented.
\r
92 > Documentation good. :)
\r
94 ... therefore the requirement that there needs to tagging information
\r
95 in tag_ops is in place.
\r
98 >> Minor thing in patch #1:
\r
100 >> + tag_ops[tag_ops_count].remove = argv[i][0] == '-';
\r
102 >> would be more clearer as:
\r
104 >> + tag_ops[tag_ops_count].remove = (argv[i][0] == '-');
\r
106 > I usually don't add braces where they aren't needed, but can do here.
\r
108 Assigment is much lower in precedence than equality comparison -- but
\r
109 as this is so seldom-used construct, humans read (with understanding)
\r
110 the code faster with this added clarity.
\r
112 >> Everything else LGTM.
\r
114 > Thanks for the review,
\r
124 >> > notmuch-tag.c | 101 ++++++++++++++++++++++++++++++++-------------------------
\r
125 >> > 1 files changed, 57 insertions(+), 44 deletions(-)
\r
127 >> > diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
128 >> > index c39b235..edbfdec 100644
\r
129 >> > --- a/notmuch-tag.c
\r
130 >> > +++ b/notmuch-tag.c
\r
131 >> > @@ -106,6 +106,60 @@ _optimize_tag_query (void *ctx, const char *orig_query_string,
\r
132 >> > return query_string;
\r
136 >> > +tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
\r
137 >> > + tag_operation_t *tag_ops, notmuch_bool_t synchronize_flags)
\r
139 >> > + notmuch_query_t *query;
\r
140 >> > + notmuch_messages_t *messages;
\r
141 >> > + notmuch_message_t *message;
\r
144 >> > + /* Optimize the query so it excludes messages that already have
\r
145 >> > + * the specified set of tags. */
\r
146 >> > + query_string = _optimize_tag_query (ctx, query_string, tag_ops);
\r
147 >> > + if (query_string == NULL) {
\r
148 >> > + fprintf (stderr, "Out of memory.\n");
\r
152 >> > + query = notmuch_query_create (notmuch, query_string);
\r
153 >> > + if (query == NULL) {
\r
154 >> > + fprintf (stderr, "Out of memory.\n");
\r
158 >> > + /* tagging is not interested in any special sort order */
\r
159 >> > + notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
\r
161 >> > + for (messages = notmuch_query_search_messages (query);
\r
162 >> > + notmuch_messages_valid (messages) && !interrupted;
\r
163 >> > + notmuch_messages_move_to_next (messages))
\r
165 >> > + message = notmuch_messages_get (messages);
\r
167 >> > + notmuch_message_freeze (message);
\r
169 >> > + for (i = 0; tag_ops[i].tag; i++) {
\r
170 >> > + if (tag_ops[i].remove)
\r
171 >> > + notmuch_message_remove_tag (message, tag_ops[i].tag);
\r
173 >> > + notmuch_message_add_tag (message, tag_ops[i].tag);
\r
176 >> > + notmuch_message_thaw (message);
\r
178 >> > + if (synchronize_flags)
\r
179 >> > + notmuch_message_tags_to_maildir_flags (message);
\r
181 >> > + notmuch_message_destroy (message);
\r
184 >> > + notmuch_query_destroy (query);
\r
186 >> > + return interrupted;
\r
190 >> > notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
192 >> > @@ -114,12 +168,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
193 >> > char *query_string;
\r
194 >> > notmuch_config_t *config;
\r
195 >> > notmuch_database_t *notmuch;
\r
196 >> > - notmuch_query_t *query;
\r
197 >> > - notmuch_messages_t *messages;
\r
198 >> > - notmuch_message_t *message;
\r
199 >> > struct sigaction action;
\r
200 >> > notmuch_bool_t synchronize_flags;
\r
204 >> > /* Setup our handler for SIGINT */
\r
205 >> > memset (&action, 0, sizeof (struct sigaction));
\r
206 >> > @@ -166,14 +218,6 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
210 >> > - /* Optimize the query so it excludes messages that already have
\r
211 >> > - * the specified set of tags. */
\r
212 >> > - query_string = _optimize_tag_query (ctx, query_string, tag_ops);
\r
213 >> > - if (query_string == NULL) {
\r
214 >> > - fprintf (stderr, "Out of memory.\n");
\r
218 >> > config = notmuch_config_open (ctx, NULL, NULL);
\r
219 >> > if (config == NULL)
\r
221 >> > @@ -185,40 +229,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
223 >> > synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
225 >> > - query = notmuch_query_create (notmuch, query_string);
\r
226 >> > - if (query == NULL) {
\r
227 >> > - fprintf (stderr, "Out of memory.\n");
\r
231 >> > - /* tagging is not interested in any special sort order */
\r
232 >> > - notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
\r
233 >> > + ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);
\r
235 >> > - for (messages = notmuch_query_search_messages (query);
\r
236 >> > - notmuch_messages_valid (messages) && !interrupted;
\r
237 >> > - notmuch_messages_move_to_next (messages))
\r
239 >> > - message = notmuch_messages_get (messages);
\r
241 >> > - notmuch_message_freeze (message);
\r
243 >> > - for (i = 0; tag_ops[i].tag; i++) {
\r
244 >> > - if (tag_ops[i].remove)
\r
245 >> > - notmuch_message_remove_tag (message, tag_ops[i].tag);
\r
247 >> > - notmuch_message_add_tag (message, tag_ops[i].tag);
\r
250 >> > - notmuch_message_thaw (message);
\r
252 >> > - if (synchronize_flags)
\r
253 >> > - notmuch_message_tags_to_maildir_flags (message);
\r
255 >> > - notmuch_message_destroy (message);
\r
258 >> > - notmuch_query_destroy (query);
\r
259 >> > notmuch_database_close (notmuch);
\r
261 >> > - return interrupted;
\r
267 >> > _______________________________________________
\r
268 >> > notmuch mailing list
\r
269 >> > notmuch@notmuchmail.org
\r
270 >> > http://notmuchmail.org/mailman/listinfo/notmuch
\r
271 > _______________________________________________
\r
272 > notmuch mailing list
\r
273 > notmuch@notmuchmail.org
\r
274 > http://notmuchmail.org/mailman/listinfo/notmuch
\r