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 CD5CE431FAF
\r
6 for <notmuch@notmuchmail.org>; Wed, 23 Jan 2013 05:36:58 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 OX5so3CoWSCh for <notmuch@notmuchmail.org>;
\r
16 Wed, 23 Jan 2013 05:36:57 -0800 (PST)
\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 9B834431FAE
\r
19 for <notmuch@notmuchmail.org>; Wed, 23 Jan 2013 05:36:57 -0800 (PST)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id B7B1A100086;
\r
22 Wed, 23 Jan 2013 15:36:45 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org
\r
25 Subject: Re: [PATCH 3/5] cli: add --batch option to notmuch count
\r
27 <9465478105bbda3d21921906b7abf24dbbaa7ec9.1358273133.git.jani@nikula.org>
\r
28 References: <cover.1358273133.git.jani@nikula.org>
\r
29 <9465478105bbda3d21921906b7abf24dbbaa7ec9.1358273133.git.jani@nikula.org>
\r
30 User-Agent: Notmuch/0.15+11~ge1e719d (http://notmuchmail.org) Emacs/24.2.1
\r
31 (x86_64-unknown-linux-gnu)
\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
33 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
34 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
35 Date: Wed, 23 Jan 2013 15:36:45 +0200
\r
36 Message-ID: <m2a9s0hvgy.fsf@guru.guru-group.fi>
\r
38 Content-Type: text/plain
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Wed, 23 Jan 2013 13:36:58 -0000
\r
53 On Tue, Jan 15 2013, Jani Nikula <jani@nikula.org> wrote:
\r
55 > Add support for reading queries from stdin, one per line, and writing
\r
56 > results to stdin, one per line.
\r
58 Jani's parts LGTM, except one IMPORTANT part -- results are written
\r
59 to STDOUT! (hopefully...yes) instead of STDIN! ;)
\r
61 I don't see a reason why this particular way to get counts could
\r
62 not be supported in notmuch into foreseeable future; the implementation
\r
63 is simple and clean.
\r
65 Next to look Mark's changes...
\r
70 > This will bring considerable performance improvements when utilized in
\r
71 > Emacs notmuch-hello, especially so when running remote notmuch.
\r
73 > notmuch-count.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
\r
74 > 1 file changed, 50 insertions(+), 2 deletions(-)
\r
76 > diff --git a/notmuch-count.c b/notmuch-count.c
\r
77 > index 0e14b48..4bc4215 100644
\r
78 > --- a/notmuch-count.c
\r
79 > +++ b/notmuch-count.c
\r
80 > @@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
85 > +count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,
\r
86 > + size_t exclude_tags_length, int output)
\r
88 > + char *line = NULL;
\r
89 > + ssize_t line_len;
\r
90 > + size_t line_size;
\r
93 > + while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {
\r
94 > + chomp_newline (line);
\r
95 > + ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,
\r
106 > notmuch_count_command (void *ctx, int argc, char *argv[])
\r
108 > @@ -73,6 +94,9 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
109 > int exclude = EXCLUDE_TRUE;
\r
110 > const char **search_exclude_tags = NULL;
\r
111 > size_t search_exclude_tags_length = 0;
\r
112 > + notmuch_bool_t batch = FALSE;
\r
113 > + FILE *input = stdin;
\r
114 > + char *input_file_name = NULL;
\r
117 > notmuch_opt_desc_t options[] = {
\r
118 > @@ -84,6 +108,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
119 > (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
\r
120 > { "false", EXCLUDE_FALSE },
\r
122 > + { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
\r
123 > + { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
\r
124 > { 0, 0, 0, 0, 0 }
\r
127 > @@ -93,6 +119,21 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
131 > + if (input_file_name) {
\r
133 > + input = fopen (input_file_name, "r");
\r
134 > + if (input == NULL) {
\r
135 > + fprintf (stderr, "Error opening %s for reading: %s\n",
\r
136 > + input_file_name, strerror (errno));
\r
141 > + if (batch && opt_index != argc) {
\r
142 > + fprintf (stderr, "--batch and query string are not compatible\n");
\r
146 > config = notmuch_config_open (ctx, NULL, NULL);
\r
147 > if (config == NULL)
\r
149 > @@ -112,10 +153,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
150 > (config, &search_exclude_tags_length);
\r
153 > - ret = print_count (notmuch, query_str, search_exclude_tags,
\r
154 > - search_exclude_tags_length, output);
\r
156 > + ret = count_file (notmuch, input, search_exclude_tags,
\r
157 > + search_exclude_tags_length, output);
\r
159 > + ret = print_count (notmuch, query_str, search_exclude_tags,
\r
160 > + search_exclude_tags_length, output);
\r
162 > notmuch_database_destroy (notmuch);
\r
164 > + if (input != stdin)
\r
165 > + fclose (input);
\r
172 > _______________________________________________
\r
173 > notmuch mailing list
\r
174 > notmuch@notmuchmail.org
\r
175 > http://notmuchmail.org/mailman/listinfo/notmuch
\r