Re: [PATCH] emacs: Compute build dependencies to fix byte compile issues
[notmuch-archives.git] / cd / bd3c7cdf5d5859ff41132b2f43d81a240cd470
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 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
25         separate function\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
37 MIME-Version: 1.0\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
41 Precedence: list\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
52 \r
53 Jani Nikula <jani@nikula.org> writes:\r
54 \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
57 >> \r
58 >> > Refactor to make tagging code easier to reuse in the future. No\r
59 >> > functional changes.\r
60 >> >\r
61 >> > Signed-off-by: Jani Nikula <jani@nikula.org>\r
62 >> > ---\r
63 >> \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
66 >\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
71 \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
74 \r
75 >\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
80 >\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
83 > together.\r
84 \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
87 checking...\r
88 \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
91 >\r
92 > Documentation good. :)\r
93 \r
94 ... therefore the requirement that there needs to tagging information\r
95 in tag_ops is in place.\r
96 \r
97 >\r
98 >> Minor thing in patch #1:\r
99 >> \r
100 >>  +       tag_ops[tag_ops_count].remove = argv[i][0] == '-';\r
101 >> \r
102 >> would be more clearer as:\r
103 >> \r
104 >>  +       tag_ops[tag_ops_count].remove = (argv[i][0] == '-');\r
105 >\r
106 > I usually don't add braces where they aren't needed, but can do here.\r
107 \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
111 \r
112 >> Everything else LGTM.\r
113 >\r
114 > Thanks for the review,\r
115 > Jani.\r
116 >\r
117 >> \r
118 >> Tomi\r
119 \r
120 Tomi\r
121 \r
122 >> \r
123 >> \r
124 >> >  notmuch-tag.c |  101 ++++++++++++++++++++++++++++++++-------------------------\r
125 >> >  1 files changed, 57 insertions(+), 44 deletions(-)\r
126 >> >\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
133 >> >  }\r
134 >> >  \r
135 >> > +static int\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
138 >> > +{\r
139 >> > +    notmuch_query_t *query;\r
140 >> > +    notmuch_messages_t *messages;\r
141 >> > +    notmuch_message_t *message;\r
142 >> > +    int i;\r
143 >> > +\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
149 >> > +  return 1;\r
150 >> > +    }\r
151 >> > +\r
152 >> > +    query = notmuch_query_create (notmuch, query_string);\r
153 >> > +    if (query == NULL) {\r
154 >> > +  fprintf (stderr, "Out of memory.\n");\r
155 >> > +  return 1;\r
156 >> > +    }\r
157 >> > +\r
158 >> > +    /* tagging is not interested in any special sort order */\r
159 >> > +    notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
160 >> > +\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
164 >> > +    {\r
165 >> > +  message = notmuch_messages_get (messages);\r
166 >> > +\r
167 >> > +  notmuch_message_freeze (message);\r
168 >> > +\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
172 >> > +      else\r
173 >> > +          notmuch_message_add_tag (message, tag_ops[i].tag);\r
174 >> > +  }\r
175 >> > +\r
176 >> > +  notmuch_message_thaw (message);\r
177 >> > +\r
178 >> > +  if (synchronize_flags)\r
179 >> > +      notmuch_message_tags_to_maildir_flags (message);\r
180 >> > +\r
181 >> > +  notmuch_message_destroy (message);\r
182 >> > +    }\r
183 >> > +\r
184 >> > +    notmuch_query_destroy (query);\r
185 >> > +\r
186 >> > +    return interrupted;\r
187 >> > +}\r
188 >> > +\r
189 >> >  int\r
190 >> >  notmuch_tag_command (void *ctx, int argc, char *argv[])\r
191 >> >  {\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
201 >> >      int i;\r
202 >> > +    int ret;\r
203 >> >  \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
207 >> >    return 1;\r
208 >> >      }\r
209 >> >  \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
215 >> > -  return 1;\r
216 >> > -    }\r
217 >> > -\r
218 >> >      config = notmuch_config_open (ctx, NULL, NULL);\r
219 >> >      if (config == NULL)\r
220 >> >    return 1;\r
221 >> > @@ -185,40 +229,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
222 >> >  \r
223 >> >      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
224 >> >  \r
225 >> > -    query = notmuch_query_create (notmuch, query_string);\r
226 >> > -    if (query == NULL) {\r
227 >> > -  fprintf (stderr, "Out of memory.\n");\r
228 >> > -  return 1;\r
229 >> > -    }\r
230 >> > -\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
234 >> >  \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
238 >> > -    {\r
239 >> > -  message = notmuch_messages_get (messages);\r
240 >> > -\r
241 >> > -  notmuch_message_freeze (message);\r
242 >> > -\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
246 >> > -      else\r
247 >> > -          notmuch_message_add_tag (message, tag_ops[i].tag);\r
248 >> > -  }\r
249 >> > -\r
250 >> > -  notmuch_message_thaw (message);\r
251 >> > -\r
252 >> > -  if (synchronize_flags)\r
253 >> > -      notmuch_message_tags_to_maildir_flags (message);\r
254 >> > -\r
255 >> > -  notmuch_message_destroy (message);\r
256 >> > -    }\r
257 >> > -\r
258 >> > -    notmuch_query_destroy (query);\r
259 >> >      notmuch_database_close (notmuch);\r
260 >> >  \r
261 >> > -    return interrupted;\r
262 >> > +    return ret;\r
263 >> >  }\r
264 >> > -- \r
265 >> > 1.7.5.4\r
266 >> >\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