git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Larry D'Anna <larry@elder-gods.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] bugfix: git diff --quiet -w never returns with exit status 1
Date: Mon, 15 Feb 2010 21:42:44 -0800	[thread overview]
Message-ID: <7v3a11ivmz.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1266293446-8092-2-git-send-email-larry@elder-gods.org> (Larry D'Anna's message of "Mon\, 15 Feb 2010 23\:10\:46 -0500")

Larry D'Anna <larry@elder-gods.org> writes:

> Rationale: diff_flush_patch expects to write its output to options->file.
> Adding a "silence" flag to diff_flush_patch and everything it calls would be
> more invasive.

I would agree that the logic to redirect the output to nowhere may be the
easiest way out, but because the reason anybody sane would want to give -q
is to say "I don't care what the actual changes are, but I want to know if
there is any real quick" (otherwise the call would be "diff -w >/dev/null"),
shouldn't we at least be exiting the loop early when we see any difference?

> Signed-off-by: Larry D'Anna <larry@elder-gods.org>
> ---
>  diff.c |   20 ++++++++++++++++++++
>  1 files changed, 20 insertions(+), 0 deletions(-)
>
> diff --git a/diff.c b/diff.c
> index 68def6c..ff00816 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -3522,6 +3522,26 @@ void diff_flush(struct diff_options *options)
>  		separator++;
>  	}
>  
> +	if (output_format & DIFF_FORMAT_NO_OUTPUT &&
> +	    DIFF_OPT_TST(options, EXIT_WITH_STATUS) &&
> +	    DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) {
> +		/* run diff_flush_patch for the exit status */
> +		/* setting options->file to /dev/null should be safe, becaue we
> +		   aren't supposed to produce any output anyways */

Style?

> +		static FILE *devnull = NULL;

Would this cause one file descriptor to leak?  Do we care?

> +		if(!devnull) {

Style?	if (!devnull)

> +			devnull = fopen("/dev/null", "w");
> +			if (!devnull)
> +				die_errno("Could not open /dev/null");
> +		}
> +		options->file = devnull;

Would this cause the original "options->file" leak?  Do we care?

> +		for (i = 0; i < q->nr; i++) {
> +			struct diff_filepair *p = q->queue[i];
> +			if (check_pair_status(p))
> +				diff_flush_patch(p, options);
> +		}
> +	}
> +
>  	if (output_format & DIFF_FORMAT_PATCH) {
>  		if (separator) {
>  			putc(options->line_termination, options->file);
> -- 
> 1.7.0.rc2.40.g7d8aa

  reply	other threads:[~2010-02-16  5:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-16  4:10 [PATCH 1/2] bugfix: segfault on git diff --output=/bad/path Larry D'Anna
2010-02-16  4:10 ` [PATCH 2/2] bugfix: git diff --quiet -w never returns with exit status 1 Larry D'Anna
2010-02-16  5:42   ` Junio C Hamano [this message]
2010-02-16  6:45     ` Larry D'Anna
2010-02-16  6:55       ` Larry D'Anna

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v3a11ivmz.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=larry@elder-gods.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.
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 NNTP newsgroup(s).