Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id CD5CE431FAF for ; Wed, 23 Jan 2013 05:36:58 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OX5so3CoWSCh for ; Wed, 23 Jan 2013 05:36:57 -0800 (PST) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 9B834431FAE for ; Wed, 23 Jan 2013 05:36:57 -0800 (PST) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id B7B1A100086; Wed, 23 Jan 2013 15:36:45 +0200 (EET) From: Tomi Ollila To: Jani Nikula , notmuch@notmuchmail.org Subject: Re: [PATCH 3/5] cli: add --batch option to notmuch count In-Reply-To: <9465478105bbda3d21921906b7abf24dbbaa7ec9.1358273133.git.jani@nikula.org> References: <9465478105bbda3d21921906b7abf24dbbaa7ec9.1358273133.git.jani@nikula.org> User-Agent: Notmuch/0.15+11~ge1e719d (http://notmuchmail.org) Emacs/24.2.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jan 2013 13:36:58 -0000 On Tue, Jan 15 2013, Jani Nikula wrote: > Add support for reading queries from stdin, one per line, and writing > results to stdin, one per line. Jani's parts LGTM, except one IMPORTANT part -- results are written to STDOUT! (hopefully...yes) instead of STDIN! ;) I don't see a reason why this particular way to get counts could not be supported in notmuch into foreseeable future; the implementation is simple and clean. Next to look Mark's changes... Tomi > > 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 0e14b48..4bc4215 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 (void *ctx, int argc, char *argv[]) > { > @@ -73,6 +94,9 @@ notmuch_count_command (void *ctx, 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[] = { > @@ -84,6 +108,8 @@ notmuch_count_command (void *ctx, 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 } > }; > > @@ -93,6 +119,21 @@ notmuch_count_command (void *ctx, 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; > + } > + > config = notmuch_config_open (ctx, NULL, NULL); > if (config == NULL) > return 1; > @@ -112,10 +153,17 @@ notmuch_count_command (void *ctx, 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 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch