1 Return-Path: <thomas@schwinge.name>
\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 olra.theworths.org (Postfix) with ESMTP id A9C2E431FD0
\r
6 for <notmuch@notmuchmail.org>; Mon, 5 Sep 2011 12:14:30 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id Ko57vJQykeGw for <notmuch@notmuchmail.org>;
\r
16 Mon, 5 Sep 2011 12:14:28 -0700 (PDT)
\r
17 X-Greylist: delayed 379 seconds by postgrey-1.32 at olra;
\r
18 Mon, 05 Sep 2011 12:14:28 PDT
\r
19 Received: from smtprelay03.ispgateway.de (smtprelay03.ispgateway.de
\r
21 by olra.theworths.org (Postfix) with ESMTP id 7E473431FB6
\r
22 for <notmuch@notmuchmail.org>; Mon, 5 Sep 2011 12:14:28 -0700 (PDT)
\r
23 Received: from [87.180.32.105] (helo=stokes.schwinge.homeip.net)
\r
24 by smtprelay03.ispgateway.de with esmtpa (Exim 4.68)
\r
25 (envelope-from <thomas@schwinge.name>) id 1R0eWb-0005OW-TD
\r
26 for notmuch@notmuchmail.org; Mon, 05 Sep 2011 21:08:06 +0200
\r
27 Received: (qmail 14781 invoked from network); 5 Sep 2011 19:07:36 -0000
\r
28 Received: from kepler.schwinge.homeip.net (192.168.111.7)
\r
29 by stokes.schwinge.homeip.net with QMQP; 5 Sep 2011 19:07:36 -0000
\r
30 Received: (nullmailer pid 20213 invoked by uid 1000);
\r
31 Mon, 05 Sep 2011 19:07:35 -0000
\r
32 From: Thomas Schwinge <thomas@schwinge.name>
\r
33 To: notmuch@notmuchmail.org
\r
34 Subject: =?UTF-8?q?=5BPATCH=5D=20notmuch=20restore=20--accumulate?=
\r
35 Date: Mon, 5 Sep 2011 21:07:17 +0200
\r
36 Message-Id: <1315249637-20179-1-git-send-email-thomas@schwinge.name>
\r
37 X-Mailer: git-send-email 1.7.5.4
\r
39 Content-Type: text/plain; charset=UTF-8
\r
40 Content-Transfer-Encoding: 8bit
\r
41 X-Df-Sender: dGhvbWFzQHNjaHdpbmdlLm5hbWU=
\r
42 Cc: Thomas Schwinge <thomas@schwinge.name>
\r
43 X-BeenThere: notmuch@notmuchmail.org
\r
44 X-Mailman-Version: 2.1.13
\r
46 List-Id: "Use and development of the notmuch mail system."
\r
47 <notmuch.notmuchmail.org>
\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
51 List-Post: <mailto:notmuch@notmuchmail.org>
\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
55 X-List-Received-Date: Mon, 05 Sep 2011 19:14:30 -0000
\r
57 From: Thomas Schwinge <thomas@schwinge.name>
\r
59 Also enhance the dump-restore testsuite, and make it generally more
\r
62 Signed-off-by: Thomas Schwinge <thomas@schwinge.name>
\r
68 Beware that I have not yet used this new functionality in the wild. ;-)
\r
69 (But I do plan to do so, soon.) And, I think that the testsuite
\r
70 enhancements cover quite a number of real-world scenarios.
\r
78 NEWS | 13 ++++++++++
\r
79 notmuch-restore.c | 42 ++++++++++++++++++++++++++-------
\r
80 notmuch.1 | 14 ++++++++---
\r
81 notmuch.c | 10 +++++--
\r
82 test/dump-restore | 67 ++++++++++++++++++++++++++++++++++++++++------------
\r
83 test/test-lib.sh | 1 +
\r
84 6 files changed, 115 insertions(+), 32 deletions(-)
\r
86 diff --git a/NEWS b/NEWS
\r
87 index f715142..d2a788f 100644
\r
91 +Notmuch TODO (TODO)
\r
92 +===================
\r
94 +New command-line features
\r
95 +-------------------------
\r
97 +Add "notmuch restore --accumulate" option
\r
99 + The --accumulate switch causes the union of the existing and new tags to be
\r
100 + applied, instead of replacing each message's tags as they are read in from
\r
104 Notmuch 0.7 (2011-08-01)
\r
105 ========================
\r
107 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
108 index f095f64..5aad60c 100644
\r
109 --- a/notmuch-restore.c
\r
110 +++ b/notmuch-restore.c
\r
111 @@ -31,7 +31,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
116 + notmuch_bool_t accumulate;
\r
119 config = notmuch_config_open (ctx, NULL, NULL);
\r
120 if (config == NULL)
\r
121 @@ -44,14 +45,28 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
123 synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
126 - input = fopen (argv[0], "r");
\r
127 - if (input == NULL) {
\r
128 - fprintf (stderr, "Error opening %s for reading: %s\n",
\r
129 - argv[0], strerror (errno));
\r
131 + accumulate = FALSE;
\r
133 + for (i = 0; i < argc; i++) {
\r
134 + if (STRNCMP_LITERAL (argv[i], "--accumulate") == 0) {
\r
135 + accumulate = TRUE;
\r
137 + if (input == NULL) {
\r
138 + input = fopen (argv[i], "r");
\r
139 + if (input == NULL) {
\r
140 + fprintf (stderr, "Error opening %s for reading: %s\n",
\r
141 + argv[i], strerror (errno));
\r
146 + "Cannot read dump from more than one file: %s\n",
\r
153 + if (input == NULL) {
\r
154 printf ("No filename given. Reading dump from stdin.\n");
\r
157 @@ -94,6 +109,13 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
161 + /* In order to detect missing messages, this check/optimization is
\r
162 + * intentionally done *after* first finding the message. */
\r
163 + if (accumulate && (file_tags == NULL || *file_tags == '\0'))
\r
168 db_tags_str = NULL;
\r
169 for (db_tags = notmuch_message_get_tags (message);
\r
170 notmuch_tags_valid (db_tags);
\r
171 @@ -115,7 +137,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
174 notmuch_message_freeze (message);
\r
175 - notmuch_message_remove_all_tags (message);
\r
178 + notmuch_message_remove_all_tags (message);
\r
182 diff --git a/notmuch.1 b/notmuch.1
\r
183 index 5a8c83d..883371d 100644
\r
186 @@ -454,7 +454,7 @@ section below for details of the supported syntax for <search-terms>.
\r
188 .BR dump " and " restore
\r
189 commands can be used to create a textual dump of email tags for backup
\r
190 -purposes, and to restore from that dump
\r
191 +purposes, and to restore from that dump.
\r
195 @@ -462,17 +462,19 @@ purposes, and to restore from that dump
\r
197 Creates a plain-text dump of the tags of each message.
\r
199 -The output is to the given filename, if any, or to stdout.
\r
200 +The output is written to the given filename, if any, or to stdout.
\r
202 These tags are the only data in the notmuch database that can't be
\r
203 recreated from the messages themselves. The output of notmuch dump is
\r
204 therefore the only critical thing to backup (and much more friendly to
\r
205 incremental backup than the native database files.)
\r
207 -.BR restore " <filename>"
\r
208 +.BR restore " [--accumulate] [<filename>]"
\r
210 Restores the tags from the given file (see
\r
211 -.BR "notmuch dump" "."
\r
212 +.BR "notmuch dump" ")."
\r
214 +The input is read from the given filename, if any, or from stdin.
\r
216 Note: The dump file format is specifically chosen to be
\r
217 compatible with the format of files produced by sup-dump.
\r
218 @@ -480,6 +482,10 @@ So if you've previously been using sup for mail, then the
\r
219 .B "notmuch restore"
\r
220 command provides you a way to import all of your tags (or labels as
\r
223 +The --accumulate switch causes the union of the existing and new tags to be
\r
224 +applied, instead of replacing each message's tags as they are read in from the
\r
229 diff --git a/notmuch.c b/notmuch.c
\r
230 index 3973e35..def52b0 100644
\r
233 @@ -377,20 +377,24 @@ static command_t commands[] = {
\r
234 { "dump", notmuch_dump_command,
\r
236 "Create a plain-text dump of the tags for each message.",
\r
237 - "\tOutput is to the given filename, if any, or to stdout.\n"
\r
238 + "\tOutput is written to the given filename, if any, or to stdout.\n"
\r
239 "\tThese tags are the only data in the notmuch database\n"
\r
240 "\tthat can't be recreated from the messages themselves.\n"
\r
241 "\tThe output of notmuch dump is therefore the only\n"
\r
242 "\tcritical thing to backup (and much more friendly to\n"
\r
243 "\tincremental backup than the native database files.)" },
\r
244 { "restore", notmuch_restore_command,
\r
246 + "[--accumulate] [<filename>]",
\r
247 "Restore the tags from the given dump file (see 'dump').",
\r
248 + "\tInput is read from the given filename, if any, or from stdin.\n"
\r
249 "\tNote: The dump file format is specifically chosen to be\n"
\r
250 "\tcompatible with the format of files produced by sup-dump.\n"
\r
251 "\tSo if you've previously been using sup for mail, then the\n"
\r
252 "\t\"notmuch restore\" command provides you a way to import\n"
\r
253 - "\tall of your tags (or labels as sup calls them)." },
\r
254 + "\tall of your tags (or labels as sup calls them).\n"
\r
255 + "\tThe --accumulate switch causes the union of the existing and new\n"
\r
256 + "\ttags to be applied, instead of replacing each message's tags as\n"
\r
257 + "\tthey are read in from the dump file."},
\r
258 { "config", notmuch_config_command,
\r
259 "[get|set] <section>.<item> [value ...]",
\r
260 "Get or set settings in the notmuch configuration file.",
\r
261 diff --git a/test/dump-restore b/test/dump-restore
\r
262 index a4de370..c85f10e 100755
\r
263 --- a/test/dump-restore
\r
264 +++ b/test/dump-restore
\r
265 @@ -4,21 +4,56 @@ test_description="\"notmuch dump\" and \"notmuch restore\""
\r
269 -test_expect_success "Dumping all tags" "generate_message &&
\r
271 -notmuch dump dump.expected"
\r
273 -test_begin_subtest "Clearing all tags"
\r
274 -sed -e "s/(\([^(]*\))$/()/" < dump.expected > clear.expected
\r
275 -notmuch restore clear.expected
\r
276 -notmuch dump clear.actual
\r
277 -test_expect_equal "$(< clear.actual)" "$(< clear.expected)"
\r
279 -test_begin_subtest "Restoring original tags"
\r
280 -notmuch restore dump.expected
\r
281 -notmuch dump dump.actual
\r
282 -test_expect_equal "$(< dump.actual)" "$(< dump.expected)"
\r
284 -test_expect_success "Restore with nothing to do" "notmuch restore dump.expected"
\r
285 +test_expect_success 'Dumping all tags' \
\r
286 + 'generate_message &&
\r
288 + notmuch dump dump.expected'
\r
290 +# This is rather arbitrary: it matches some of the email corpus' messages, but
\r
291 +# not all of them.
\r
292 +search_term=from:worth
\r
294 +test_expect_success 'Dumping all tags to stdout' \
\r
295 + 'notmuch tag +ABC +DEF -- $search_term &&
\r
296 + notmuch dump > dump-ABC_DEF.expected &&
\r
297 + ! cmp dump.expected dump-ABC_DEF.expected'
\r
299 +test_expect_success 'Clearing all tags' \
\r
300 + 'sed -e "s/(\([^(]*\))$/()/" < dump.expected > clear.expected &&
\r
301 + notmuch restore clear.expected &&
\r
302 + notmuch dump clear.actual &&
\r
303 + test_cmp clear.expected clear.actual'
\r
305 +test_expect_success 'Accumulate original tags' \
\r
306 + 'notmuch tag +ABC +DEF -- $search_term &&
\r
307 + notmuch restore --accumulate < dump.expected &&
\r
308 + notmuch dump dump.actual &&
\r
309 + test_cmp dump-ABC_DEF.expected dump.actual'
\r
311 +test_expect_success 'Restoring original tags' \
\r
312 + 'notmuch restore dump.expected &&
\r
313 + notmuch dump dump.actual &&
\r
314 + test_cmp dump.expected dump.actual'
\r
316 +test_expect_success 'Restore with nothing to do' \
\r
317 + 'notmuch restore < dump.expected &&
\r
318 + notmuch dump > dump.actual &&
\r
319 + test_cmp dump.expected dump.actual'
\r
321 +test_expect_success 'Restore with nothing to do, II' \
\r
322 + 'notmuch restore --accumulate dump.expected &&
\r
323 + notmuch dump dump.actual &&
\r
324 + test_cmp dump.expected dump.actual'
\r
326 +test_expect_success 'Restore with nothing to do, III' \
\r
327 + 'notmuch restore --accumulate < clear.expected &&
\r
328 + notmuch dump dump.actual &&
\r
329 + test_cmp dump.expected dump.actual'
\r
331 +test_expect_success 'Invalid restore invocation' \
\r
332 + '! notmuch restore one two'
\r
334 +test_expect_success 'Invalid restore invocation, II' \
\r
335 + '! notmuch restore --accumulate one two'
\r
338 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
339 index 22e387e..56bbce4 100755
\r
340 --- a/test/test-lib.sh
\r
341 +++ b/test/test-lib.sh
\r
342 @@ -461,6 +461,7 @@ test_expect_equal ()
\r
346 +# Like test_expect_equal, but takes two filenames.
\r
347 test_expect_equal_file ()
\r
349 exec 1>&6 2>&7 # Restore stdout and stderr
\r
351 tg: (8e2a14b..) t/restore-accumulate (depends on: master)
\r