unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: Re: [PATCH v2 1/7] cli: allow query to come from stdin
Date: Sat, 24 Nov 2012 13:24:33 +0000	[thread overview]
Message-ID: <87mwy7jfqm.fsf@qmul.ac.uk> (raw)
In-Reply-To: <1353763256-32336-2-git-send-email-markwalters1009@gmail.com>


I should have said the code for reading from stdin was 
stolen from Peter's patch for notmuch-insert
id:1343223767-9812-4-git-send-email-novalazy@gmail.com
(errors are of course mine)

My apologies for not mentioning this in the commit message.

Mark



On Sat, 24 Nov 2012, markwalters1009 <markwalters1009@gmail.com> wrote:
> From: Mark Walters <markwalters1009@gmail.com>
>
> After this series there will be times when a caller will want to pass
> a very large query string to notmuch (eg a list of 10,000 message-ids)
> and this can exceed the size of ARG_MAX. Hence allow notmuch to take
> the query from stdin (if the query is -).
> ---
>  query-string.c |   41 +++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 41 insertions(+), 0 deletions(-)
>
> diff --git a/query-string.c b/query-string.c
> index 6536512..b1fbdeb 100644
> --- a/query-string.c
> +++ b/query-string.c
> @@ -20,6 +20,44 @@
>  
>  #include "notmuch-client.h"
>  
> +/* Read a single query string from STDIN, using
> + * 'ctx' as the talloc owner for all allocations.
> + *
> + * This function returns NULL in case of insufficient memory or read
> + * errors.
> + */
> +static char *
> +query_string_from_stdin (void *ctx)
> +{
> +    char *query_string;
> +    char buf[4096];
> +    ssize_t remain;
> +
> +    query_string = talloc_strdup (ctx, "");
> +    if (query_string == NULL)
> +	return NULL;
> +
> +    for (;;) {
> +	remain = read (STDIN_FILENO, buf, sizeof(buf) - 1);
> +	if (remain == 0)
> +	    break;
> +	if (remain < 0) {
> +	    if (errno == EINTR)
> +		continue;
> +	    fprintf (stderr, "Error: reading from standard input: %s\n",
> +		     strerror (errno));
> +	    return NULL;
> +	}
> +
> +	buf[remain] = '\0';
> +	query_string = talloc_strdup_append (query_string, buf);
> +	if (query_string == NULL)
> +	    return NULL;
> +    }
> +
> +    return query_string;
> +}
> +
>  /* Construct a single query string from the passed arguments, using
>   * 'ctx' as the talloc owner for all allocations.
>   *
> @@ -35,6 +73,9 @@ query_string_from_args (void *ctx, int argc, char *argv[])
>      char *query_string;
>      int i;
>  
> +    if ((argc == 1) && (strcmp ("-", argv[0]) == 0))
> +	return query_string_from_stdin (ctx);
> +
>      query_string = talloc_strdup (ctx, "");
>      if (query_string == NULL)
>  	return NULL;
> -- 
> 1.7.9.1

  reply	other threads:[~2012-11-24 13:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-24 13:20 [PATCH v2 0/7] Fix emacs tagging race markwalters1009
2012-11-24 13:20 ` [PATCH v2 1/7] cli: allow query to come from stdin markwalters1009
2012-11-24 13:24   ` Mark Walters [this message]
2012-11-24 17:41   ` Austin Clements
2012-11-26 10:15     ` Mark Walters
2012-11-24 22:34   ` Tomi Ollila
2012-11-24 13:20 ` [PATCH v2 2/7] test: for the new query from stdin functionality markwalters1009
2012-11-24 13:20 ` [PATCH v2 3/7] emacs: notmuch.el split call-process into call-process-region markwalters1009
2012-11-24 13:20 ` [PATCH v2 4/7] emacs: make emacs tagging use the stdin query functionality markwalters1009
2012-11-24 22:09   ` Austin Clements
2012-11-24 13:20 ` [PATCH v2 5/7] test: test for race when tagging from emacs search markwalters1009
2012-11-24 13:20 ` [PATCH v2 6/7] cli: allow search mode to include msg-ids with JSON output markwalters1009
2012-11-24 22:30   ` Tomi Ollila
2012-11-25  0:23   ` Austin Clements
2012-11-24 13:20 ` [PATCH v2 7/7] emacs: make emacs use message-ids for tagging markwalters1009
2012-11-25  0:38   ` Austin Clements

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=87mwy7jfqm.fsf@qmul.ac.uk \
    --to=markwalters1009@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /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).