public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Christian Couder <christian.couder@gmail•com>
Cc: git@vger•kernel.org, "Jeff King" <peff@peff•net>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail•com>,
	"Karsten Blees" <karsten.blees@gmail•com>,
	"Nguyen Thai Ngoc Duy" <pclouds@gmail•com>,
	"Stefan Beller" <sbeller@google•com>,
	"Eric Sunshine" <sunshine@sunshineco•com>,
	"Ramsay Jones" <ramsay@ramsayjones•plus.com>,
	"Johannes Sixt" <j6t@kdbg•org>, "René Scharfe" <l.s.r@web•de>,
	"Christian Couder" <chriscool@tuxfamily•org>
Subject: Re: [PATCH v8 34/41] apply: add 'be_silent' variable to 'struct apply_state'
Date: Tue, 26 Jul 2016 12:34:56 -0700	[thread overview]
Message-ID: <xmqqeg6g19cv.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20160627182429.31550-35-chriscool@tuxfamily.org> (Christian Couder's message of "Mon, 27 Jun 2016 20:24:22 +0200")

Christian Couder <christian.couder@gmail•com> writes:

> This variable should prevent anything to be printed on both stderr
> and stdout.

It is far more important to describe "why" this is needed than what
it does, the latter of which can be read from the patch text.

And I do not see any "why" here.  Is this "when the current caller
wanted to silence us, it spawned us in a separate process and
redirected our output to /dev/null, but we no longer can do that
because we will change the calling convention to allow direct calls
into us"?

Do we have a precedent to name a switch that we usually call "quiet"
or "silent" as "be_{silent,quiet}"?  Is there already a "silent"
nearby that records what the end-user gave us (e.g. via "--silent"
option), a new name may be needed, but if that is the motivation,
I'd probably call it something more specific, "apply_silently" or
somesuch.

> Let's not take care of stdout and apply_verbosely for now though,
> as that will be taken care of in following patches.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily•org>
> ---
>  apply.c | 43 +++++++++++++++++++++++++++++--------------
>  apply.h |  1 +
>  2 files changed, 30 insertions(+), 14 deletions(-)
>
> diff --git a/apply.c b/apply.c
> index 7bf12a7..802fa79 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -1617,8 +1617,9 @@ static void record_ws_error(struct apply_state *state,
>  		return;
>  
>  	err = whitespace_error_string(result);
> -	fprintf(stderr, "%s:%d: %s.\n%.*s\n",
> -		state->patch_input_file, linenr, err, len, line);
> +	if (!state->be_silent)
> +		fprintf(stderr, "%s:%d: %s.\n%.*s\n",
> +			state->patch_input_file, linenr, err, len, line);
>  	free(err);
>  }
>  
> @@ -1813,7 +1814,7 @@ static int parse_single_patch(struct apply_state *state,
>  		return error(_("new file %s depends on old contents"), patch->new_name);
>  	if (0 < patch->is_delete && newlines)
>  		return error(_("deleted file %s still has contents"), patch->old_name);
> -	if (!patch->is_delete && !newlines && context)
> +	if (!patch->is_delete && !newlines && context && !state->be_silent)
>  		fprintf_ln(stderr,
>  			   _("** warning: "
>  			     "file %s becomes empty but is not deleted"),
> @@ -3038,8 +3039,8 @@ static int apply_one_fragment(struct apply_state *state,
>  		 * Warn if it was necessary to reduce the number
>  		 * of context lines.
>  		 */
> -		if ((leading != frag->leading) ||
> -		    (trailing != frag->trailing))
> +		if ((leading != frag->leading ||
> +		     trailing != frag->trailing) && !state->be_silent)
>  			fprintf_ln(stderr, _("Context reduced to (%ld/%ld)"
>  					     " to apply fragment at %d"),
>  				   leading, trailing, applied_pos+1);
> @@ -3536,7 +3537,8 @@ static int try_threeway(struct apply_state *state,
>  		 read_blob_object(&buf, pre_sha1, patch->old_mode))
>  		return error("repository lacks the necessary blob to fall back on 3-way merge.");
>  
> -	fprintf(stderr, "Falling back to three-way merge...\n");
> +	if (!state->be_silent)
> +		fprintf(stderr, "Falling back to three-way merge...\n");
>  
>  	img = strbuf_detach(&buf, &len);
>  	prepare_image(&tmp_image, img, len, 1);
> @@ -3566,7 +3568,9 @@ static int try_threeway(struct apply_state *state,
>  	status = three_way_merge(image, patch->new_name,
>  				 pre_sha1, our_sha1, post_sha1);
>  	if (status < 0) {
> -		fprintf(stderr, "Failed to fall back on three-way merge...\n");
> +		if (!state->be_silent)
> +			fprintf(stderr,
> +				"Failed to fall back on three-way merge...\n");
>  		return status;
>  	}
>  
> @@ -3578,9 +3582,15 @@ static int try_threeway(struct apply_state *state,
>  			hashcpy(patch->threeway_stage[0].hash, pre_sha1);
>  		hashcpy(patch->threeway_stage[1].hash, our_sha1);
>  		hashcpy(patch->threeway_stage[2].hash, post_sha1);
> -		fprintf(stderr, "Applied patch to '%s' with conflicts.\n", patch->new_name);
> +		if (!state->be_silent)
> +			fprintf(stderr,
> +				"Applied patch to '%s' with conflicts.\n",
> +				patch->new_name);
>  	} else {
> -		fprintf(stderr, "Applied patch to '%s' cleanly.\n", patch->new_name);
> +		if (!state->be_silent)
> +			fprintf(stderr,
> +				"Applied patch to '%s' cleanly.\n",
> +				patch->new_name);
>  	}
>  	return 0;
>  }
> @@ -4483,7 +4493,8 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
>  			    "Applying patch %%s with %d rejects...",
>  			    cnt),
>  		    cnt);
> -	say_patch_name(stderr, sb.buf, patch);
> +	if (!state->be_silent)
> +		say_patch_name(stderr, sb.buf, patch);
>  	strbuf_release(&sb);
>  
>  	cnt = strlen(patch->new_name);
> @@ -4510,10 +4521,12 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
>  	     frag;
>  	     cnt++, frag = frag->next) {
>  		if (!frag->rejected) {
> -			fprintf_ln(stderr, _("Hunk #%d applied cleanly."), cnt);
> +			if (!state->be_silent)
> +				fprintf_ln(stderr, _("Hunk #%d applied cleanly."), cnt);
>  			continue;
>  		}
> -		fprintf_ln(stderr, _("Rejected hunk #%d."), cnt);
> +		if (!state->be_silent)
> +			fprintf_ln(stderr, _("Rejected hunk #%d."), cnt);
>  		fprintf(rej, "%.*s", frag->size, frag->patch);
>  		if (frag->patch[frag->size-1] != '\n')
>  			fputc('\n', rej);
> @@ -4562,8 +4575,10 @@ static int write_out_results(struct apply_state *state, struct patch *list)
>  		struct string_list_item *item;
>  
>  		string_list_sort(&cpath);
> -		for_each_string_list_item(item, &cpath)
> -			fprintf(stderr, "U %s\n", item->string);
> +		if (!state->be_silent) {
> +			for_each_string_list_item(item, &cpath)
> +				fprintf(stderr, "U %s\n", item->string);
> +		}
>  		string_list_clear(&cpath, 0);
>  
>  		rerere(0);
> diff --git a/apply.h b/apply.h
> index df44b51..44bed19 100644
> --- a/apply.h
> +++ b/apply.h
> @@ -52,6 +52,7 @@ struct apply_state {
>  	int apply_in_reverse;
>  	int apply_with_reject;
>  	int apply_verbosely;
> +	int be_silent;
>  	int no_add;
>  	int threeway;
>  	int unidiff_zero;

  reply	other threads:[~2016-07-26 19:35 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-27 18:23 [PATCH v8 00/41] libify apply and use lib in am, part 2 Christian Couder
2016-06-27 18:23 ` [PATCH v8 01/41] apply: make some names more specific Christian Couder
2016-06-27 18:23 ` [PATCH v8 02/41] apply: move 'struct apply_state' to apply.h Christian Couder
2016-06-27 18:23 ` [PATCH v8 03/41] builtin/apply: make apply_patch() return -1 or -128 instead of die()ing Christian Couder
2016-06-27 18:23 ` [PATCH v8 04/41] builtin/apply: read_patch_file() return -1 " Christian Couder
2016-06-27 18:23 ` [PATCH v8 05/41] builtin/apply: make find_header() return -128 " Christian Couder
2016-06-27 18:23 ` [PATCH v8 06/41] builtin/apply: make parse_chunk() return a negative integer on error Christian Couder
2016-06-27 18:23 ` [PATCH v8 07/41] builtin/apply: make parse_single_patch() return -1 " Christian Couder
2016-06-27 18:23 ` [PATCH v8 08/41] builtin/apply: make parse_whitespace_option() return -1 instead of die()ing Christian Couder
2016-06-27 18:23 ` [PATCH v8 09/41] builtin/apply: make parse_ignorewhitespace_option() " Christian Couder
2016-06-27 18:23 ` [PATCH v8 10/41] builtin/apply: move init_apply_state() to apply.c Christian Couder
2016-06-27 18:23 ` [PATCH v8 11/41] apply: make init_apply_state() return -1 instead of exit()ing Christian Couder
2016-06-27 18:24 ` [PATCH v8 12/41] builtin/apply: make check_apply_state() return -1 instead of die()ing Christian Couder
2016-06-27 18:24 ` [PATCH v8 13/41] builtin/apply: move check_apply_state() to apply.c Christian Couder
2016-06-27 18:24 ` [PATCH v8 14/41] builtin/apply: make apply_all_patches() return 128 or 1 on error Christian Couder
2016-06-27 18:24 ` [PATCH v8 15/41] builtin/apply: make parse_traditional_patch() return -1 " Christian Couder
2016-06-27 18:24 ` [PATCH v8 16/41] builtin/apply: make gitdiff_*() return 1 at end of header Christian Couder
2016-06-27 18:24 ` [PATCH v8 17/41] builtin/apply: make gitdiff_*() return -1 on error Christian Couder
2016-06-27 18:24 ` [PATCH v8 18/41] builtin/apply: change die_on_unsafe_path() to check_unsafe_path() Christian Couder
2016-06-27 18:24 ` [PATCH v8 19/41] builtin/apply: make build_fake_ancestor() return -1 on error Christian Couder
2016-06-27 18:24 ` [PATCH v8 20/41] builtin/apply: make remove_file() " Christian Couder
2016-06-27 18:24 ` [PATCH v8 21/41] builtin/apply: make add_conflicted_stages_file() " Christian Couder
2016-06-27 18:24 ` [PATCH v8 22/41] builtin/apply: make add_index_file() " Christian Couder
2016-06-27 18:24 ` [PATCH v8 23/41] builtin/apply: make create_file() " Christian Couder
2016-06-27 18:24 ` [PATCH v8 24/41] builtin/apply: make write_out_one_result() " Christian Couder
2016-06-27 18:24 ` [PATCH v8 25/41] builtin/apply: make write_out_results() " Christian Couder
2016-06-27 18:24 ` [PATCH v8 26/41] builtin/apply: make try_create_file() " Christian Couder
2016-06-27 18:24 ` [PATCH v8 27/41] builtin/apply: make create_one_file() " Christian Couder
2016-06-27 18:24 ` [PATCH v8 28/41] builtin/apply: rename option parsing functions Christian Couder
2016-06-27 18:24 ` [PATCH v8 29/41] apply: rename and move opt constants to apply.h Christian Couder
2016-06-27 18:24 ` [PATCH v8 31/41] apply: make some parsing functions static again Christian Couder
2016-06-27 18:24 ` [PATCH v8 32/41] environment: add set_index_file() Christian Couder
2016-07-26 19:28   ` Junio C Hamano
2016-07-27 15:14     ` Duy Nguyen
2016-07-29 14:21       ` Christian Couder
2016-07-29 15:34         ` Duy Nguyen
2016-07-29 18:23           ` Christian Couder
2016-07-29 18:35             ` Duy Nguyen
2016-07-29 18:58               ` Junio C Hamano
2016-06-27 18:24 ` [PATCH v8 33/41] write_or_die: use warning() instead of fprintf(stderr, ...) Christian Couder
2016-06-28 21:39   ` Junio C Hamano
2016-06-30  9:50     ` Christian Couder
2016-06-27 18:24 ` [PATCH v8 34/41] apply: add 'be_silent' variable to 'struct apply_state' Christian Couder
2016-07-26 19:34   ` Junio C Hamano [this message]
2016-06-27 18:24 ` [PATCH v8 35/41] apply: make 'be_silent' incompatible with 'apply_verbosely' Christian Couder
2016-07-26 19:37   ` Junio C Hamano
2016-06-27 18:24 ` [PATCH v8 36/41] apply: don't print on stdout when be_silent is set Christian Couder
2016-07-26 19:41   ` Junio C Hamano
2016-06-27 18:24 ` [PATCH v8 37/41] usage: add set_warn_routine() Christian Couder
2016-06-27 18:24 ` [PATCH v8 38/41] usage: add get_error_routine() and get_warn_routine() Christian Couder
2016-06-27 18:24 ` [PATCH v8 39/41] apply: change error_routine when be_silent is set Christian Couder
2016-06-27 18:24 ` [PATCH v8 40/41] builtin/am: use apply api in run_apply() Christian Couder
2016-07-26 19:48   ` Junio C Hamano
2016-06-27 18:24 ` [PATCH v8 41/41] apply: use error_errno() where possible Christian Couder
2016-06-27 18:33 ` [PATCH v8 00/41] libify apply and use lib in am, part 2 Christian Couder
2016-07-26 21:18 ` Junio C Hamano
2016-07-27  6:15   ` Christian Couder
2016-07-27 16:24     ` Junio C Hamano
2016-07-30 17:39       ` Christian Couder

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=xmqqeg6g19cv.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=avarab@gmail$(echo .)com \
    --cc=chriscool@tuxfamily$(echo .)org \
    --cc=christian.couder@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=j6t@kdbg$(echo .)org \
    --cc=karsten.blees@gmail$(echo .)com \
    --cc=l.s.r@web$(echo .)de \
    --cc=pclouds@gmail$(echo .)com \
    --cc=peff@peff$(echo .)net \
    --cc=ramsay@ramsayjones$(echo .)plus.com \
    --cc=sbeller@google$(echo .)com \
    --cc=sunshine@sunshineco$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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