Subject: Re: [PATCH 2/2] check-attr: Add --stdin-paths option

From: Johannes Sixt <[email-masked]>
Date: Mon, 06 Oct 2008 09:09:11 +0200

Dmitry Potapov schrieb:
> +static void check_attr_stdin_paths(int cnt, struct git_attr_check *check,
> +	const char** name)
> +{
> +	struct strbuf buf, nbuf;
> +
> +	strbuf_init(&buf, 0);
> +	strbuf_init(&nbuf, 0);
> +	while (strbuf_getline(&buf, stdin, '\n') != EOF) {
> +		if (buf.buf[0] == '"') {
> +			strbuf_reset(&nbuf);
> +			if (unquote_c_style(&nbuf, buf.buf, NULL))
> +				die("line is badly quoted");
> +			strbuf_swap(&buf, &nbuf);
> +		}
> +		check_attr(cnt, check, name, buf.buf);
> +	}
> +	strbuf_release(&buf);
> +	strbuf_release(&nbuf);
> +}
> +

We know that you will want to use this feature in gitk to reduce the
number of fork()s. But you've a problem: gitk will first write a path to
git-check-addr's stdin, and then wait for the result on its stdout. But
this is a classic pitfall: You are not guaranteed that something will be
returned from stdout right away due to buffering. The least that is needed
is fflush(stdout) in this loop (after each iteration!) so that gitk sees
some result and does not hang forever.

-- Hannes