Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 64 / f65aca0444ef085c30d5b9365e2dea8bcab9e9
1 Return-Path: <tomi.ollila@iki.fi>\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 57A5D431FBD\r
6         for <notmuch@notmuchmail.org>; Wed,  2 Apr 2014 09:50:23 -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 e4bw9X63sQp6 for <notmuch@notmuchmail.org>;\r
16         Wed,  2 Apr 2014 09:50:19 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id D66FE431FAE\r
19         for <notmuch@notmuchmail.org>; Wed,  2 Apr 2014 09:50:18 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 128DE100051;\r
22         Wed,  2 Apr 2014 19:50:14 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
25 Subject: Re: [Patch v5 1/6] dump: support gzipped output\r
26 In-Reply-To: <1396401381-18128-2-git-send-email-david@tethera.net>\r
27 References: <1396401381-18128-1-git-send-email-david@tethera.net>\r
28         <1396401381-18128-2-git-send-email-david@tethera.net>\r
29 User-Agent: Notmuch/0.17+174~gef82849 (http://notmuchmail.org) Emacs/24.3.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Wed, 02 Apr 2014 19:50:14 +0300\r
35 Message-ID: <m2txab3cc9.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\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: Wed, 02 Apr 2014 16:50:23 -0000\r
51 \r
52 On Wed, Apr 02 2014, David Bremner <david@tethera.net> wrote:\r
53 \r
54 > The main goal is to support gzipped output for future internal\r
55 > calls (e.g. from notmuch-new) to notmuch_database_dump.\r
56 >\r
57 > The additional dependency is not very heavy since xapian already pulls\r
58 > in zlib.\r
59 > ---\r
60 >  INSTALL                   | 17 +++++++++++----\r
61 >  Makefile.local            |  2 +-\r
62 >  configure                 | 28 +++++++++++++++++++++---\r
63 >  doc/man1/notmuch-dump.rst |  3 +++\r
64 >  notmuch-client.h          |  4 +++-\r
65 >  notmuch-dump.c            | 54 ++++++++++++++++++++++++++++++-----------------\r
66 >  test/T240-dump-restore.sh | 12 +++++++++++\r
67 >  7 files changed, 92 insertions(+), 28 deletions(-)\r
68 >\r
69 > diff --git a/INSTALL b/INSTALL\r
70 > index 690b0ef..df318fa 100644\r
71 > --- a/INSTALL\r
72 > +++ b/INSTALL\r
73 > @@ -20,8 +20,8 @@ configure stage.\r
74 >  \r
75 >  Dependencies\r
76 >  ------------\r
77 > -Notmuch depends on three libraries: Xapian, GMime 2.4 or 2.6, and\r
78 > -Talloc which are each described below:\r
79 > +Notmuch depends on four libraries: Xapian, GMime 2.4 or 2.6,\r
80 > +Talloc, and zlib which are each described below:\r
81 >  \r
82 >       Xapian\r
83 >       ------\r
84 > @@ -60,6 +60,15 @@ Talloc which are each described below:\r
85 >  \r
86 >       Talloc is available from http://talloc.samba.org/\r
87 >  \r
88 > +     zlib\r
89 > +     ----\r
90 > +\r
91 > +     zlib is an extremely popular compression library. It is used\r
92 > +     by Xapian, so if you installed that you will already have\r
93 > +     zlib. You may need to install the zlib headers separately.\r
94 > +\r
95 > +     zlib is available from http://zlib.net\r
96 > +\r
97 >  Building Documentation\r
98 >  ----------------------\r
99 >  \r
100 > @@ -79,11 +88,11 @@ dependencies with a simple simple command line. For example:\r
101 >  \r
102 >    For Debian and similar:\r
103 >  \r
104 > -        sudo apt-get install libxapian-dev libgmime-2.6-dev libtalloc-dev python-sphinx\r
105 > +        sudo apt-get install libxapian-dev libgmime-2.6-dev libtalloc-dev zlib1g-dev python-sphinx\r
106 >  \r
107 >    For Fedora and similar:\r
108 >  \r
109 > -     sudo yum install xapian-core-devel gmime-devel libtalloc-devel python-sphinx\r
110 > +     sudo yum install xapian-core-devel gmime-devel libtalloc-devel zlib-devel python-sphinx\r
111 >  \r
112 >  On other systems, a similar command can be used, but the details of\r
113 >  the package names may be different.\r
114 > diff --git a/Makefile.local b/Makefile.local\r
115 > index cb7b106..e5a20a7 100644\r
116 > --- a/Makefile.local\r
117 > +++ b/Makefile.local\r
118 > @@ -41,7 +41,7 @@ PV_FILE=bindings/python/notmuch/version.py\r
119 >  # Smash together user's values with our extra values\r
120 >  FINAL_CFLAGS = -DNOTMUCH_VERSION=$(VERSION) $(CPPFLAGS) $(CFLAGS) $(WARN_CFLAGS) $(extra_cflags) $(CONFIGURE_CFLAGS)\r
121 >  FINAL_CXXFLAGS = $(CPPFLAGS) $(CXXFLAGS) $(WARN_CXXFLAGS) $(extra_cflags) $(extra_cxxflags) $(CONFIGURE_CXXFLAGS)\r
122 > -FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)\r
123 > +FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS) $(ZLIB_LDFLAGS)\r
124 >  FINAL_NOTMUCH_LINKER = CC\r
125 >  ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1)\r
126 >  FINAL_NOTMUCH_LDFLAGS += $(CONFIGURE_LDFLAGS)\r
127 > diff --git a/configure b/configure\r
128 > index 1d430b9..d685ab3 100755\r
129 > --- a/configure\r
130 > +++ b/configure\r
131 > @@ -340,6 +340,18 @@ else\r
132 >      errors=$((errors + 1))\r
133 >  fi\r
134 >  \r
135 > +printf "Checking for zlib development files... "\r
136 > +have_zlib=0\r
137 > +if pkg-config --exists zlib; then\r
138 > +    printf "Yes.\n"\r
139 > +    have_zlib=1\r
140 > +    zlib_cflags=$(pkg-config --cflags zlib)\r
141 > +    zlib_ldflags=$(pkg-config --libs zlib)\r
142 > +else\r
143 > +    printf "No.\n"\r
144 > +    errors=$((errors + 1))\r
145 > +fi\r
146 \r
147 Like Austin mentioned on IRC, zlib 1.2.5.2 (Dec 2011) is the first version\r
148 supporting 'wT', the test above should use:\r
149 \r
150 pkg-config --atleast-version=1.2.5.2 zlib \r
151 \r
152 And the related documentation should mention this version dependency...\r
153 \r
154 (maybe we can go with this and somebody(tm) who wants support to older\r
155 zlibs may provide tolerable patches for that to be done).\r
156 \r
157 For example Scientific Linux 6.2 (RHEL 6.2-compatible) has zlib 1.2.3 (released\r
158 2005). Maybe there are backports and maybe 6.3 has newer... for me it is\r
159 just easier to compile newer zlib :D)\r
160 \r
161 \r
162 Tomi\r
163 \r
164 > +\r
165 >  printf "Checking for talloc development files... "\r
166 >  if pkg-config --exists talloc; then\r
167 >      printf "Yes.\n"\r
168 > @@ -496,6 +508,11 @@ EOF\r
169 >       echo "  Xapian library (including development files such as headers)"\r
170 >       echo "  http://xapian.org/"\r
171 >      fi\r
172 > +    if [ $have_zlib -eq 0 ]; then\r
173 > +     echo "  zlib library (including development files such as headers)"\r
174 > +     echo "  http://zlib.net/"\r
175 > +     echo\r
176 > +    fi\r
177 >      if [ $have_gmime -eq 0 ]; then\r
178 >       echo "  Either GMime 2.4 library" $GMIME_24_VERSION_CTR "or GMime 2.6 library" $GMIME_26_VERSION_CTR\r
179 >       echo "  (including development files such as headers)"\r
180 > @@ -519,11 +536,11 @@ case a simple command will install everything you need. For example:\r
181 >  \r
182 >  On Debian and similar systems:\r
183 >  \r
184 > -     sudo apt-get install libxapian-dev libgmime-2.6-dev libtalloc-dev\r
185 > +     sudo apt-get install libxapian-dev libgmime-2.6-dev libtalloc-dev zlib1g-dev\r
186 >  \r
187 >  Or on Fedora and similar systems:\r
188 >  \r
189 > -     sudo yum install xapian-core-devel gmime-devel libtalloc-devel\r
190 > +     sudo yum install xapian-core-devel gmime-devel libtalloc-devel zlib-devel\r
191 >  \r
192 >  On other systems, similar commands can be used, but the details of the\r
193 >  package names may be different.\r
194 > @@ -844,6 +861,10 @@ XAPIAN_LDFLAGS = ${xapian_ldflags}\r
195 >  GMIME_CFLAGS = ${gmime_cflags}\r
196 >  GMIME_LDFLAGS = ${gmime_ldflags}\r
197 >  \r
198 > +# Flags needed to compile and link against zlib\r
199 > +ZLIB_CFLAGS = ${zlib_cflags}\r
200 > +ZLIB_LDFLAGS = ${zlib_ldflags}\r
201 > +\r
202 >  # Flags needed to compile and link against talloc\r
203 >  TALLOC_CFLAGS = ${talloc_cflags}\r
204 >  TALLOC_LDFLAGS = ${talloc_ldflags}\r
205 > @@ -882,6 +903,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
206 >                  -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
207 >  \r
208 >  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
209 > +                  \$(ZLIB_CFLAGS)                                     \\\r
210 >                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
211 >                    \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
212 >                    -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)               \\\r
213 > @@ -892,5 +914,5 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
214 >                    -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\\r
215 >                    -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
216 >  \r
217 > -CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
218 > +CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
219 >  EOF\r
220 > diff --git a/doc/man1/notmuch-dump.rst b/doc/man1/notmuch-dump.rst\r
221 > index 17d1da5..d94cb4f 100644\r
222 > --- a/doc/man1/notmuch-dump.rst\r
223 > +++ b/doc/man1/notmuch-dump.rst\r
224 > @@ -19,6 +19,9 @@ recreated from the messages themselves. The output of notmuch dump is\r
225 >  therefore the only critical thing to backup (and much more friendly to\r
226 >  incremental backup than the native database files.)\r
227 >  \r
228 > +``--gzip``\r
229 > +    Compress the output in a format compatible with **gzip(1)**.\r
230 > +\r
231 >  ``--format=(sup|batch-tag)``\r
232 >      Notmuch restore supports two plain text dump formats, both with one\r
233 >      message-id per line, followed by a list of tags.\r
234 > diff --git a/notmuch-client.h b/notmuch-client.h\r
235 > index d110648..e1efbe0 100644\r
236 > --- a/notmuch-client.h\r
237 > +++ b/notmuch-client.h\r
238 > @@ -450,7 +450,9 @@ typedef enum dump_formats {\r
239 >  int\r
240 >  notmuch_database_dump (notmuch_database_t *notmuch,\r
241 >                      const char *output_file_name,\r
242 > -                    const char *query_str, dump_format_t output_format);\r
243 > +                    const char *query_str,\r
244 > +                    dump_format_t output_format,\r
245 > +                    notmuch_bool_t gzip_output);\r
246 >  \r
247 >  #include "command-line-arguments.h"\r
248 >  #endif\r
249 > diff --git a/notmuch-dump.c b/notmuch-dump.c\r
250 > index 21702d7..28342b7 100644\r
251 > --- a/notmuch-dump.c\r
252 > +++ b/notmuch-dump.c\r
253 > @@ -21,9 +21,11 @@\r
254 >  #include "notmuch-client.h"\r
255 >  #include "hex-escape.h"\r
256 >  #include "string-util.h"\r
257 > +#include <zlib.h>\r
258 > +\r
259 >  \r
260 >  static int\r
261 > -database_dump_file (notmuch_database_t *notmuch, FILE *output,\r
262 > +database_dump_file (notmuch_database_t *notmuch, gzFile output,\r
263 >                   const char *query_str, int output_format)\r
264 >  {\r
265 >      notmuch_query_t *query;\r
266 > @@ -69,7 +71,7 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,\r
267 >       }\r
268 >  \r
269 >       if (output_format == DUMP_FORMAT_SUP) {\r
270 > -         fprintf (output, "%s (", message_id);\r
271 > +         gzprintf (output, "%s (", message_id);\r
272 >       }\r
273 >  \r
274 >       for (tags = notmuch_message_get_tags (message);\r
275 > @@ -78,12 +80,12 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,\r
276 >           const char *tag_str = notmuch_tags_get (tags);\r
277 >  \r
278 >           if (! first)\r
279 > -             fputs (" ", output);\r
280 > +             gzputs (output, " ");\r
281 >  \r
282 >           first = 0;\r
283 >  \r
284 >           if (output_format == DUMP_FORMAT_SUP) {\r
285 > -             fputs (tag_str, output);\r
286 > +             gzputs (output, tag_str);\r
287 >           } else {\r
288 >               if (hex_encode (notmuch, tag_str,\r
289 >                               &buffer, &buffer_size) != HEX_SUCCESS) {\r
290 > @@ -91,12 +93,12 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,\r
291 >                            tag_str);\r
292 >                   return EXIT_FAILURE;\r
293 >               }\r
294 > -             fprintf (output, "+%s", buffer);\r
295 > +             gzprintf (output, "+%s", buffer);\r
296 >           }\r
297 >       }\r
298 >  \r
299 >       if (output_format == DUMP_FORMAT_SUP) {\r
300 > -         fputs (")\n", output);\r
301 > +         gzputs (output, ")\n");\r
302 >       } else {\r
303 >           if (make_boolean_term (notmuch, "id", message_id,\r
304 >                                  &buffer, &buffer_size)) {\r
305 > @@ -104,7 +106,7 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,\r
306 >                            message_id, strerror (errno));\r
307 >                   return EXIT_FAILURE;\r
308 >           }\r
309 > -         fprintf (output, " -- %s\n", buffer);\r
310 > +         gzprintf (output, " -- %s\n", buffer);\r
311 >       }\r
312 >  \r
313 >       notmuch_message_destroy (message);\r
314 > @@ -121,24 +123,36 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,\r
315 >  int\r
316 >  notmuch_database_dump (notmuch_database_t *notmuch,\r
317 >                      const char *output_file_name,\r
318 > -                    const char *query_str, dump_format_t output_format)\r
319 > +                    const char *query_str,\r
320 > +                    dump_format_t output_format,\r
321 > +                    notmuch_bool_t gzip_output)\r
322 >  {\r
323 > -    FILE *output = stdout;\r
324 > +    gzFile output;\r
325 > +    const char *mode = gzip_output ? "w9" : "wT";\r
326 > +\r
327 >      int ret;\r
328 >  \r
329 > -    if (output_file_name) {\r
330 > -     output = fopen (output_file_name, "w");\r
331 > -     if (output == NULL) {\r
332 > -         fprintf (stderr, "Error opening %s for writing: %s\n",\r
333 > -                  output_file_name, strerror (errno));\r
334 > -         return EXIT_FAILURE;\r
335 > -     }\r
336 > +    if (output_file_name)\r
337 > +     output = gzopen (output_file_name, mode);\r
338 > +    else\r
339 > +     output = gzdopen (fileno (stdout), mode);\r
340 > +\r
341 > +    if (output == NULL) {\r
342 > +     fprintf (stderr, "Error opening %s for (gzip) writing: %s\n",\r
343 > +              output_file_name ? output_file_name : "stdout", strerror (errno));\r
344 > +     return EXIT_FAILURE;\r
345 >      }\r
346 >  \r
347 >      ret = database_dump_file (notmuch, output, query_str, output_format);\r
348 >  \r
349 > -    if (output != stdout)\r
350 > -     fclose (output);\r
351 > +    if (gzflush (output, Z_FINISH)) {\r
352 > +     fprintf (stderr, "Error flushing output: %s\n",\r
353 > +              gzerror (output, NULL));\r
354 > +     return EXIT_FAILURE;\r
355 > +    }\r
356 > +\r
357 > +    if (output_file_name)\r
358 > +     gzclose_w (output);\r
359 >  \r
360 >      return ret;\r
361 >  }\r
362 > @@ -158,6 +172,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
363 >      int opt_index;\r
364 >  \r
365 >      int output_format = DUMP_FORMAT_BATCH_TAG;\r
366 > +    notmuch_bool_t gzip_output = 0;\r
367 >  \r
368 >      notmuch_opt_desc_t options[] = {\r
369 >       { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',\r
370 > @@ -165,6 +180,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
371 >                                 { "batch-tag", DUMP_FORMAT_BATCH_TAG },\r
372 >                                 { 0, 0 } } },\r
373 >       { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0  },\r
374 > +     { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },\r
375 >       { 0, 0, 0, 0, 0 }\r
376 >      };\r
377 >  \r
378 > @@ -181,7 +197,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
379 >      }\r
380 >  \r
381 >      ret = notmuch_database_dump (notmuch, output_file_name, query_str,\r
382 > -                              output_format);\r
383 > +                              output_format, gzip_output);\r
384 >  \r
385 >      notmuch_database_destroy (notmuch);\r
386 >  \r
387 > diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh\r
388 > index 0004438..d79aca8 100755\r
389 > --- a/test/T240-dump-restore.sh\r
390 > +++ b/test/T240-dump-restore.sh\r
391 > @@ -68,6 +68,18 @@ test_begin_subtest "dump --output=outfile --"\r
392 >  notmuch dump --output=dump-1-arg-dash.actual --\r
393 >  test_expect_equal_file dump.expected dump-1-arg-dash.actual\r
394 >  \r
395 > +# gzipped output\r
396 > +\r
397 > +test_begin_subtest "dump --gzip"\r
398 > +notmuch dump --gzip > dump-gzip.gz\r
399 > +gunzip dump-gzip.gz\r
400 > +test_expect_equal_file dump.expected dump-gzip\r
401 > +\r
402 > +test_begin_subtest "dump --gzip --output=outfile"\r
403 > +notmuch dump --gzip --output=dump-gzip-outfile.gz\r
404 > +gunzip dump-gzip-outfile.gz\r
405 > +test_expect_equal_file dump.expected dump-gzip-outfile\r
406 > +\r
407 >  # Note, we assume all messages from cworth have a message-id\r
408 >  # containing cworth.org\r
409 >  \r
410 > -- \r
411 > 1.9.0\r