1 Return-Path: <jani@nikula.org>
\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 3873F431FBF
\r
6 for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:49:08 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 4XnOq63NSIqT for <notmuch@notmuchmail.org>;
\r
16 Tue, 25 Mar 2014 10:49:02 -0700 (PDT)
\r
17 Received: from mail-ee0-f42.google.com (mail-ee0-f42.google.com
\r
18 [74.125.83.42]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
19 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
20 7DD73431FBD for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:49:02 -0700
\r
22 Received: by mail-ee0-f42.google.com with SMTP id d17so743323eek.29
\r
23 for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:49:00 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=1e100.net; s=20130820;
\r
26 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
28 bh=Xgc2UWmTFhQZVkKmF56y2nz94HBdnmVQXwlfnWA7/Ik=;
\r
29 b=CsKdcx1WL1EXL2izviNw42Zxiyk7FUYU4k6VHsVtGKhuDd4aCEaOHAgUb6gN8VVFsh
\r
30 tgt3W/1Nkf0XQQWi1H/ir9trinXIQam9Me+vs/q9ghqKYelvP+iBBiyoGQVkYiW4wazg
\r
31 YSxlbQJaXsxeKiAIVXVaD9+Sd0RnQla8JwN8XsmwgWMnxMyWFHs75XE8MuNMoLbAwkzW
\r
32 MZdqMQrWgJZI4eLoQ0P7y6Tlep06lxfhWIqllwb/huO02/0bI/cFNK+mn6grGgTiJzXG
\r
33 klb0xOR06iGeT79WUDU+sIzFm1njTqMXc+gBLqtM0SwuGghI7JzNFxya8mvw+3/TBtcP
\r
36 ALoCoQkzk9e+GuLEqym9xaIMH6Oz1a0uqTZ9NZ2f6R/Z6MDxYE2oWsPVjNv81z85VG8+XYfBVbk0
\r
37 X-Received: by 10.14.198.197 with SMTP id v45mr71281009een.9.1395769739874;
\r
38 Tue, 25 Mar 2014 10:48:59 -0700 (PDT)
\r
39 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.
\r
41 by mx.google.com with ESMTPSA id m1sm41573676een.7.2014.03.25.10.48.58
\r
42 for <multiple recipients>
\r
43 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
44 Tue, 25 Mar 2014 10:48:58 -0700 (PDT)
\r
45 From: Jani Nikula <jani@nikula.org>
\r
46 To: notmuch@notmuchmail.org
\r
47 Subject: [PATCH v2] cli: abstract dump file open from the dump command
\r
48 Date: Tue, 25 Mar 2014 19:48:57 +0200
\r
49 Message-Id: <1395769737-14598-1-git-send-email-jani@nikula.org>
\r
50 X-Mailer: git-send-email 1.9.0
\r
52 <92929cc512b9e9cd5ccb7d4e537671ce84de514f.1395767165.git.jani@nikula.org>
\r
54 <92929cc512b9e9cd5ccb7d4e537671ce84de514f.1395767165.git.jani@nikula.org>
\r
55 X-BeenThere: notmuch@notmuchmail.org
\r
56 X-Mailman-Version: 2.1.13
\r
58 List-Id: "Use and development of the notmuch mail system."
\r
59 <notmuch.notmuchmail.org>
\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
61 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
63 List-Post: <mailto:notmuch@notmuchmail.org>
\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
67 X-List-Received-Date: Tue, 25 Mar 2014 17:49:08 -0000
\r
69 Also expose the dump function to the rest of notmuch. No functional
\r
70 changes, except for slight improvement in error handling.
\r
72 dump-restore-private.h | 13 -------------
\r
73 notmuch-client.h | 11 +++++++++++
\r
74 notmuch-dump.c | 47 +++++++++++++++++++++++++++++++----------------
\r
75 notmuch-restore.c | 2 +-
\r
76 4 files changed, 43 insertions(+), 30 deletions(-)
\r
77 delete mode 100644 dump-restore-private.h
\r
79 diff --git a/dump-restore-private.h b/dump-restore-private.h
\r
80 deleted file mode 100644
\r
81 index 896a00430986..000000000000
\r
82 --- a/dump-restore-private.h
\r
85 -#ifndef DUMP_RESTORE_PRIVATE_H
\r
86 -#define DUMP_RESTORE_PRIVATE_H
\r
88 -#include "hex-escape.h"
\r
89 -#include "command-line-arguments.h"
\r
91 -typedef enum dump_formats {
\r
93 - DUMP_FORMAT_BATCH_TAG,
\r
98 diff --git a/notmuch-client.h b/notmuch-client.h
\r
99 index 278b498a246a..d11064824ddf 100644
\r
100 --- a/notmuch-client.h
\r
101 +++ b/notmuch-client.h
\r
102 @@ -441,5 +441,16 @@ mime_node_child (mime_node_t *parent, int child);
\r
104 mime_node_seek_dfs (mime_node_t *node, int n);
\r
106 +typedef enum dump_formats {
\r
107 + DUMP_FORMAT_AUTO,
\r
108 + DUMP_FORMAT_BATCH_TAG,
\r
113 +notmuch_database_dump (notmuch_database_t *notmuch,
\r
114 + const char *output_file_name,
\r
115 + const char *query_str, dump_format_t output_format);
\r
117 #include "command-line-arguments.h"
\r
119 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
120 index 179e2e97bf61..21702d793bcf 100644
\r
121 --- a/notmuch-dump.c
\r
122 +++ b/notmuch-dump.c
\r
126 #include "notmuch-client.h"
\r
127 -#include "dump-restore-private.h"
\r
128 +#include "hex-escape.h"
\r
129 #include "string-util.h"
\r
132 @@ -115,11 +115,38 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
133 return EXIT_SUCCESS;
\r
136 +/* Dump database into output_file_name if it's non-NULL, stdout
\r
140 +notmuch_database_dump (notmuch_database_t *notmuch,
\r
141 + const char *output_file_name,
\r
142 + const char *query_str, dump_format_t output_format)
\r
144 + FILE *output = stdout;
\r
147 + if (output_file_name) {
\r
148 + output = fopen (output_file_name, "w");
\r
149 + if (output == NULL) {
\r
150 + fprintf (stderr, "Error opening %s for writing: %s\n",
\r
151 + output_file_name, strerror (errno));
\r
152 + return EXIT_FAILURE;
\r
156 + ret = database_dump_file (notmuch, output, query_str, output_format);
\r
158 + if (output != stdout)
\r
165 notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
167 notmuch_database_t *notmuch;
\r
168 - FILE *output = stdout;
\r
169 const char *query_str = NULL;
\r
172 @@ -145,16 +172,6 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
174 return EXIT_FAILURE;
\r
176 - if (output_file_name) {
\r
177 - output = fopen (output_file_name, "w");
\r
178 - if (output == NULL) {
\r
179 - fprintf (stderr, "Error opening %s for writing: %s\n",
\r
180 - output_file_name, strerror (errno));
\r
181 - return EXIT_FAILURE;
\r
186 if (opt_index < argc) {
\r
187 query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
\r
188 if (query_str == NULL) {
\r
189 @@ -163,10 +180,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
193 - ret = database_dump_file (notmuch, output, query_str, output_format);
\r
195 - if (output != stdout)
\r
197 + ret = notmuch_database_dump (notmuch, output_file_name, query_str,
\r
200 notmuch_database_destroy (notmuch);
\r
202 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
203 index f23ab983a93d..c54d51328b51 100644
\r
204 --- a/notmuch-restore.c
\r
205 +++ b/notmuch-restore.c
\r
209 #include "notmuch-client.h"
\r
210 -#include "dump-restore-private.h"
\r
211 +#include "hex-escape.h"
\r
212 #include "tag-util.h"
\r
213 #include "string-util.h"
\r