Re: [PATCH] lib: provide _notmuch_database_log_append
[notmuch-archives.git] / 44 / 78bcd527d81c543f35016204125966deb96bd7
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 arlo.cworth.org (Postfix) with ESMTP id BDD036DE1579\r
6  for <notmuch@notmuchmail.org>; Mon, 10 Aug 2015 12:42:46 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.245\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.245 tagged_above=-999 required=5 tests=[AWL=-0.151,\r
12   SPF_NEUTRAL=0.652, URIBL_SBL=0.644, URIBL_SBL_A=0.1] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id DMaztYa2nQde for <notmuch@notmuchmail.org>;\r
16  Mon, 10 Aug 2015 12:42:45 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 7357F6DE0244\r
19  for <notmuch@notmuchmail.org>; Mon, 10 Aug 2015 12:42:44 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21  by guru.guru-group.fi (Postfix) with ESMTP id B15971000CE;\r
22  Mon, 10 Aug 2015 22:42:33 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH 4/5] cli: add global option "--uuid"\r
26 In-Reply-To: <1439112285-6681-5-git-send-email-david@tethera.net>\r
27 References: <1439112285-6681-1-git-send-email-david@tethera.net>\r
28  <1439112285-6681-5-git-send-email-david@tethera.net>\r
29 User-Agent: Notmuch/0.20.2+58~ge9cd033 (http://notmuchmail.org) Emacs/24.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: Mon, 10 Aug 2015 22:42:33 +0300\r
35 Message-ID: <m2y4hj3p7a.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.18\r
40 Precedence: list\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: Mon, 10 Aug 2015 19:42:46 -0000\r
51 \r
52 On Sun, Aug 09 2015, David Bremner <david@tethera.net> wrote:\r
53 \r
54 > The function notmuch_exit_if_unmatched_db_uuid is split from\r
55 > notmuch_process_shared_options because it needs an open notmuch\r
56 > database.\r
57 > ---\r
58 >  doc/man1/notmuch.rst           | 12 ++++++++++--\r
59 >  notmuch-client.h               |  4 ++++\r
60 >  notmuch-compact.c              |  4 ++++\r
61 >  notmuch-config.c               |  4 ++++\r
62 >  notmuch-count.c                |  2 ++\r
63 >  notmuch-dump.c                 |  2 ++\r
64 >  notmuch-insert.c               |  2 ++\r
65 >  notmuch-new.c                  |  3 ++-\r
66 >  notmuch-reply.c                |  2 ++\r
67 >  notmuch-restore.c              |  2 ++\r
68 >  notmuch-search.c               |  2 ++\r
69 >  notmuch-setup.c                |  4 ++++\r
70 >  notmuch-show.c                 |  2 ++\r
71 >  notmuch-tag.c                  |  2 ++\r
72 >  notmuch.c                      | 18 ++++++++++++++++++\r
73 >  test/T570-revision-tracking.sh | 27 +++++++++++++++++++++++++++\r
74 >  test/random-corpus.c           |  2 ++\r
75 >  17 files changed, 91 insertions(+), 3 deletions(-)\r
76 >\r
77 > diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst\r
78 > index 0401c91..0b89544 100644\r
79 > --- a/doc/man1/notmuch.rst\r
80 > +++ b/doc/man1/notmuch.rst\r
81 > @@ -51,9 +51,17 @@ Supported global options for ``notmuch`` include\r
82 >       Specify the configuration file to use. This overrides any\r
83 >       configuration file specified by ${NOTMUCH\_CONFIG}.\r
84 >  \r
85 > +    ``--uuid=HEX``\r
86 > +       Enforce that the database UUID (a unique identifier which\r
87 > +       persists until e.g. the database is compacted)\r
88 > +       is HEX; exit with an error if it is not. This is useful to\r
89 > +       detect rollover in modification counts on messages. You can\r
90 > +       find this UUID in the first column of output from\r
91 > +       ``notmuch count --output=modifications``\r
92 > +\r
93 >  All global options except ``--config`` can also be specified after the\r
94 > -command. For example, ``notmuch subcommand --version`` is equivalent to\r
95 > -``notmuch --version subcommand``.\r
96 > +command. For example, ``notmuch subcommand --uuid=HEX`` is\r
97 > +equivalent to ``notmuch --uuid=HEX subcommand``.\r
98 >  \r
99 >  COMMANDS\r
100 >  ========\r
101 > diff --git a/notmuch-client.h b/notmuch-client.h\r
102 > index 78680aa..4a4f86c 100644\r
103 > --- a/notmuch-client.h\r
104 > +++ b/notmuch-client.h\r
105 > @@ -466,7 +466,11 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
106 >                      notmuch_bool_t gzip_output);\r
107 >  \r
108 >  #include "command-line-arguments.h"\r
109 > +\r
110 > +extern char *notmuch_requested_db_uuid;\r
111 >  extern const notmuch_opt_desc_t  notmuch_shared_options [];\r
112 > +void notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch);\r
113 > +\r
114 >  void notmuch_process_shared_options (const char* subcommand_name);\r
115 >  int notmuch_minimal_options (const char* subcommand_name,\r
116 >                            int argc, char **argv);\r
117 > diff --git a/notmuch-compact.c b/notmuch-compact.c\r
118 > index 5be551d..61fccd8 100644\r
119 > --- a/notmuch-compact.c\r
120 > +++ b/notmuch-compact.c\r
121 > @@ -46,6 +46,10 @@ notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])\r
122 >      if (opt_index < 0)\r
123 >       return EXIT_FAILURE;\r
124 >  \r
125 > +    if (notmuch_requested_db_uuid)\r
126 > +     fprintf (stderr, "Warning: ignoring --uuid=%s\n",\r
127 > +              notmuch_requested_db_uuid);\r
128 > +\r
129 \r
130 I see in these commands this warning is issued, we don't open the database\r
131 (at this time, IIRC compact opens it later)...\r
132 \r
133 ... In this case I'm wondering whether giving --uuid should be considered\r
134 as error (and stopping) instead of printing warning and continuing.  In\r
135 some other cases we do warn and continue but here ... we're modifying\r
136 the database or configurations...\r
137 ... later we could add database uuid check always if --uuid is given\r
138 and allow continuing if it matches in these cases...\r
139 \r
140 One more (now the trivial thing) to go, do not stop here ;)\r
141 \r
142 >      notmuch_process_shared_options (argv[0]);\r
143 >  \r
144 >      if (! quiet)\r
145 > diff --git a/notmuch-config.c b/notmuch-config.c\r
146 > index 9348278..d252bb2 100644\r
147 > --- a/notmuch-config.c\r
148 > +++ b/notmuch-config.c\r
149 > @@ -878,6 +878,10 @@ notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])\r
150 >      if (opt_index < 0)\r
151 >       return EXIT_FAILURE;\r
152 >  \r
153 > +    if (notmuch_requested_db_uuid)\r
154 > +     fprintf (stderr, "Warning: ignoring --uuid=%s\n",\r
155 > +              notmuch_requested_db_uuid);\r
156 > +\r
157 >      /* skip at least subcommand argument */\r
158 >      argc-= opt_index;\r
159 >      argv+= opt_index;\r
160 > diff --git a/notmuch-count.c b/notmuch-count.c\r
161 > index 7c61ccb..091e376 100644\r
162 > --- a/notmuch-count.c\r
163 > +++ b/notmuch-count.c\r
164 > @@ -191,6 +191,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
165 >                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
166 >       return EXIT_FAILURE;\r
167 >  \r
168 > +    notmuch_exit_if_unmatched_db_uuid (notmuch);\r
169 > +\r
170 >      query_str = query_string_from_args (config, argc-opt_index, argv+opt_index);\r
171 >      if (query_str == NULL) {\r
172 >       fprintf (stderr, "Out of memory.\n");\r
173 > diff --git a/notmuch-dump.c b/notmuch-dump.c\r
174 > index fab22bd..24fc2f2 100644\r
175 > --- a/notmuch-dump.c\r
176 > +++ b/notmuch-dump.c\r
177 > @@ -215,6 +215,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
178 >                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
179 >       return EXIT_FAILURE;\r
180 >  \r
181 > +    notmuch_exit_if_unmatched_db_uuid (notmuch);\r
182 > +\r
183 >      char *output_file_name = NULL;\r
184 >      int opt_index;\r
185 >  \r
186 > diff --git a/notmuch-insert.c b/notmuch-insert.c\r
187 > index c277d62..5205c17 100644\r
188 > --- a/notmuch-insert.c\r
189 > +++ b/notmuch-insert.c\r
190 > @@ -536,6 +536,8 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
191 >                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
192 >       return EXIT_FAILURE;\r
193 >  \r
194 > +    notmuch_exit_if_unmatched_db_uuid (notmuch);\r
195 > +\r
196 >      /* Write the message to the Maildir new directory. */\r
197 >      newpath = maildir_write_new (config, STDIN_FILENO, maildir);\r
198 >      if (! newpath) {\r
199 > diff --git a/notmuch-new.c b/notmuch-new.c\r
200 > index ee786a3..514e06a 100644\r
201 > --- a/notmuch-new.c\r
202 > +++ b/notmuch-new.c\r
203 > @@ -1009,10 +1009,11 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
204 >               fputs (status_string, stderr);\r
205 >               free (status_string);\r
206 >           }\r
207 > -\r
208 >           return EXIT_FAILURE;\r
209 >       }\r
210 >  \r
211 > +     notmuch_exit_if_unmatched_db_uuid (notmuch);\r
212 > +\r
213 >       if (notmuch_database_needs_upgrade (notmuch)) {\r
214 >           time_t now = time (NULL);\r
215 >           struct tm *gm_time = gmtime (&now);\r
216 > diff --git a/notmuch-reply.c b/notmuch-reply.c\r
217 > index 4464741..7c5c28f 100644\r
218 > --- a/notmuch-reply.c\r
219 > +++ b/notmuch-reply.c\r
220 > @@ -831,6 +831,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
221 >                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
222 >       return EXIT_FAILURE;\r
223 >  \r
224 > +    notmuch_exit_if_unmatched_db_uuid (notmuch);\r
225 > +\r
226 >      query = notmuch_query_create (notmuch, query_string);\r
227 >      if (query == NULL) {\r
228 >       fprintf (stderr, "Out of memory\n");\r
229 > diff --git a/notmuch-restore.c b/notmuch-restore.c\r
230 > index 2a534dc..9abc64f 100644\r
231 > --- a/notmuch-restore.c\r
232 > +++ b/notmuch-restore.c\r
233 > @@ -165,6 +165,8 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
234 >      }\r
235 >  \r
236 >      notmuch_process_shared_options (argv[0]);\r
237 > +    notmuch_exit_if_unmatched_db_uuid (notmuch);\r
238 > +\r
239 >      name_for_error = input_file_name ? input_file_name : "stdin";\r
240 >  \r
241 >      if (! accumulate)\r
242 > diff --git a/notmuch-search.c b/notmuch-search.c\r
243 > index b89a17e..3076c3f 100644\r
244 > --- a/notmuch-search.c\r
245 > +++ b/notmuch-search.c\r
246 > @@ -583,6 +583,8 @@ _notmuch_search_prepare (search_context_t *ctx, notmuch_config_t *config, int ar\r
247 >       return EXIT_FAILURE;\r
248 >      }\r
249 >  \r
250 > +    notmuch_exit_if_unmatched_db_uuid (ctx->notmuch);\r
251 > +\r
252 >      query_str = query_string_from_args (ctx->notmuch, argc, argv);\r
253 >      if (query_str == NULL) {\r
254 >       fprintf (stderr, "Out of memory.\n");\r
255 > diff --git a/notmuch-setup.c b/notmuch-setup.c\r
256 > index 7dd5822..9aaf928 100644\r
257 > --- a/notmuch-setup.c\r
258 > +++ b/notmuch-setup.c\r
259 > @@ -148,6 +148,10 @@ notmuch_setup_command (notmuch_config_t *config,\r
260 >      if (notmuch_minimal_options ("setup", argc, argv) < 0)\r
261 >       return EXIT_FAILURE;\r
262 >  \r
263 > +    if (notmuch_requested_db_uuid)\r
264 > +     fprintf (stderr, "Warning: ignoring --uuid=%s\n",\r
265 > +              notmuch_requested_db_uuid);\r
266 > +\r
267 >      if (notmuch_config_is_new (config))\r
268 >       welcome_message_pre_setup ();\r
269 >  \r
270 > diff --git a/notmuch-show.c b/notmuch-show.c\r
271 > index b80933a..6ef3308 100644\r
272 > --- a/notmuch-show.c\r
273 > +++ b/notmuch-show.c\r
274 > @@ -1213,6 +1213,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
275 >                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
276 >       return EXIT_FAILURE;\r
277 >  \r
278 > +    notmuch_exit_if_unmatched_db_uuid (notmuch);\r
279 > +\r
280 >      query = notmuch_query_create (notmuch, query_string);\r
281 >      if (query == NULL) {\r
282 >       fprintf (stderr, "Out of memory\n");\r
283 > diff --git a/notmuch-tag.c b/notmuch-tag.c\r
284 > index 38d99aa..7ae98f6 100644\r
285 > --- a/notmuch-tag.c\r
286 > +++ b/notmuch-tag.c\r
287 > @@ -261,6 +261,8 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
288 >                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
289 >       return EXIT_FAILURE;\r
290 >  \r
291 > +    notmuch_exit_if_unmatched_db_uuid (notmuch);\r
292 > +\r
293 >      if (notmuch_config_get_maildir_synchronize_flags (config))\r
294 >       tag_flags |= TAG_FLAG_MAILDIR_SYNC;\r
295 >  \r
296 > diff --git a/notmuch.c b/notmuch.c\r
297 > index 9580c3f..ce6c575 100644\r
298 > --- a/notmuch.c\r
299 > +++ b/notmuch.c\r
300 > @@ -47,10 +47,12 @@ static int\r
301 >  _help_for (const char *topic);\r
302 >  \r
303 >  static notmuch_bool_t print_version = FALSE, print_help = FALSE;\r
304 > +char *notmuch_requested_db_uuid = NULL;\r
305 >  \r
306 >  const notmuch_opt_desc_t notmuch_shared_options [] = {\r
307 >      { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
308 >      { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
309 > +    { NOTMUCH_OPT_STRING, &notmuch_requested_db_uuid, "uuid", 'u', 0 },\r
310 >      {0, 0, 0, 0, 0}\r
311 >  };\r
312 >  \r
313 > @@ -218,6 +220,22 @@ be supported in the future.\n", notmuch_format_version);\r
314 >      }\r
315 >  }\r
316 >  \r
317 > +void\r
318 > +notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch)\r
319 > +{\r
320 > +    const char *uuid = NULL;\r
321 > +\r
322 > +    if (!notmuch_requested_db_uuid)\r
323 > +     return;\r
324 > +    IGNORE_RESULT (notmuch_database_get_revision (notmuch, &uuid));\r
325 > +\r
326 > +    if (strcmp (notmuch_requested_db_uuid, uuid) != 0){\r
327 > +     fprintf (stderr, "Error: requested database revision %s does not match %s\n",\r
328 > +              notmuch_requested_db_uuid, uuid);\r
329 > +     exit (1);\r
330 > +    }\r
331 > +}\r
332 > +\r
333 >  static void\r
334 >  exec_man (const char *page)\r
335 >  {\r
336 > diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh\r
337 > index 008c5d0..74e3ba9 100755\r
338 > --- a/test/T570-revision-tracking.sh\r
339 > +++ b/test/T570-revision-tracking.sh\r
340 > @@ -46,4 +46,31 @@ notmuch tag +a-random-tag-8743632 '*'\r
341 >  after=$(notmuch count --output=modifications '*' | cut -f2)\r
342 >  result=$(($before < $after))\r
343 >  test_expect_equal 1 ${result}\r
344 > +\r
345 > +notmuch count --output=modifications '*' | cut -f1 > UUID\r
346 \r
347 the above could be\r
348 \r
349 UUID=$(notmuch count --output=modifications '*' | cut -f1)\r
350 \r
351 > +\r
352 > +test_expect_success 'search succeeds with correct uuid' \\r
353 > +                 "notmuch search --uuid=$(cat UUID) '*'"\r
354 \r
355 And then these just as \r
356 \r
357 test_expect_success 'search succeeds with correct uuid' \\r
358                     "notmuch search --uuid=${UUID} '*'"\r
359 \r
360 \r
361 Tomi\r
362 \r
363 \r
364 > +\r
365 > +test_expect_success 'uuid works as global option ' \\r
366 > +                 "notmuch --uuid=$(cat UUID) search '*'"\r
367 > +\r
368 > +test_expect_code 1 'uuid works as global option II' \\r
369 > +                 "notmuch --uuid=this-is-no-uuid search '*'"\r
370 > +\r
371 > +test_expect_code 1 'search fails with incorrect uuid' \\r
372 > +              "notmuch search --uuid=this-is-no-uuid '*'"\r
373 > +\r
374 > +test_expect_success 'show succeeds with correct uuid' \\r
375 > +                 "notmuch show --uuid=$(cat UUID) '*'"\r
376 > +\r
377 > +test_expect_code 1 'show fails with incorrect uuid' \\r
378 > +              "notmuch show --uuid=this-is-no-uuid '*'"\r
379 > +\r
380 > +test_expect_success 'tag succeeds with correct uuid' \\r
381 > +                 "notmuch tag --uuid=$(cat UUID) +test '*'"\r
382 > +\r
383 > +test_expect_code 1 'tag fails with incorrect uuid' \\r
384 > +              "notmuch tag --uuid=this-is-no-uuid '*' +test2"\r
385 > +\r
386 >  test_done\r
387 > diff --git a/test/random-corpus.c b/test/random-corpus.c\r
388 > index b377eb4..d74271d 100644\r
389 > --- a/test/random-corpus.c\r
390 > +++ b/test/random-corpus.c\r
391 > @@ -119,6 +119,8 @@ const notmuch_opt_desc_t notmuch_shared_options[] = {\r
392 >       { 0, 0, 0, 0, 0 }\r
393 >  };\r
394 >  \r
395 > +char *notmuch_requested_db_uuid = NULL;\r
396 > +\r
397 >  void\r
398 >  notmuch_process_shared_options (unused (const char *dummy))\r
399 >  {\r
400 > -- \r
401 > 2.1.4\r