--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 3B131429E26\r
+ for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:20 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id mJukoyrQRl43 for <notmuch@notmuchmail.org>;\r
+ Sun, 31 Mar 2013 02:46:18 -0700 (PDT)\r
+Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com\r
+ [209.85.217.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 7D501429E38\r
+ for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:16 -0700 (PDT)\r
+Received: by mail-lb0-f169.google.com with SMTP id p11so1257509lbi.0\r
+ for <notmuch@notmuchmail.org>; Sun, 31 Mar 2013 02:46:15 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+ :references:in-reply-to:references:x-gm-message-state;\r
+ bh=KYXmHV2QLnBerQFTXbjTzwVPfi2Z8+ml5yJ02DrCPjk=;\r
+ b=JK3aAIIOKXlZ3jwKF+rfn3eEJM9jrTXYihAs5bYt2bXZb0SehPqE5pKFVF1576B4+J\r
+ yrK3imoyHuWNlY9tpSfQNr04UAXqKsk4PCjdvovVfJGPoezlBLESJffggH9sjSotxo43\r
+ PulKc3MlvB+craPmT4LQMhTIhNB+A37nokB7+bi6I7k66BzUO99HfFmTrT+I4bxRxUk4\r
+ wi0gI1KU8RZ325qSzUwEC4cmv56S8Jg7HBd6CkQoPkXN0WZnt1McXo3IGonm5qHgN3Ui\r
+ AmecZpASH6fqb87x9mKvPZWbQ/CNx9RyYHtCXUu3dVQY42KctIR/gPsTftFhEijsg2lX\r
+ vEjQ==\r
+X-Received: by 10.112.173.169 with SMTP id bl9mr3907050lbc.37.1364723174810;\r
+ Sun, 31 Mar 2013 02:46:14 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+ [80.223.81.27])\r
+ by mx.google.com with ESMTPS id h7sm3706591lbp.16.2013.03.31.02.46.13\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 31 Mar 2013 02:46:14 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 3/6] cli: add --batch option to notmuch count\r
+Date: Sun, 31 Mar 2013 12:46:00 +0300\r
+Message-Id:\r
+ <67dfaef373465f5a0d7426ae4839fbaf0df6ff7d.1364722841.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <cover.1364722841.git.jani@nikula.org>\r
+References: <cover.1364722841.git.jani@nikula.org>\r
+In-Reply-To: <cover.1364722841.git.jani@nikula.org>\r
+References: <cover.1364722841.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQnlGN0caz1ygIgF3RUBygSA209AfI6L9pVhl73I1Ofpgut45kcJVA3lDfMFV1ZoOFFb7uMz\r
+Cc: Tomi Ollila <tomi.ollila@iki.fi>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 31 Mar 2013 09:46:20 -0000\r
+\r
+Add support for reading queries from stdin, one per line, and writing\r
+results to stdout, one per line.\r
+\r
+This will bring considerable performance improvements when utilized in\r
+Emacs notmuch-hello, especially so when running remote notmuch.\r
+---\r
+ notmuch-count.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--\r
+ 1 file changed, 50 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index 630f036..8772cff 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+ return 0;\r
+ }\r
+ \r
++static int\r
++count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,\r
++ size_t exclude_tags_length, int output)\r
++{\r
++ char *line = NULL;\r
++ ssize_t line_len;\r
++ size_t line_size;\r
++ int ret = 0;\r
++\r
++ while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {\r
++ chomp_newline (line);\r
++ ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,\r
++ output);\r
++ }\r
++\r
++ if (line)\r
++ free (line);\r
++\r
++ return ret;\r
++}\r
++\r
+ int\r
+ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
+@@ -72,6 +93,9 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ int exclude = EXCLUDE_TRUE;\r
+ const char **search_exclude_tags = NULL;\r
+ size_t search_exclude_tags_length = 0;\r
++ notmuch_bool_t batch = FALSE;\r
++ FILE *input = stdin;\r
++ char *input_file_name = NULL;\r
+ int ret;\r
+ \r
+ notmuch_opt_desc_t options[] = {\r
+@@ -83,6 +107,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },\r
+ { "false", EXCLUDE_FALSE },\r
+ { 0, 0 } } },\r
++ { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
++ { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
+ { 0, 0, 0, 0, 0 }\r
+ };\r
+ \r
+@@ -92,6 +118,21 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ return 1;\r
+ }\r
+ \r
++ if (input_file_name) {\r
++ batch = TRUE;\r
++ input = fopen (input_file_name, "r");\r
++ if (input == NULL) {\r
++ fprintf (stderr, "Error opening %s for reading: %s\n",\r
++ input_file_name, strerror (errno));\r
++ return 1;\r
++ }\r
++ }\r
++\r
++ if (batch && opt_index != argc) {\r
++ fprintf (stderr, "--batch and query string are not compatible\n");\r
++ return 1;\r
++ }\r
++\r
+ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
+ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
+ return 1;\r
+@@ -107,10 +148,17 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
+ (config, &search_exclude_tags_length);\r
+ }\r
+ \r
+- ret = print_count (notmuch, query_str, search_exclude_tags,\r
+- search_exclude_tags_length, output);\r
++ if (batch)\r
++ ret = count_file (notmuch, input, search_exclude_tags,\r
++ search_exclude_tags_length, output);\r
++ else\r
++ ret = print_count (notmuch, query_str, search_exclude_tags,\r
++ search_exclude_tags_length, output);\r
+ \r
+ notmuch_database_destroy (notmuch);\r
+ \r
++ if (input != stdin)\r
++ fclose (input);\r
++\r
+ return ret;\r
+ }\r
+-- \r
+1.7.10.4\r
+\r