[PATCH] configure: add --without-api-docs option
[notmuch-archives.git] / 4c / 17ccce01737245a95408c6ef9a2afc7bd701a9
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 41A4C431FC9\r
6         for <notmuch@notmuchmail.org>; Tue,  1 Apr 2014 18:16:41 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 M+8I5kYSZ2aM for <notmuch@notmuchmail.org>;\r
16         Tue,  1 Apr 2014 18:16:39 -0700 (PDT)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 78175431FC0\r
21         for <notmuch@notmuchmail.org>; Tue,  1 Apr 2014 18:16:37 -0700 (PDT)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tethera.net>)\r
24         id 1WV9nB-00072k-2e; Tue, 01 Apr 2014 22:16:37 -0300\r
25 Received: (nullmailer pid 18505 invoked by uid 1000); Wed, 02 Apr 2014\r
26         01:16:27 -0000\r
27 From: David Bremner <david@tethera.net>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v5 4/6] restore: transparently support gzipped input\r
30 Date: Tue,  1 Apr 2014 22:16:19 -0300\r
31 Message-Id: <1396401381-18128-5-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.9.0\r
33 In-Reply-To: <1396401381-18128-1-git-send-email-david@tethera.net>\r
34 References: <1396401381-18128-1-git-send-email-david@tethera.net>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Wed, 02 Apr 2014 01:16:41 -0000\r
48 \r
49 We rely completely on zlib to do the right thing in detecting gzipped\r
50 input. Since our dump format is chosen to be 7 bit ascii, this should\r
51 be fine.\r
52 ---\r
53  doc/man1/notmuch-restore.rst |  8 ++++++++\r
54  notmuch-restore.c            | 37 +++++++++++++++++++++----------------\r
55  test/T240-dump-restore.sh    | 14 ++++++++++++++\r
56  3 files changed, 43 insertions(+), 16 deletions(-)\r
57 \r
58 diff --git a/doc/man1/notmuch-restore.rst b/doc/man1/notmuch-restore.rst\r
59 index d6cf19a..936b138 100644\r
60 --- a/doc/man1/notmuch-restore.rst\r
61 +++ b/doc/man1/notmuch-restore.rst\r
62 @@ -50,6 +50,14 @@ Supported options for **restore** include\r
63              format, this heuristic, based the fact that batch-tag format\r
64              contains no parentheses, should be accurate.\r
65  \r
66 +GZIPPED INPUT\r
67 +=============\r
68 +\r
69 +\ **notmuch restore** will detect if the input is compressed in\r
70 +**gzip(1)** format and automatically decompress it while reading. This\r
71 +detection does not depend on file naming and in particular works for\r
72 +standard input.\r
73 +\r
74  SEE ALSO\r
75  ========\r
76  \r
77 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
78 index c54d513..86bce20 100644\r
79 --- a/notmuch-restore.c\r
80 +++ b/notmuch-restore.c\r
81 @@ -22,6 +22,7 @@\r
82  #include "hex-escape.h"\r
83  #include "tag-util.h"\r
84  #include "string-util.h"\r
85 +#include "zlib-extra.h"\r
86  \r
87  static regex_t regex;\r
88  \r
89 @@ -128,7 +129,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
90      tag_op_list_t *tag_ops;\r
91  \r
92      char *input_file_name = NULL;\r
93 -    FILE *input = stdin;\r
94 +    gzFile input;\r
95      char *line = NULL;\r
96      void *line_ctx = NULL;\r
97      size_t line_size;\r
98 @@ -163,13 +164,15 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
99      if (! accumulate)\r
100         flags |= TAG_FLAG_REMOVE_ALL;\r
101  \r
102 -    if (input_file_name) {\r
103 -       input = fopen (input_file_name, "r");\r
104 -       if (input == NULL) {\r
105 -           fprintf (stderr, "Error opening %s for reading: %s\n",\r
106 -                    input_file_name, strerror (errno));\r
107 -           return EXIT_FAILURE;\r
108 -       }\r
109 +    if (input_file_name)\r
110 +       input = gzopen (input_file_name, "r");\r
111 +    else\r
112 +       input = gzdopen (fileno (stdin), "r");\r
113 +\r
114 +    if (input == NULL) {\r
115 +       fprintf (stderr, "Error opening %s for (gzip) reading: %s\n",\r
116 +                input_file_name ? input_file_name : "stdin", strerror (errno));\r
117 +       return EXIT_FAILURE;\r
118      }\r
119  \r
120      if (opt_index < argc) {\r
121 @@ -184,12 +187,17 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
122      }\r
123  \r
124      do {\r
125 -       line_len = getline (&line, &line_size, input);\r
126 +       util_status_t status;\r
127 +\r
128 +       status = gz_getline (line_ctx, &line, &line_size, &line_len, input);\r
129  \r
130         /* empty input file not considered an error */\r
131 -       if (line_len < 0)\r
132 +       if (status == UTIL_EOF)\r
133             return EXIT_SUCCESS;\r
134  \r
135 +       if (status)\r
136 +           return EXIT_FAILURE;\r
137 +\r
138      } while ((line_len == 0) ||\r
139              (line[0] == '#') ||\r
140              /* the cast is safe because we checked about for line_len < 0 */\r
141 @@ -254,7 +262,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
142         if (ret)\r
143             break;\r
144  \r
145 -    }  while ((line_len = getline (&line, &line_size, input)) != -1);\r
146 +    }  while (gz_getline (line_ctx, &line, &line_size, &line_len, input) == UTIL_SUCCESS);\r
147  \r
148      if (line_ctx != NULL)\r
149         talloc_free (line_ctx);\r
150 @@ -262,13 +270,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
151      if (input_format == DUMP_FORMAT_SUP)\r
152         regfree (&regex);\r
153  \r
154 -    if (line)\r
155 -       free (line);\r
156 -\r
157      notmuch_database_destroy (notmuch);\r
158  \r
159 -    if (input != stdin)\r
160 -       fclose (input);\r
161 +    if (input_file_name != NULL)\r
162 +       gzclose_r (input);\r
163  \r
164      return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
165  }\r
166 diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh\r
167 index d79aca8..50d4d48 100755\r
168 --- a/test/T240-dump-restore.sh\r
169 +++ b/test/T240-dump-restore.sh\r
170 @@ -80,6 +80,20 @@ notmuch dump --gzip --output=dump-gzip-outfile.gz\r
171  gunzip dump-gzip-outfile.gz\r
172  test_expect_equal_file dump.expected dump-gzip-outfile\r
173  \r
174 +test_begin_subtest "restoring gzipped stdin"\r
175 +notmuch dump --gzip --output=backup.gz\r
176 +notmuch tag +new_tag '*'\r
177 +notmuch restore < backup.gz\r
178 +notmuch dump --output=dump.actual\r
179 +test_expect_equal_file dump.expected dump.actual\r
180 +\r
181 +test_begin_subtest "restoring gzipped file"\r
182 +notmuch dump --gzip --output=backup.gz\r
183 +notmuch tag +new_tag '*'\r
184 +notmuch restore --input=backup.gz\r
185 +notmuch dump --output=dump.actual\r
186 +test_expect_equal_file dump.expected dump.actual\r
187 +\r
188  # Note, we assume all messages from cworth have a message-id\r
189  # containing cworth.org\r
190  \r
191 -- \r
192 1.9.0\r
193 \r