[PATCH] configure: add --without-api-docs option
[notmuch-archives.git] / 1b / 79025aabd28272bdac9e267bf6eea30ab63ed9
1 Return-Path: <bremner@tethera.net>\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 E1F3A6DE02D5\r
6  for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:35 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.029\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.029 tagged_above=-999 required=5\r
12  tests=[AWL=-0.018, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
13  autolearn=disabled\r
14 Received: from arlo.cworth.org ([127.0.0.1])\r
15  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
16  with ESMTP id w-31sWo3c5Ki for <notmuch@notmuchmail.org>;\r
17  Tue, 22 Mar 2016 03:55:24 -0700 (PDT)\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id EDA776DE02A6\r
20  for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:17 -0700 (PDT)\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
22  (envelope-from <bremner@tethera.net>)\r
23  id 1aiJyb-00014U-GF; Tue, 22 Mar 2016 06:55:53 -0400\r
24 Received: (nullmailer pid 14085 invoked by uid 1000);\r
25  Tue, 22 Mar 2016 10:55:11 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 09/13] CLI: add optional config data to dump output.\r
29 Date: Tue, 22 Mar 2016 07:54:50 -0300\r
30 Message-Id: <1458644094-13951-10-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.7.0\r
32 In-Reply-To: <1458644094-13951-1-git-send-email-david@tethera.net>\r
33 References: <1458644094-13951-1-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.20\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Tue, 22 Mar 2016 10:55:36 -0000\r
47 \r
48 This lacks at least documentation. Note that it changes the default dump\r
49 output format, but doesn't break existing notmuch-restore. It might\r
50 break user scripts though.\r
51 ---\r
52  notmuch-client.h          |  8 +++++\r
53  notmuch-dump.c            | 80 +++++++++++++++++++++++++++++++++++++++++++++--\r
54  notmuch-new.c             |  2 +-\r
55  test/T150-tagging.sh      |  8 ++---\r
56  test/T240-dump-restore.sh | 14 ++++-----\r
57  test/T590-libconfig.sh    | 17 ++++++++++\r
58  test/test-lib.sh          |  6 ++++\r
59  7 files changed, 120 insertions(+), 15 deletions(-)\r
60 \r
61 diff --git a/notmuch-client.h b/notmuch-client.h\r
62 index b3d0b66..ae6f124 100644\r
63 --- a/notmuch-client.h\r
64 +++ b/notmuch-client.h\r
65 @@ -446,11 +446,19 @@ typedef enum dump_formats {\r
66      DUMP_FORMAT_SUP\r
67  } dump_format_t;\r
68  \r
69 +typedef enum dump_includes {\r
70 +    DUMP_INCLUDE_TAGS=1,\r
71 +    DUMP_INCLUDE_CONFIG=2,\r
72 +} dump_include_t;\r
73 +\r
74 +#define NOTMUCH_DUMP_VERSION 2\r
75 +\r
76  int\r
77  notmuch_database_dump (notmuch_database_t *notmuch,\r
78                        const char *output_file_name,\r
79                        const char *query_str,\r
80                        dump_format_t output_format,\r
81 +                      dump_include_t include,\r
82                        notmuch_bool_t gzip_output);\r
83  \r
84  /* If status is non-zero (i.e. error) print appropriate\r
85 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
86 index 829781f..a6cf810 100644\r
87 --- a/notmuch-dump.c\r
88 +++ b/notmuch-dump.c\r
89 @@ -23,16 +23,82 @@\r
90  #include "string-util.h"\r
91  #include <zlib.h>\r
92  \r
93 +static int\r
94 +database_dump_config (notmuch_database_t *notmuch, gzFile output)\r
95 +{\r
96 +    notmuch_config_list_t *list;\r
97 +    int ret = EXIT_FAILURE;\r
98 +    char *buffer = NULL;\r
99 +    size_t buffer_size = 0;\r
100 +\r
101 +    if (print_status_database ("notmuch dump", notmuch,\r
102 +                              notmuch_database_get_config_list (notmuch, NULL, &list)))\r
103 +       goto DONE;\r
104 +\r
105 +    for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {\r
106 +       if (hex_encode (notmuch, notmuch_config_list_key (list),\r
107 +                       &buffer, &buffer_size) != HEX_SUCCESS) {\r
108 +           fprintf (stderr, "Error: failed to hex-encode config key %s\n",\r
109 +                    notmuch_config_list_key (list));\r
110 +           goto DONE;\r
111 +       }\r
112 +       gzprintf (output, "#@ %s", buffer);\r
113 +\r
114 +       if (hex_encode (notmuch, notmuch_config_list_value (list),\r
115 +                       &buffer, &buffer_size) != HEX_SUCCESS) {\r
116 +           fprintf (stderr, "Error: failed to hex-encode config value %s\n",\r
117 +                    notmuch_config_list_value (list) );\r
118 +           goto DONE;\r
119 +       }\r
120 +\r
121 +       gzprintf (output, " %s\n", buffer);\r
122 +    }\r
123 +\r
124 +    ret = EXIT_SUCCESS;\r
125 +\r
126 + DONE:\r
127 +    if (list)\r
128 +       notmuch_config_list_destroy (list);\r
129 +\r
130 +    if (buffer)\r
131 +       talloc_free (buffer);\r
132 +\r
133 +    return ret;\r
134 +}\r
135 +\r
136 +static void\r
137 +print_dump_header (gzFile output, int output_format, int include)\r
138 +{\r
139 +    gzprintf (output, "#notmuch-dump %s:%d %s%s%s\n",\r
140 +             (output_format == DUMP_FORMAT_SUP) ? "sup" : "batch-tag",\r
141 +             NOTMUCH_DUMP_VERSION,\r
142 +             (include & DUMP_INCLUDE_CONFIG) ? "config" : "",\r
143 +             (include & DUMP_INCLUDE_TAGS) && (include & DUMP_INCLUDE_CONFIG) ? "," : "",\r
144 +             (include & DUMP_INCLUDE_TAGS) ? "tags" : "");\r
145 +\r
146 +\r
147 +}\r
148  \r
149  static int\r
150  database_dump_file (notmuch_database_t *notmuch, gzFile output,\r
151 -                   const char *query_str, int output_format)\r
152 +                   const char *query_str, int output_format, int include)\r
153  {\r
154      notmuch_query_t *query;\r
155      notmuch_messages_t *messages;\r
156      notmuch_message_t *message;\r
157      notmuch_tags_t *tags;\r
158  \r
159 +    print_dump_header (output, output_format, include);\r
160 +\r
161 +    if (include & DUMP_INCLUDE_CONFIG) {\r
162 +       if (print_status_database ("notmuch dump", notmuch,\r
163 +                                  database_dump_config(notmuch,output)))\r
164 +           return EXIT_FAILURE;\r
165 +    }\r
166 +\r
167 +    if (! (include & DUMP_INCLUDE_TAGS))\r
168 +       return EXIT_SUCCESS;\r
169 +\r
170      if (! query_str)\r
171         query_str = "";\r
172  \r
173 @@ -130,6 +196,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
174                        const char *output_file_name,\r
175                        const char *query_str,\r
176                        dump_format_t output_format,\r
177 +                      dump_include_t include,\r
178                        notmuch_bool_t gzip_output)\r
179  {\r
180      gzFile output = NULL;\r
181 @@ -164,7 +231,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
182         goto DONE;\r
183      }\r
184  \r
185 -    ret = database_dump_file (notmuch, output, query_str, output_format);\r
186 +    ret = database_dump_file (notmuch, output, query_str, output_format, include);\r
187      if (ret) goto DONE;\r
188  \r
189      ret = gzflush (output, Z_FINISH);\r
190 @@ -226,6 +293,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
191      int opt_index;\r
192  \r
193      int output_format = DUMP_FORMAT_BATCH_TAG;\r
194 +    int include = 0;\r
195      notmuch_bool_t gzip_output = 0;\r
196  \r
197      notmuch_opt_desc_t options[] = {\r
198 @@ -233,6 +301,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
199           (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },\r
200                                   { "batch-tag", DUMP_FORMAT_BATCH_TAG },\r
201                                   { 0, 0 } } },\r
202 +       { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',\r
203 +         (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },\r
204 +                                 { "tags", DUMP_INCLUDE_TAGS} } },\r
205         { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0  },\r
206         { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },\r
207         { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
208 @@ -245,6 +316,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
209  \r
210      notmuch_process_shared_options (argv[0]);\r
211  \r
212 +    if (include == 0)\r
213 +       include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;\r
214 +\r
215      if (opt_index < argc) {\r
216         query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);\r
217         if (query_str == NULL) {\r
218 @@ -254,7 +328,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
219      }\r
220  \r
221      ret = notmuch_database_dump (notmuch, output_file_name, query_str,\r
222 -                                output_format, gzip_output);\r
223 +                                output_format, include, gzip_output);\r
224  \r
225      notmuch_database_destroy (notmuch);\r
226  \r
227 diff --git a/notmuch-new.c b/notmuch-new.c\r
228 index e503776..fd2ff82 100644\r
229 --- a/notmuch-new.c\r
230 +++ b/notmuch-new.c\r
231 @@ -1041,7 +1041,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
232             }\r
233  \r
234             if (notmuch_database_dump (notmuch, backup_name, "",\r
235 -                                      DUMP_FORMAT_BATCH_TAG, TRUE)) {\r
236 +                                      DUMP_FORMAT_BATCH_TAG, DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS, TRUE)) {\r
237                 fprintf (stderr, "Backup failed. Aborting upgrade.");\r
238                 return EXIT_FAILURE;\r
239             }\r
240 diff --git a/test/T150-tagging.sh b/test/T150-tagging.sh\r
241 index 8adcabc..f1a6df0 100755\r
242 --- a/test/T150-tagging.sh\r
243 +++ b/test/T150-tagging.sh\r
244 @@ -188,7 +188,7 @@ cat <<EOF > EXPECTED\r
245  +%22%27%22%27%22%22%27%27 +inbox +tag4 +tag5 +unread -- id:msg-002@notmuch-test-suite\r
246  EOF\r
247  \r
248 -notmuch dump --format=batch-tag | sort > OUTPUT\r
249 +NOTMUCH_DUMP_TAGS > OUTPUT\r
250  notmuch restore --format=batch-tag < BACKUP\r
251  test_expect_equal_file EXPECTED OUTPUT\r
252  \r
253 @@ -209,7 +209,7 @@ cat <<EOF > EXPECTED\r
254  +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e +inbox +tag5 +unread -- id:msg-001@notmuch-test-suite\r
255  EOF\r
256  \r
257 -notmuch dump --format=batch-tag | sort > OUTPUT\r
258 +NOTMUCH_DUMP_TAGS > OUTPUT\r
259  notmuch restore --format=batch-tag < BACKUP\r
260  test_expect_equal_file EXPECTED OUTPUT\r
261  \r
262 @@ -235,7 +235,7 @@ cat <<EOF > EXPECTED\r
263  +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7 +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27 +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1 +P%c4%98%2f +R +inbox +tag5 +unread +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6 +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d -- id:msg-001@notmuch-test-suite\r
264  EOF\r
265  \r
266 -notmuch dump --format=batch-tag | sort > OUTPUT\r
267 +NOTMUCH_DUMP_TAGS > OUTPUT\r
268  notmuch restore --format=batch-tag < BACKUP\r
269  test_expect_equal_file EXPECTED OUTPUT\r
270  \r
271 @@ -260,7 +260,7 @@ cat <<EOF > EXPECTED\r
272  +foo%3a%3abar%25 +found%3a%3ait +inbox +tag5 +unread +winner -- id:msg-001@notmuch-test-suite\r
273  EOF\r
274  \r
275 -notmuch dump --format=batch-tag | sort > OUTPUT\r
276 +NOTMUCH_DUMP_TAGS > OUTPUT\r
277  notmuch restore --format=batch-tag < BACKUP\r
278  test_expect_equal_file EXPECTED OUTPUT\r
279  \r
280 diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh\r
281 index e6976ff..758d355 100755\r
282 --- a/test/T240-dump-restore.sh\r
283 +++ b/test/T240-dump-restore.sh\r
284 @@ -97,7 +97,7 @@ test_expect_equal_file dump.expected dump.actual\r
285  # Note, we assume all messages from cworth have a message-id\r
286  # containing cworth.org\r
287  \r
288 -grep 'cworth[.]org' dump.expected > dump-cworth.expected\r
289 +(head -1 dump.expected ; grep 'cworth[.]org' dump.expected) > dump-cworth.expected\r
290  \r
291  test_begin_subtest "dump -- from:cworth"\r
292  notmuch dump -- from:cworth > dump-dash-cworth.actual\r
293 @@ -118,16 +118,16 @@ notmuch search --output=messages from:cworth | sed s/^id:// |\\r
294  test_expect_equal_file OUTPUT EXPECTED\r
295  \r
296  test_begin_subtest "format=batch-tag, dump sanity check."\r
297 -notmuch dump --format=sup from:cworth | cut -f1 -d' ' | \\r
298 +NOTMUCH_DUMP_TAGS --format=sup from:cworth | cut -f1 -d' ' | \\r
299      sort > EXPECTED.$test_count\r
300 -notmuch dump --format=batch-tag from:cworth | sed 's/^.*-- id://' | \\r
301 +NOTMUCH_DUMP_TAGS --format=batch-tag from:cworth | sed 's/^.*-- id://' | \\r
302      sort > OUTPUT.$test_count\r
303  test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count\r
304  \r
305  test_begin_subtest "format=batch-tag, missing newline"\r
306  printf "+a_tag_without_newline -- id:20091117232137.GA7669@griffis1.net" > IN\r
307  notmuch restore --accumulate < IN\r
308 -notmuch dump id:20091117232137.GA7669@griffis1.net > OUT\r
309 +NOTMUCH_DUMP_TAGS id:20091117232137.GA7669@griffis1.net > OUT\r
310  cat <<EOF > EXPECTED\r
311  +a_tag_without_newline +inbox +unread -- id:20091117232137.GA7669@griffis1.net\r
312  EOF\r
313 @@ -155,7 +155,7 @@ cat <<EOF >EXPECTED.$test_count\r
314  + -- id:20091117232137.GA7669@griffis1.net\r
315  EOF\r
316  notmuch restore --format=batch-tag < EXPECTED.$test_count\r
317 -notmuch dump --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count\r
318 +NOTMUCH_DUMP_TAGS --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count\r
319  test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count\r
320  \r
321  tag1='comic_swear=$&^%$^%\\//-+$^%$'\r
322 @@ -217,9 +217,9 @@ notmuch dump --format=batch-tag > OUTPUT.$test_count\r
323  test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count\r
324  \r
325  test_begin_subtest 'format=batch-tag, checking encoded output'\r
326 -notmuch dump --format=batch-tag -- from:cworth |\\r
327 +NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth |\\r
328          awk "{ print \"+$enc1 +$enc2 +$enc3 -- \" \$5 }" > EXPECTED.$test_count\r
329 -notmuch dump --format=batch-tag -- from:cworth  > OUTPUT.$test_count\r
330 +NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth  > OUTPUT.$test_count\r
331  test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count\r
332  \r
333  test_begin_subtest 'restoring sane tags'\r
334 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh\r
335 index 8ca6883..5ea5300 100755\r
336 --- a/test/T590-libconfig.sh\r
337 +++ b/test/T590-libconfig.sh\r
338 @@ -115,4 +115,21 @@ testkey2 testvalue2\r
339  EOF\r
340  test_expect_equal_file EXPECTED OUTPUT\r
341  \r
342 +test_begin_subtest "dump config"\r
343 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
344 +{\r
345 +    RUN(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));\r
346 +}\r
347 +EOF\r
348 +notmuch dump --include=config >OUTPUT\r
349 +cat <<'EOF' >EXPECTED\r
350 +#notmuch-dump batch-tag:2 config\r
351 +#@ aaabefore beforeval\r
352 +#@ key%20with%20spaces value,%20with,%20spaces%21\r
353 +#@ testkey1 testvalue1\r
354 +#@ testkey2 testvalue2\r
355 +#@ zzzafter afterval\r
356 +EOF\r
357 +test_expect_equal_file EXPECTED OUTPUT\r
358 +\r
359  test_done\r
360 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
361 index 49e6f40..98abbe2 100644\r
362 --- a/test/test-lib.sh\r
363 +++ b/test/test-lib.sh\r
364 @@ -673,6 +673,12 @@ NOTMUCH_NEW ()\r
365      notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'\r
366  }\r
367  \r
368 +NOTMUCH_DUMP_TAGS ()\r
369 +{\r
370 +    # this relies on the default format being batch-tag, otherwise some tests will break\r
371 +    notmuch dump --include=tags "${@}" | sed '/^#/d' | sort\r
372 +}\r
373 +\r
374  notmuch_search_sanitize ()\r
375  {\r
376      perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'\r
377 -- \r
378 2.7.0\r
379 \r