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 F22946DE01FF
\r
6 for <notmuch@notmuchmail.org>; Tue, 12 Jan 2016 19:10:28 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.311 tagged_above=-999 required=5 tests=[AWL=0.240,
\r
12 RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] 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 cFR9P_HEN4-j for <notmuch@notmuchmail.org>;
\r
16 Tue, 12 Jan 2016 19:10:27 -0800 (PST)
\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
18 by arlo.cworth.org (Postfix) with ESMTPS id A316D6DE0B4F
\r
19 for <notmuch@notmuchmail.org>; Tue, 12 Jan 2016 19:10:24 -0800 (PST)
\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
21 (envelope-from <bremner@tethera.net>)
\r
22 id 1aJBp8-0000ye-8s; Tue, 12 Jan 2016 22:10:14 -0500
\r
23 Received: (nullmailer pid 23106 invoked by uid 1000);
\r
24 Wed, 13 Jan 2016 03:10:18 -0000
\r
25 From: David Bremner <david@tethera.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [WIP2 4/4] CLI: add optional metadata to dump output.
\r
28 Date: Tue, 12 Jan 2016 23:10:10 -0400
\r
29 Message-Id: <1452654610-22864-5-git-send-email-david@tethera.net>
\r
30 X-Mailer: git-send-email 2.6.4
\r
31 In-Reply-To: <1452654610-22864-1-git-send-email-david@tethera.net>
\r
32 References: <1452654610-22864-1-git-send-email-david@tethera.net>
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.20
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Wed, 13 Jan 2016 03:10:29 -0000
\r
47 This lacks at least documentation. Note that it changes the default dump
\r
48 output format, but doesn't break existing notmuch-restore. It might
\r
49 break user scripts though.
\r
51 notmuch-client.h | 6 ++++++
\r
52 notmuch-dump.c | 41 ++++++++++++++++++++++++++++++++++++++---
\r
53 notmuch-new.c | 2 +-
\r
54 test/T590-libconfig.sh | 10 ++++++++++
\r
55 4 files changed, 55 insertions(+), 4 deletions(-)
\r
57 diff --git a/notmuch-client.h b/notmuch-client.h
\r
58 index 7c9a1ea..2dca83c 100644
\r
59 --- a/notmuch-client.h
\r
60 +++ b/notmuch-client.h
\r
61 @@ -443,11 +443,17 @@ typedef enum dump_formats {
\r
65 +typedef enum dump_includes {
\r
66 + DUMP_INCLUDE_TAGS=1,
\r
67 + DUMP_INCLUDE_CONFIG=2,
\r
71 notmuch_database_dump (notmuch_database_t *notmuch,
\r
72 const char *output_file_name,
\r
73 const char *query_str,
\r
74 dump_format_t output_format,
\r
75 + dump_include_t include,
\r
76 notmuch_bool_t gzip_output);
\r
78 /* If status is non-zero (i.e. error) print appropriate
\r
79 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
80 index 829781f..4909493 100644
\r
81 --- a/notmuch-dump.c
\r
82 +++ b/notmuch-dump.c
\r
84 #include "string-util.h"
\r
87 +static notmuch_status_t
\r
88 +database_dump_config(notmuch_database_t *notmuch, gzFile output)
\r
90 + notmuch_config_list_t *list;
\r
91 + notmuch_status_t status;
\r
92 + status = notmuch_database_get_config_list (notmuch, NULL, &list);
\r
96 + for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
\r
97 + /* FIXME hexencode key and values */
\r
98 + gzprintf(output, "#@ %s %s\n",
\r
99 + notmuch_config_list_key (list), notmuch_config_list_value (list));
\r
101 + notmuch_config_list_destroy (list);
\r
103 + return NOTMUCH_STATUS_SUCCESS;
\r
107 database_dump_file (notmuch_database_t *notmuch, gzFile output,
\r
108 - const char *query_str, int output_format)
\r
109 + const char *query_str, int output_format, int include)
\r
111 notmuch_query_t *query;
\r
112 notmuch_messages_t *messages;
\r
113 notmuch_message_t *message;
\r
114 notmuch_tags_t *tags;
\r
116 + if (include | DUMP_INCLUDE_CONFIG) {
\r
117 + if (print_status_database ("notmuch dump", notmuch,
\r
118 + database_dump_config(notmuch,output)))
\r
119 + return EXIT_FAILURE;
\r
122 + if (! (include & DUMP_INCLUDE_TAGS))
\r
123 + return EXIT_SUCCESS;
\r
128 @@ -130,6 +157,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
129 const char *output_file_name,
\r
130 const char *query_str,
\r
131 dump_format_t output_format,
\r
132 + dump_include_t include,
\r
133 notmuch_bool_t gzip_output)
\r
135 gzFile output = NULL;
\r
136 @@ -164,7 +192,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
140 - ret = database_dump_file (notmuch, output, query_str, output_format);
\r
141 + ret = database_dump_file (notmuch, output, query_str, output_format, include);
\r
142 if (ret) goto DONE;
\r
144 ret = gzflush (output, Z_FINISH);
\r
145 @@ -226,6 +254,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
148 int output_format = DUMP_FORMAT_BATCH_TAG;
\r
150 notmuch_bool_t gzip_output = 0;
\r
152 notmuch_opt_desc_t options[] = {
\r
153 @@ -233,6 +262,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
154 (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
\r
155 { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
157 + { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'i',
\r
158 + (notmuch_keyword_t []){ { "metadata", DUMP_INCLUDE_CONFIG },
\r
159 + { "tags", DUMP_INCLUDE_TAGS} } },
\r
160 { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
\r
161 { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },
\r
162 { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
\r
163 @@ -245,6 +277,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
165 notmuch_process_shared_options (argv[0]);
\r
167 + if (include == 0)
\r
168 + include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;
\r
170 if (opt_index < argc) {
\r
171 query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
\r
172 if (query_str == NULL) {
\r
173 @@ -254,7 +289,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
176 ret = notmuch_database_dump (notmuch, output_file_name, query_str,
\r
177 - output_format, gzip_output);
\r
178 + output_format, include, gzip_output);
\r
180 notmuch_database_destroy (notmuch);
\r
182 diff --git a/notmuch-new.c b/notmuch-new.c
\r
183 index e503776..fd2ff82 100644
\r
184 --- a/notmuch-new.c
\r
185 +++ b/notmuch-new.c
\r
186 @@ -1041,7 +1041,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
\r
189 if (notmuch_database_dump (notmuch, backup_name, "",
\r
190 - DUMP_FORMAT_BATCH_TAG, TRUE)) {
\r
191 + DUMP_FORMAT_BATCH_TAG, DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS, TRUE)) {
\r
192 fprintf (stderr, "Backup failed. Aborting upgrade.");
\r
193 return EXIT_FAILURE;
\r
195 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
\r
196 index 8ca6883..4fe6bd1 100755
\r
197 --- a/test/T590-libconfig.sh
\r
198 +++ b/test/T590-libconfig.sh
\r
199 @@ -115,4 +115,14 @@ testkey2 testvalue2
\r
201 test_expect_equal_file EXPECTED OUTPUT
\r
203 +test_begin_subtest "dump config"
\r
204 +notmuch dump --include=metadata >OUTPUT
\r
205 +cat <<'EOF' >EXPECTED
\r
206 +#@ aaabefore beforeval
\r
207 +#@ testkey1 testvalue1
\r
208 +#@ testkey2 testvalue2
\r
209 +#@ zzzafter afterval
\r
211 +test_expect_equal_file EXPECTED OUTPUT
\r