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 3B131429E26
\r
6 for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:20 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id mJukoyrQRl43 for <notmuch@notmuchmail.org>;
\r
17 Sun, 31 Mar 2013 02:46:18 -0700 (PDT)
\r
18 Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com
\r
19 [209.85.217.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 7D501429E38
\r
22 for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:16 -0700 (PDT)
\r
23 Received: by mail-lb0-f169.google.com with SMTP id p11so1257509lbi.0
\r
24 for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:15 -0700 (PDT)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=google.com; s=20120113;
\r
27 h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to
\r
28 :references:in-reply-to:references:x-gm-message-state;
\r
29 bh=KYXmHV2QLnBerQFTXbjTzwVPfi2Z8+ml5yJ02DrCPjk=;
\r
30 b=JK3aAIIOKXlZ3jwKF+rfn3eEJM9jrTXYihAs5bYt2bXZb0SehPqE5pKFVF1576B4+J
\r
31 yrK3imoyHuWNlY9tpSfQNr04UAXqKsk4PCjdvovVfJGPoezlBLESJffggH9sjSotxo43
\r
32 PulKc3MlvB+craPmT4LQMhTIhNB+A37nokB7+bi6I7k66BzUO99HfFmTrT+I4bxRxUk4
\r
33 wi0gI1KU8RZ325qSzUwEC4cmv56S8Jg7HBd6CkQoPkXN0WZnt1McXo3IGonm5qHgN3Ui
\r
34 AmecZpASH6fqb87x9mKvPZWbQ/CNx9RyYHtCXUu3dVQY42KctIR/gPsTftFhEijsg2lX
\r
36 X-Received: by 10.112.173.169 with SMTP id bl9mr3907050lbc.37.1364723174810;
\r
37 Sun, 31 Mar 2013 02:46:14 -0700 (PDT)
\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
40 by mx.google.com with ESMTPS id h7sm3706591lbp.16.2013.03.31.02.46.13
\r
41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
42 Sun, 31 Mar 2013 02:46:14 -0700 (PDT)
\r
43 From: Jani Nikula <jani@nikula.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH v3 3/6] cli: add --batch option to notmuch count
\r
46 Date: Sun, 31 Mar 2013 12:46:00 +0300
\r
48 <67dfaef373465f5a0d7426ae4839fbaf0df6ff7d.1364722841.git.jani@nikula.org>
\r
49 X-Mailer: git-send-email 1.7.10.4
\r
50 In-Reply-To: <cover.1364722841.git.jani@nikula.org>
\r
51 References: <cover.1364722841.git.jani@nikula.org>
\r
52 In-Reply-To: <cover.1364722841.git.jani@nikula.org>
\r
53 References: <cover.1364722841.git.jani@nikula.org>
\r
55 ALoCoQnlGN0caz1ygIgF3RUBygSA209AfI6L9pVhl73I1Ofpgut45kcJVA3lDfMFV1ZoOFFb7uMz
\r
56 Cc: Tomi Ollila <tomi.ollila@iki.fi>
\r
57 X-BeenThere: notmuch@notmuchmail.org
\r
58 X-Mailman-Version: 2.1.13
\r
60 List-Id: "Use and development of the notmuch mail system."
\r
61 <notmuch.notmuchmail.org>
\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
65 List-Post: <mailto:notmuch@notmuchmail.org>
\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
68 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
69 X-List-Received-Date: Sun, 31 Mar 2013 09:46:20 -0000
\r
71 Add support for reading queries from stdin, one per line, and writing
\r
72 results to stdout, one per line.
\r
74 This will bring considerable performance improvements when utilized in
\r
75 Emacs notmuch-hello, especially so when running remote notmuch.
\r
77 notmuch-count.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
\r
78 1 file changed, 50 insertions(+), 2 deletions(-)
\r
80 diff --git a/notmuch-count.c b/notmuch-count.c
\r
81 index 630f036..8772cff 100644
\r
82 --- a/notmuch-count.c
\r
83 +++ b/notmuch-count.c
\r
84 @@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
89 +count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,
\r
90 + size_t exclude_tags_length, int output)
\r
92 + char *line = NULL;
\r
97 + while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {
\r
98 + chomp_newline (line);
\r
99 + ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,
\r
110 notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
\r
112 @@ -72,6 +93,9 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
\r
113 int exclude = EXCLUDE_TRUE;
\r
114 const char **search_exclude_tags = NULL;
\r
115 size_t search_exclude_tags_length = 0;
\r
116 + notmuch_bool_t batch = FALSE;
\r
117 + FILE *input = stdin;
\r
118 + char *input_file_name = NULL;
\r
121 notmuch_opt_desc_t options[] = {
\r
122 @@ -83,6 +107,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
\r
123 (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
\r
124 { "false", EXCLUDE_FALSE },
\r
126 + { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
\r
127 + { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
\r
131 @@ -92,6 +118,21 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
\r
135 + if (input_file_name) {
\r
137 + input = fopen (input_file_name, "r");
\r
138 + if (input == NULL) {
\r
139 + fprintf (stderr, "Error opening %s for reading: %s\n",
\r
140 + input_file_name, strerror (errno));
\r
145 + if (batch && opt_index != argc) {
\r
146 + fprintf (stderr, "--batch and query string are not compatible\n");
\r
150 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
151 NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
153 @@ -107,10 +148,17 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
\r
154 (config, &search_exclude_tags_length);
\r
157 - ret = print_count (notmuch, query_str, search_exclude_tags,
\r
158 - search_exclude_tags_length, output);
\r
160 + ret = count_file (notmuch, input, search_exclude_tags,
\r
161 + search_exclude_tags_length, output);
\r
163 + ret = print_count (notmuch, query_str, search_exclude_tags,
\r
164 + search_exclude_tags_length, output);
\r
166 notmuch_database_destroy (notmuch);
\r
168 + if (input != stdin)
\r