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 olra.theworths.org (Postfix) with ESMTP id C7824429E30
\r
6 for <notmuch@notmuchmail.org>; Sun, 18 Dec 2011 05:15:42 -0800 (PST)
\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 VxMiOGte2CmW for <notmuch@notmuchmail.org>;
\r
16 Sun, 18 Dec 2011 05:15:41 -0800 (PST)
\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 56F27431FB6
\r
21 for <notmuch@notmuchmail.org>; Sun, 18 Dec 2011 05:15:41 -0800 (PST)
\r
22 Received: from zancas.localnet
\r
23 (fctnnbsc36w-156034079193.pppoe-dynamic.High-Speed.nb.bellaliant.net
\r
24 [156.34.79.193]) (authenticated bits=0)
\r
25 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pBIDFduk017885
\r
26 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);
\r
27 Sun, 18 Dec 2011 09:15:40 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.77)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1RcGaZ-0008RY-3F; Sun, 18 Dec 2011 09:15:39 -0400
\r
31 From: David Bremner <david@tethera.net>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH Draft 2 8/9] notmuch-restore: auto detect format of backup
\r
34 Date: Sun, 18 Dec 2011 09:15:10 -0400
\r
35 Message-Id: <1324214111-32079-9-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.7.3
\r
37 In-Reply-To: <1324214111-32079-1-git-send-email-david@tethera.net>
\r
38 References: <id:87sjkmuck7.fsf@gmail.com>
\r
39 <1324214111-32079-1-git-send-email-david@tethera.net>
\r
40 Cc: David Bremner <bremner@debian.org>
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Sun, 18 Dec 2011 13:15:43 -0000
\r
55 From: David Bremner <bremner@debian.org>
\r
57 The simple heuristic relies on the fact that '(' is not part of the
\r
58 character set used by hex-escape. Since hex-escape is designed to be
\r
59 OK for pathnames (and shells), this seems like a reasonable
\r
62 In principle the --format argument to notmuch-restore is notmuch
\r
63 needed at this point, but it adds literally 5 lines of argument
\r
64 description, so I left it.
\r
66 dump-restore-private.h | 5 +++--
\r
67 notmuch-restore.c | 45 ++++++++++++++++++++++++++++++++-------------
\r
68 2 files changed, 35 insertions(+), 15 deletions(-)
\r
70 diff --git a/dump-restore-private.h b/dump-restore-private.h
\r
71 index 34a5022..67795e5 100644
\r
72 --- a/dump-restore-private.h
\r
73 +++ b/dump-restore-private.h
\r
75 #include "command-line-arguments.h"
\r
77 typedef enum dump_formats {
\r
79 - DUMP_FORMAT_NOTMUCH
\r
81 + DUMP_FORMAT_NOTMUCH,
\r
86 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
87 index f618b47..340f31f 100644
\r
88 --- a/notmuch-restore.c
\r
89 +++ b/notmuch-restore.c
\r
90 @@ -36,7 +36,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
94 - int input_format = DUMP_FORMAT_SUP;
\r
95 + int input_format = DUMP_FORMAT_AUTO;
\r
97 config = notmuch_config_open (ctx, NULL, NULL);
\r
99 @@ -50,7 +50,11 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
100 synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
102 notmuch_opt_desc_t options[] = {
\r
103 - FORMAT_DESC (input_format),
\r
104 + { NOTMUCH_OPT_KEYWORD, &input_format, "format", 'f',
\r
105 + (notmuch_keyword_t []){ { "auto", DUMP_FORMAT_AUTO },
\r
106 + { "notmuch", DUMP_FORMAT_NOTMUCH },
\r
107 + { "sup", DUMP_FORMAT_SUP },
\r
109 { NOTMUCH_OPT_POSITION, &input_file_name, 0, 0, 0 },
\r
110 { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
\r
112 @@ -80,17 +84,6 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
116 - /* Dump output is one line per message. We match a sequence of
\r
117 - * non-space characters for the message-id, then one or more
\r
118 - * spaces, then a list of space-separated tags as a sequence of
\r
119 - * characters within literal '(' and ')'. */
\r
120 - if (input_format == DUMP_FORMAT_SUP) {
\r
121 - if ( xregcomp (®ex,
\r
122 - "^([^ ]+) \\(([^)]*)\\)$",
\r
124 - INTERNAL_ERROR("compile time constant regex failed.");
\r
128 /* These are out here to re-use the buffers with hex_decode */
\r
130 @@ -98,6 +91,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
131 size_t message_id_size = 0;
\r
133 size_t tag_size = 0;
\r
134 + notmuch_bool_t first_line = TRUE;
\r
136 while ((line_len = getline (&line, &line_size, input)) != -1) {
\r
137 regmatch_t match[3];
\r
138 @@ -109,6 +103,30 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
141 chomp_newline (line);
\r
142 + if (first_line && input_format == DUMP_FORMAT_AUTO) {
\r
145 + for (p = line; *p; p++) {
\r
147 + input_format = DUMP_FORMAT_SUP;
\r
150 + if (input_format == DUMP_FORMAT_AUTO)
\r
151 + input_format = DUMP_FORMAT_NOTMUCH;
\r
155 + /* sup dump output is one line per message. We match a
\r
156 + * sequence of non-space characters for the message-id, then
\r
157 + * one or more spaces, then a list of space-separated tags as
\r
158 + * a sequence of characters within literal '(' and ')'. */
\r
159 + if (first_line && input_format == DUMP_FORMAT_SUP) {
\r
160 + if ( xregcomp (®ex,
\r
161 + "^([^ ]+) \\(([^)]*)\\)$",
\r
163 + INTERNAL_ERROR("compile time constant regex failed.");
\r
167 /* Silently ignore blank lines */
\r
169 @@ -141,6 +159,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
170 file_tags = xstrdup (p);
\r
173 + first_line = FALSE;
\r
175 status = notmuch_database_find_message (notmuch, message_id, &message);
\r
176 if (status || message == NULL) {
\r