1 Return-Path: <bremner@pivot.cs.unb.ca>
\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 85D69429E29
\r
6 for <notmuch@notmuchmail.org>; Fri, 21 Oct 2011 12:48:14 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 fwwl510BJXho for <notmuch@notmuchmail.org>;
\r
16 Fri, 21 Oct 2011 12:48:13 -0700 (PDT)
\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])
\r
18 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 81009429E2E
\r
21 for <notmuch@notmuchmail.org>; Fri, 21 Oct 2011 12:48:11 -0700 (PDT)
\r
22 Received: from convex-new.cs.unb.ca ([131.202.13.154])
\r
23 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9LJm4NU002203;
\r
24 Fri, 21 Oct 2011 16:48:07 -0300
\r
25 Received: from bremner by convex-new.cs.unb.ca with local (Exim 4.72)
\r
26 (envelope-from <bremner@pivot.cs.unb.ca>)
\r
27 id 1RHL4W-00016W-Rd; Fri, 21 Oct 2011 16:48:04 -0300
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: [PATCH 4/6] notmuch-restore: implement --accumulate option
\r
31 Date: Fri, 21 Oct 2011 16:47:55 -0300
\r
32 Message-Id: <1319226477-4181-5-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 1.7.5.4
\r
34 In-Reply-To: <1319226477-4181-1-git-send-email-david@tethera.net>
\r
35 References: <1317317857-29636-1-git-send-email-thomas@schwinge.name>
\r
36 <1319226477-4181-1-git-send-email-david@tethera.net>
\r
37 Cc: David Bremner <bremner@debian.org>
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Fri, 21 Oct 2011 19:48:15 -0000
\r
52 From: David Bremner <bremner@debian.org>
\r
54 Modify command line argument handling to take a --accumulate flag.
\r
55 Test for extra arguments beyond the input file.
\r
57 The --accumulate switch causes the union of the existing and new tags to be
\r
58 applied, instead of replacing each message's tags as they are read in from the
\r
61 Based on a patch by Thomas Schwinge:
\r
63 id:"1317317857-29636-1-git-send-email-thomas@schwinge.name"
\r
65 notmuch-restore.c | 45 ++++++++++++++++++++++++++++++++++++---------
\r
66 test/dump-restore | 3 ---
\r
67 2 files changed, 36 insertions(+), 12 deletions(-)
\r
69 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
70 index f530bb4..097ca4b 100644
\r
71 --- a/notmuch-restore.c
\r
72 +++ b/notmuch-restore.c
\r
74 * Author: Carl Worth <cworth@cworth.org>
\r
77 +#include <getopt.h>
\r
79 #include "notmuch-client.h"
\r
82 @@ -26,7 +28,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
83 notmuch_config_t *config;
\r
84 notmuch_database_t *notmuch;
\r
85 notmuch_bool_t synchronize_flags;
\r
87 + notmuch_bool_t accumulate = FALSE;
\r
88 + FILE *input = stdin;
\r
92 @@ -44,18 +47,33 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
94 synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
96 - argc--; argv++; /* skip subcommand argument */
\r
97 + struct option options[] = {
\r
98 + { "accumulate", no_argument, 0, 'a' },
\r
104 + opt = getopt_long (argc, argv, "", options, NULL);
\r
114 + } while (opt != -1);
\r
117 - input = fopen (argv[0], "r");
\r
118 + if (optind < argc) {
\r
119 + input = fopen (argv[optind], "r");
\r
120 if (input == NULL) {
\r
121 fprintf (stderr, "Error opening %s for reading: %s\n",
\r
122 - argv[0], strerror (errno));
\r
123 + argv[optind], strerror (errno));
\r
127 - printf ("No filename given. Reading dump from stdin.\n");
\r
132 /* Dump output is one line per message. We match a sequence of
\r
133 @@ -99,6 +117,13 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
137 + /* In order to detect missing messages, this check/optimization is
\r
138 + * intentionally done *after* first finding the message. */
\r
139 + if (accumulate && (file_tags == NULL || *file_tags == '\0'))
\r
144 db_tags_str = NULL;
\r
145 for (db_tags = notmuch_message_get_tags (message);
\r
146 notmuch_tags_valid (db_tags);
\r
147 @@ -120,7 +145,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
150 notmuch_message_freeze (message);
\r
151 - notmuch_message_remove_all_tags (message);
\r
154 + notmuch_message_remove_all_tags (message);
\r
158 diff --git a/test/dump-restore b/test/dump-restore
\r
159 index 276dd6f..2f8dcc7 100755
\r
160 --- a/test/dump-restore
\r
161 +++ b/test/dump-restore
\r
162 @@ -23,7 +23,6 @@ test_expect_success 'Clearing all tags' \
\r
163 notmuch dump > clear.actual &&
\r
164 test_cmp clear.expected clear.actual'
\r
166 -test_subtest_known_broken # missing --accumuluate
\r
167 test_expect_success 'Accumulate original tags' \
\r
168 'notmuch tag +ABC +DEF -- from:cworth &&
\r
169 notmuch restore --accumulate < dump.expected &&
\r
170 @@ -40,13 +39,11 @@ test_expect_success 'Restore with nothing to do' \
\r
171 notmuch dump > dump.actual &&
\r
172 test_cmp dump.expected dump.actual'
\r
174 -test_subtest_known_broken # missing --accumuluate
\r
175 test_expect_success 'Restore with nothing to do, II' \
\r
176 'notmuch restore --accumulate dump.expected &&
\r
177 notmuch dump > dump.actual &&
\r
178 test_cmp dump.expected dump.actual'
\r
180 -test_subtest_known_broken # missing --accumuluate
\r
181 test_expect_success 'Restore with nothing to do, III' \
\r
182 'notmuch restore --accumulate < clear.expected &&
\r
183 notmuch dump > dump.actual &&
\r