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 46CD46DE0931
\r
6 for <notmuch@notmuchmail.org>; Wed, 25 May 2016 03:52:04 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.001, 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 h5tyTwJSPLZ1 for <notmuch@notmuchmail.org>;
\r
17 Wed, 25 May 2016 03:51:55 -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 0C21E6DE02B5
\r
20 for <notmuch@notmuchmail.org>; Wed, 25 May 2016 03:51:39 -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 1b5WPR-0004UN-KJ; Wed, 25 May 2016 06:51:29 -0400
\r
24 Received: (nullmailer pid 23140 invoked by uid 1000);
\r
25 Wed, 25 May 2016 10:51:31 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [Patch v6 3/7] CLI: add optional config data to dump output.
\r
29 Date: Wed, 25 May 2016 07:51:22 -0300
\r
30 Message-Id: <1464173486-23032-4-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.8.1
\r
32 In-Reply-To: <1464173486-23032-1-git-send-email-david@tethera.net>
\r
33 References: <1464173486-23032-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: Wed, 25 May 2016 10:52:04 -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 | 78 +++++++++++++++++++++++++++++++++++++++++++++--
\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, 135 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..c130b93 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..8e79511 100644
\r
115 --- a/notmuch-dump.c
\r
116 +++ b/notmuch-dump.c
\r
117 @@ -23,16 +23,80 @@
\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
176 database_dump_file (notmuch_database_t *notmuch, gzFile output,
\r
177 - const char *query_str, int output_format)
\r
178 + const char *query_str, int output_format, int include)
\r
180 notmuch_query_t *query;
\r
181 notmuch_messages_t *messages;
\r
182 notmuch_message_t *message;
\r
183 notmuch_tags_t *tags;
\r
185 + print_dump_header (output, output_format, include);
\r
187 + if (include & DUMP_INCLUDE_CONFIG) {
\r
188 + if (print_status_database ("notmuch dump", notmuch,
\r
189 + database_dump_config(notmuch,output)))
\r
190 + return EXIT_FAILURE;
\r
193 + if (! (include & DUMP_INCLUDE_TAGS))
\r
194 + return EXIT_SUCCESS;
\r
199 @@ -130,6 +194,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
200 const char *output_file_name,
\r
201 const char *query_str,
\r
202 dump_format_t output_format,
\r
203 + dump_include_t include,
\r
204 notmuch_bool_t gzip_output)
\r
206 gzFile output = NULL;
\r
207 @@ -164,7 +229,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
211 - ret = database_dump_file (notmuch, output, query_str, output_format);
\r
212 + ret = database_dump_file (notmuch, output, query_str, output_format, include);
\r
213 if (ret) goto DONE;
\r
215 ret = gzflush (output, Z_FINISH);
\r
216 @@ -226,6 +291,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
219 int output_format = DUMP_FORMAT_BATCH_TAG;
\r
221 notmuch_bool_t gzip_output = 0;
\r
223 notmuch_opt_desc_t options[] = {
\r
224 @@ -233,6 +299,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
225 (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
\r
226 { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
228 + { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',
\r
229 + (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },
\r
230 + { "tags", DUMP_INCLUDE_TAGS} } },
\r
231 { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
\r
232 { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },
\r
233 { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
\r
234 @@ -245,6 +314,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
236 notmuch_process_shared_options (argv[0]);
\r
238 + if (include == 0)
\r
239 + include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;
\r
241 if (opt_index < argc) {
\r
242 query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
\r
243 if (query_str == NULL) {
\r
244 @@ -254,7 +326,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
247 ret = notmuch_database_dump (notmuch, output_file_name, query_str,
\r
248 - output_format, gzip_output);
\r
249 + output_format, include, gzip_output);
\r
251 notmuch_database_destroy (notmuch);
\r
253 diff --git a/notmuch-new.c b/notmuch-new.c
\r
254 index 2d975eb..8d1545e 100644
\r
255 --- a/notmuch-new.c
\r
256 +++ b/notmuch-new.c
\r
257 @@ -1042,7 +1042,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
\r
260 if (notmuch_database_dump (notmuch, backup_name, "",
\r
261 - DUMP_FORMAT_BATCH_TAG, TRUE)) {
\r
262 + DUMP_FORMAT_BATCH_TAG, DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS, TRUE)) {
\r
263 fprintf (stderr, "Backup failed. Aborting upgrade.");
\r
264 return EXIT_FAILURE;
\r
266 diff --git a/test/T150-tagging.sh b/test/T150-tagging.sh
\r
267 index a451ffa..61d1311 100755
\r
268 --- a/test/T150-tagging.sh
\r
269 +++ b/test/T150-tagging.sh
\r
270 @@ -188,7 +188,7 @@ cat <<EOF > EXPECTED
\r
271 +%22%27%22%27%22%22%27%27 +inbox +tag4 +tag5 +unread -- id:msg-002@notmuch-test-suite
\r
274 -notmuch dump --format=batch-tag | sort > OUTPUT
\r
275 +NOTMUCH_DUMP_TAGS > OUTPUT
\r
276 notmuch restore --format=batch-tag < BACKUP
\r
277 test_expect_equal_file EXPECTED OUTPUT
\r
279 @@ -209,7 +209,7 @@ cat <<EOF > EXPECTED
\r
280 +%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
283 -notmuch dump --format=batch-tag | sort > OUTPUT
\r
284 +NOTMUCH_DUMP_TAGS > OUTPUT
\r
285 notmuch restore --format=batch-tag < BACKUP
\r
286 test_expect_equal_file EXPECTED OUTPUT
\r
288 @@ -235,7 +235,7 @@ cat <<EOF > EXPECTED
\r
289 +%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
292 -notmuch dump --format=batch-tag | sort > OUTPUT
\r
293 +NOTMUCH_DUMP_TAGS > OUTPUT
\r
294 notmuch restore --format=batch-tag < BACKUP
\r
295 test_expect_equal_file EXPECTED OUTPUT
\r
297 @@ -260,7 +260,7 @@ cat <<EOF > EXPECTED
\r
298 +foo%3a%3abar%25 +found%3a%3ait +inbox +tag5 +unread +winner -- id:msg-001@notmuch-test-suite
\r
301 -notmuch dump --format=batch-tag | sort > OUTPUT
\r
302 +NOTMUCH_DUMP_TAGS > OUTPUT
\r
303 notmuch restore --format=batch-tag < BACKUP
\r
304 test_expect_equal_file EXPECTED OUTPUT
\r
306 diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh
\r
307 index e6976ff..bbfb09b 100755
\r
308 --- a/test/T240-dump-restore.sh
\r
309 +++ b/test/T240-dump-restore.sh
\r
310 @@ -97,7 +97,7 @@ test_expect_equal_file dump.expected dump.actual
\r
311 # Note, we assume all messages from cworth have a message-id
\r
312 # containing cworth.org
\r
314 -grep 'cworth[.]org' dump.expected > dump-cworth.expected
\r
315 +{ head -1 dump.expected ; grep 'cworth[.]org' dump.expected; } > dump-cworth.expected
\r
317 test_begin_subtest "dump -- from:cworth"
\r
318 notmuch dump -- from:cworth > dump-dash-cworth.actual
\r
319 @@ -118,16 +118,16 @@ notmuch search --output=messages from:cworth | sed s/^id:// |\
\r
320 test_expect_equal_file OUTPUT EXPECTED
\r
322 test_begin_subtest "format=batch-tag, dump sanity check."
\r
323 -notmuch dump --format=sup from:cworth | cut -f1 -d' ' | \
\r
324 +NOTMUCH_DUMP_TAGS --format=sup from:cworth | cut -f1 -d' ' | \
\r
325 sort > EXPECTED.$test_count
\r
326 -notmuch dump --format=batch-tag from:cworth | sed 's/^.*-- id://' | \
\r
327 +NOTMUCH_DUMP_TAGS --format=batch-tag from:cworth | sed 's/^.*-- id://' | \
\r
328 sort > OUTPUT.$test_count
\r
329 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
\r
331 test_begin_subtest "format=batch-tag, missing newline"
\r
332 printf "+a_tag_without_newline -- id:20091117232137.GA7669@griffis1.net" > IN
\r
333 notmuch restore --accumulate < IN
\r
334 -notmuch dump id:20091117232137.GA7669@griffis1.net > OUT
\r
335 +NOTMUCH_DUMP_TAGS id:20091117232137.GA7669@griffis1.net > OUT
\r
336 cat <<EOF > EXPECTED
\r
337 +a_tag_without_newline +inbox +unread -- id:20091117232137.GA7669@griffis1.net
\r
339 @@ -155,7 +155,7 @@ cat <<EOF >EXPECTED.$test_count
\r
340 + -- id:20091117232137.GA7669@griffis1.net
\r
342 notmuch restore --format=batch-tag < EXPECTED.$test_count
\r
343 -notmuch dump --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count
\r
344 +NOTMUCH_DUMP_TAGS --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count
\r
345 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
\r
347 tag1='comic_swear=$&^%$^%\\//-+$^%$'
\r
348 @@ -217,9 +217,9 @@ notmuch dump --format=batch-tag > OUTPUT.$test_count
\r
349 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
\r
351 test_begin_subtest 'format=batch-tag, checking encoded output'
\r
352 -notmuch dump --format=batch-tag -- from:cworth |\
\r
353 +NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth |\
\r
354 awk "{ print \"+$enc1 +$enc2 +$enc3 -- \" \$5 }" > EXPECTED.$test_count
\r
355 -notmuch dump --format=batch-tag -- from:cworth > OUTPUT.$test_count
\r
356 +NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth > OUTPUT.$test_count
\r
357 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
\r
359 test_begin_subtest 'restoring sane tags'
\r
360 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
\r
361 index 8ca6883..5ea5300 100755
\r
362 --- a/test/T590-libconfig.sh
\r
363 +++ b/test/T590-libconfig.sh
\r
364 @@ -115,4 +115,21 @@ testkey2 testvalue2
\r
366 test_expect_equal_file EXPECTED OUTPUT
\r
368 +test_begin_subtest "dump config"
\r
369 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
371 + RUN(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));
\r
374 +notmuch dump --include=config >OUTPUT
\r
375 +cat <<'EOF' >EXPECTED
\r
376 +#notmuch-dump batch-tag:2 config
\r
377 +#@ aaabefore beforeval
\r
378 +#@ key%20with%20spaces value,%20with,%20spaces%21
\r
379 +#@ testkey1 testvalue1
\r
380 +#@ testkey2 testvalue2
\r
381 +#@ zzzafter afterval
\r
383 +test_expect_equal_file EXPECTED OUTPUT
\r
386 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
387 index 62e123d..e439862 100644
\r
388 --- a/test/test-lib.sh
\r
389 +++ b/test/test-lib.sh
\r
390 @@ -674,6 +674,12 @@ NOTMUCH_NEW ()
\r
391 notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
\r
394 +NOTMUCH_DUMP_TAGS ()
\r
396 + # this relies on the default format being batch-tag, otherwise some tests will break
\r
397 + notmuch dump --include=tags "${@}" | sed '/^#/d' | sort
\r
400 notmuch_search_sanitize ()
\r
402 perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
\r