From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Cc: Tomi Ollila <tomi.ollila@iki.fi>
Subject: [PATCH v3 3/6] cli: add --batch option to notmuch count
Date: Sun, 31 Mar 2013 12:46:00 +0300 [thread overview]
Message-ID: <67dfaef373465f5a0d7426ae4839fbaf0df6ff7d.1364722841.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1364722841.git.jani@nikula.org>
In-Reply-To: <cover.1364722841.git.jani@nikula.org>
Add support for reading queries from stdin, one per line, and writing
results to stdout, one per line.
This will bring considerable performance improvements when utilized in
Emacs notmuch-hello, especially so when running remote notmuch.
---
notmuch-count.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
diff --git a/notmuch-count.c b/notmuch-count.c
index 630f036..8772cff 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
return 0;
}
+static int
+count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,
+ size_t exclude_tags_length, int output)
+{
+ char *line = NULL;
+ ssize_t line_len;
+ size_t line_size;
+ int ret = 0;
+
+ while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {
+ chomp_newline (line);
+ ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,
+ output);
+ }
+
+ if (line)
+ free (line);
+
+ return ret;
+}
+
int
notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
{
@@ -72,6 +93,9 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
int exclude = EXCLUDE_TRUE;
const char **search_exclude_tags = NULL;
size_t search_exclude_tags_length = 0;
+ notmuch_bool_t batch = FALSE;
+ FILE *input = stdin;
+ char *input_file_name = NULL;
int ret;
notmuch_opt_desc_t options[] = {
@@ -83,6 +107,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
(notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
{ "false", EXCLUDE_FALSE },
{ 0, 0 } } },
+ { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
+ { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
{ 0, 0, 0, 0, 0 }
};
@@ -92,6 +118,21 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
return 1;
}
+ if (input_file_name) {
+ batch = TRUE;
+ input = fopen (input_file_name, "r");
+ if (input == NULL) {
+ fprintf (stderr, "Error opening %s for reading: %s\n",
+ input_file_name, strerror (errno));
+ return 1;
+ }
+ }
+
+ if (batch && opt_index != argc) {
+ fprintf (stderr, "--batch and query string are not compatible\n");
+ return 1;
+ }
+
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
return 1;
@@ -107,10 +148,17 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
(config, &search_exclude_tags_length);
}
- ret = print_count (notmuch, query_str, search_exclude_tags,
- search_exclude_tags_length, output);
+ if (batch)
+ ret = count_file (notmuch, input, search_exclude_tags,
+ search_exclude_tags_length, output);
+ else
+ ret = print_count (notmuch, query_str, search_exclude_tags,
+ search_exclude_tags_length, output);
notmuch_database_destroy (notmuch);
+ if (input != stdin)
+ fclose (input);
+
return ret;
}
--
1.7.10.4
next prev parent reply other threads:[~2013-03-31 9:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-31 9:45 [PATCH v3 0/6] batch count for notmuch-hello speedup Jani Nikula
2013-03-31 9:45 ` [PATCH v3 1/6] cli: remove useless talloc_strdup Jani Nikula
2013-03-31 9:45 ` [PATCH v3 2/6] cli: extract count printing to a separate function in notmuch count Jani Nikula
2013-03-31 9:46 ` Jani Nikula [this message]
2013-03-31 9:46 ` [PATCH v3 4/6] man: document notmuch count --batch and --input options Jani Nikula
2013-03-31 9:46 ` [PATCH v3 5/6] test: " Jani Nikula
2013-03-31 9:46 ` [PATCH v3 6/6] emacs: hello: use batch count Jani Nikula
2013-03-31 16:38 ` [PATCH v3 0/6] batch count for notmuch-hello speedup Tomi Ollila
2013-04-01 13:43 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=67dfaef373465f5a0d7426ae4839fbaf0df6ff7d.1364722841.git.jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
--cc=tomi.ollila@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).