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 BF4526DE092D
\r
6 for <notmuch@notmuchmail.org>; Sat, 7 May 2016 17:05:12 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.013 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.002, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]
\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 NqA6BtBD_lMz for <notmuch@notmuchmail.org>;
\r
17 Sat, 7 May 2016 17:05:04 -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 8A6996DE026C
\r
20 for <notmuch@notmuchmail.org>; Sat, 7 May 2016 17:04:57 -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 1azCDL-00013q-Gt; Sat, 07 May 2016 20:04:51 -0400
\r
24 Received: (nullmailer pid 17195 invoked by uid 1000);
\r
25 Sun, 08 May 2016 00:04:53 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [Patch v4 07/12] CLI: add optional config data to dump output.
\r
29 Date: Sat, 7 May 2016 21:04:44 -0300
\r
30 Message-Id: <1462665889-17121-8-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.8.1
\r
32 In-Reply-To: <1462665889-17121-1-git-send-email-david@tethera.net>
\r
33 References: <1462665889-17121-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\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: Sun, 08 May 2016 00:05:12 -0000
\r
48 Note that it changes the default dump output format, but doesn't break
\r
49 existing notmuch-restore. It might break user scripts though.
\r
51 doc/man1/notmuch-dump.rst | 17 ++++++++++
\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 8 files changed, 137 insertions(+), 15 deletions(-)
\r
61 diff --git a/doc/man1/notmuch-dump.rst b/doc/man1/notmuch-dump.rst
\r
62 index a37c337..eda9e07 100644
\r
63 --- a/doc/man1/notmuch-dump.rst
\r
64 +++ b/doc/man1/notmuch-dump.rst
\r
65 @@ -71,6 +71,23 @@ Supported options for **dump** include
\r
66 characters. Note also that tags with spaces will not be
\r
67 correctly restored with this format.
\r
69 + ``--include=(config|tags)``
\r
71 + Control what kind of metadata is included in the output.
\r
75 + Output configuration data stored in the database. Each line
\r
76 + starts with "#@ ", followed by a space seperated key-value
\r
77 + pair. Both key and value are hex encoded if needed.
\r
81 + Output per-message metadata, namely tags. See *format* above
\r
82 + for description of the output.
\r
84 + The default is to include both tags and configuration information
\r
86 ``--output=``\ <filename>
\r
87 Write output to given file instead of stdout.
\r
89 diff --git a/notmuch-client.h b/notmuch-client.h
\r
90 index b3d0b66..ae6f124 100644
\r
91 --- a/notmuch-client.h
\r
92 +++ b/notmuch-client.h
\r
93 @@ -446,11 +446,19 @@ typedef enum dump_formats {
\r
97 +typedef enum dump_includes {
\r
98 + DUMP_INCLUDE_TAGS=1,
\r
99 + DUMP_INCLUDE_CONFIG=2,
\r
102 +#define NOTMUCH_DUMP_VERSION 2
\r
105 notmuch_database_dump (notmuch_database_t *notmuch,
\r
106 const char *output_file_name,
\r
107 const char *query_str,
\r
108 dump_format_t output_format,
\r
109 + dump_include_t include,
\r
110 notmuch_bool_t gzip_output);
\r
112 /* If status is non-zero (i.e. error) print appropriate
\r
113 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
114 index 829781f..a6cf810 100644
\r
115 --- a/notmuch-dump.c
\r
116 +++ b/notmuch-dump.c
\r
117 @@ -23,16 +23,82 @@
\r
118 #include "string-util.h"
\r
122 +database_dump_config (notmuch_database_t *notmuch, gzFile output)
\r
124 + notmuch_config_list_t *list;
\r
125 + int ret = EXIT_FAILURE;
\r
126 + char *buffer = NULL;
\r
127 + size_t buffer_size = 0;
\r
129 + if (print_status_database ("notmuch dump", notmuch,
\r
130 + notmuch_database_get_config_list (notmuch, NULL, &list)))
\r
133 + for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
\r
134 + if (hex_encode (notmuch, notmuch_config_list_key (list),
\r
135 + &buffer, &buffer_size) != HEX_SUCCESS) {
\r
136 + fprintf (stderr, "Error: failed to hex-encode config key %s\n",
\r
137 + notmuch_config_list_key (list));
\r
140 + gzprintf (output, "#@ %s", buffer);
\r
142 + if (hex_encode (notmuch, notmuch_config_list_value (list),
\r
143 + &buffer, &buffer_size) != HEX_SUCCESS) {
\r
144 + fprintf (stderr, "Error: failed to hex-encode config value %s\n",
\r
145 + notmuch_config_list_value (list) );
\r
149 + gzprintf (output, " %s\n", buffer);
\r
152 + ret = EXIT_SUCCESS;
\r
156 + notmuch_config_list_destroy (list);
\r
159 + talloc_free (buffer);
\r
165 +print_dump_header (gzFile output, int output_format, int include)
\r
167 + gzprintf (output, "#notmuch-dump %s:%d %s%s%s\n",
\r
168 + (output_format == DUMP_FORMAT_SUP) ? "sup" : "batch-tag",
\r
169 + NOTMUCH_DUMP_VERSION,
\r
170 + (include & DUMP_INCLUDE_CONFIG) ? "config" : "",
\r
171 + (include & DUMP_INCLUDE_TAGS) && (include & DUMP_INCLUDE_CONFIG) ? "," : "",
\r
172 + (include & DUMP_INCLUDE_TAGS) ? "tags" : "");
\r
178 database_dump_file (notmuch_database_t *notmuch, gzFile output,
\r
179 - const char *query_str, int output_format)
\r
180 + const char *query_str, int output_format, int include)
\r
182 notmuch_query_t *query;
\r
183 notmuch_messages_t *messages;
\r
184 notmuch_message_t *message;
\r
185 notmuch_tags_t *tags;
\r
187 + print_dump_header (output, output_format, include);
\r
189 + if (include & DUMP_INCLUDE_CONFIG) {
\r
190 + if (print_status_database ("notmuch dump", notmuch,
\r
191 + database_dump_config(notmuch,output)))
\r
192 + return EXIT_FAILURE;
\r
195 + if (! (include & DUMP_INCLUDE_TAGS))
\r
196 + return EXIT_SUCCESS;
\r
201 @@ -130,6 +196,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
202 const char *output_file_name,
\r
203 const char *query_str,
\r
204 dump_format_t output_format,
\r
205 + dump_include_t include,
\r
206 notmuch_bool_t gzip_output)
\r
208 gzFile output = NULL;
\r
209 @@ -164,7 +231,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
213 - ret = database_dump_file (notmuch, output, query_str, output_format);
\r
214 + ret = database_dump_file (notmuch, output, query_str, output_format, include);
\r
215 if (ret) goto DONE;
\r
217 ret = gzflush (output, Z_FINISH);
\r
218 @@ -226,6 +293,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
221 int output_format = DUMP_FORMAT_BATCH_TAG;
\r
223 notmuch_bool_t gzip_output = 0;
\r
225 notmuch_opt_desc_t options[] = {
\r
226 @@ -233,6 +301,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
227 (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
\r
228 { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
230 + { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',
\r
231 + (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },
\r
232 + { "tags", DUMP_INCLUDE_TAGS} } },
\r
233 { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
\r
234 { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },
\r
235 { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
\r
236 @@ -245,6 +316,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
238 notmuch_process_shared_options (argv[0]);
\r
240 + if (include == 0)
\r
241 + include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;
\r
243 if (opt_index < argc) {
\r
244 query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
\r
245 if (query_str == NULL) {
\r
246 @@ -254,7 +328,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
249 ret = notmuch_database_dump (notmuch, output_file_name, query_str,
\r
250 - output_format, gzip_output);
\r
251 + output_format, include, gzip_output);
\r
253 notmuch_database_destroy (notmuch);
\r
255 diff --git a/notmuch-new.c b/notmuch-new.c
\r
256 index 2d975eb..8d1545e 100644
\r
257 --- a/notmuch-new.c
\r
258 +++ b/notmuch-new.c
\r
259 @@ -1042,7 +1042,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
\r
262 if (notmuch_database_dump (notmuch, backup_name, "",
\r
263 - DUMP_FORMAT_BATCH_TAG, TRUE)) {
\r
264 + DUMP_FORMAT_BATCH_TAG, DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS, TRUE)) {
\r
265 fprintf (stderr, "Backup failed. Aborting upgrade.");
\r
266 return EXIT_FAILURE;
\r
268 diff --git a/test/T150-tagging.sh b/test/T150-tagging.sh
\r
269 index a451ffa..61d1311 100755
\r
270 --- a/test/T150-tagging.sh
\r
271 +++ b/test/T150-tagging.sh
\r
272 @@ -188,7 +188,7 @@ cat <<EOF > EXPECTED
\r
273 +%22%27%22%27%22%22%27%27 +inbox +tag4 +tag5 +unread -- id:msg-002@notmuch-test-suite
\r
276 -notmuch dump --format=batch-tag | sort > OUTPUT
\r
277 +NOTMUCH_DUMP_TAGS > OUTPUT
\r
278 notmuch restore --format=batch-tag < BACKUP
\r
279 test_expect_equal_file EXPECTED OUTPUT
\r
281 @@ -209,7 +209,7 @@ cat <<EOF > EXPECTED
\r
282 +%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
285 -notmuch dump --format=batch-tag | sort > OUTPUT
\r
286 +NOTMUCH_DUMP_TAGS > OUTPUT
\r
287 notmuch restore --format=batch-tag < BACKUP
\r
288 test_expect_equal_file EXPECTED OUTPUT
\r
290 @@ -235,7 +235,7 @@ cat <<EOF > EXPECTED
\r
291 +%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
294 -notmuch dump --format=batch-tag | sort > OUTPUT
\r
295 +NOTMUCH_DUMP_TAGS > OUTPUT
\r
296 notmuch restore --format=batch-tag < BACKUP
\r
297 test_expect_equal_file EXPECTED OUTPUT
\r
299 @@ -260,7 +260,7 @@ cat <<EOF > EXPECTED
\r
300 +foo%3a%3abar%25 +found%3a%3ait +inbox +tag5 +unread +winner -- id:msg-001@notmuch-test-suite
\r
303 -notmuch dump --format=batch-tag | sort > OUTPUT
\r
304 +NOTMUCH_DUMP_TAGS > OUTPUT
\r
305 notmuch restore --format=batch-tag < BACKUP
\r
306 test_expect_equal_file EXPECTED OUTPUT
\r
308 diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh
\r
309 index e6976ff..bbfb09b 100755
\r
310 --- a/test/T240-dump-restore.sh
\r
311 +++ b/test/T240-dump-restore.sh
\r
312 @@ -97,7 +97,7 @@ test_expect_equal_file dump.expected dump.actual
\r
313 # Note, we assume all messages from cworth have a message-id
\r
314 # containing cworth.org
\r
316 -grep 'cworth[.]org' dump.expected > dump-cworth.expected
\r
317 +{ head -1 dump.expected ; grep 'cworth[.]org' dump.expected; } > dump-cworth.expected
\r
319 test_begin_subtest "dump -- from:cworth"
\r
320 notmuch dump -- from:cworth > dump-dash-cworth.actual
\r
321 @@ -118,16 +118,16 @@ notmuch search --output=messages from:cworth | sed s/^id:// |\
\r
322 test_expect_equal_file OUTPUT EXPECTED
\r
324 test_begin_subtest "format=batch-tag, dump sanity check."
\r
325 -notmuch dump --format=sup from:cworth | cut -f1 -d' ' | \
\r
326 +NOTMUCH_DUMP_TAGS --format=sup from:cworth | cut -f1 -d' ' | \
\r
327 sort > EXPECTED.$test_count
\r
328 -notmuch dump --format=batch-tag from:cworth | sed 's/^.*-- id://' | \
\r
329 +NOTMUCH_DUMP_TAGS --format=batch-tag from:cworth | sed 's/^.*-- id://' | \
\r
330 sort > OUTPUT.$test_count
\r
331 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
\r
333 test_begin_subtest "format=batch-tag, missing newline"
\r
334 printf "+a_tag_without_newline -- id:20091117232137.GA7669@griffis1.net" > IN
\r
335 notmuch restore --accumulate < IN
\r
336 -notmuch dump id:20091117232137.GA7669@griffis1.net > OUT
\r
337 +NOTMUCH_DUMP_TAGS id:20091117232137.GA7669@griffis1.net > OUT
\r
338 cat <<EOF > EXPECTED
\r
339 +a_tag_without_newline +inbox +unread -- id:20091117232137.GA7669@griffis1.net
\r
341 @@ -155,7 +155,7 @@ cat <<EOF >EXPECTED.$test_count
\r
342 + -- id:20091117232137.GA7669@griffis1.net
\r
344 notmuch restore --format=batch-tag < EXPECTED.$test_count
\r
345 -notmuch dump --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count
\r
346 +NOTMUCH_DUMP_TAGS --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count
\r
347 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
\r
349 tag1='comic_swear=$&^%$^%\\//-+$^%$'
\r
350 @@ -217,9 +217,9 @@ notmuch dump --format=batch-tag > OUTPUT.$test_count
\r
351 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
\r
353 test_begin_subtest 'format=batch-tag, checking encoded output'
\r
354 -notmuch dump --format=batch-tag -- from:cworth |\
\r
355 +NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth |\
\r
356 awk "{ print \"+$enc1 +$enc2 +$enc3 -- \" \$5 }" > EXPECTED.$test_count
\r
357 -notmuch dump --format=batch-tag -- from:cworth > OUTPUT.$test_count
\r
358 +NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth > OUTPUT.$test_count
\r
359 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
\r
361 test_begin_subtest 'restoring sane tags'
\r
362 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
\r
363 index 8ca6883..5ea5300 100755
\r
364 --- a/test/T590-libconfig.sh
\r
365 +++ b/test/T590-libconfig.sh
\r
366 @@ -115,4 +115,21 @@ testkey2 testvalue2
\r
368 test_expect_equal_file EXPECTED OUTPUT
\r
370 +test_begin_subtest "dump config"
\r
371 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
373 + RUN(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));
\r
376 +notmuch dump --include=config >OUTPUT
\r
377 +cat <<'EOF' >EXPECTED
\r
378 +#notmuch-dump batch-tag:2 config
\r
379 +#@ aaabefore beforeval
\r
380 +#@ key%20with%20spaces value,%20with,%20spaces%21
\r
381 +#@ testkey1 testvalue1
\r
382 +#@ testkey2 testvalue2
\r
383 +#@ zzzafter afterval
\r
385 +test_expect_equal_file EXPECTED OUTPUT
\r
388 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
389 index 09f8731..68a8774 100644
\r
390 --- a/test/test-lib.sh
\r
391 +++ b/test/test-lib.sh
\r
392 @@ -673,6 +673,12 @@ NOTMUCH_NEW ()
\r
393 notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
\r
396 +NOTMUCH_DUMP_TAGS ()
\r
398 + # this relies on the default format being batch-tag, otherwise some tests will break
\r
399 + notmuch dump --include=tags "${@}" | sed '/^#/d' | sort
\r
402 notmuch_search_sanitize ()
\r
404 perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
\r