Browse Source

apply: change error_routine when silent

To avoid printing anything when applying with
`state->apply_verbosity == verbosity_silent`, let's save the
existing warn and error routines before applying, and let's
replace them with a routine that does nothing.

Then after applying, let's restore the saved routines.

Note that, as we need to restore the saved routines in all
cases, we cannot return early any more in apply_all_patches().

Helped-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Christian Couder 8 years ago committed by Junio C Hamano
parent
commit
45b78d8ba3
  1. 21
      apply.c
  2. 8
      apply.h

21
apply.c

@ -112,6 +112,11 @@ void clear_apply_state(struct apply_state *state) @@ -112,6 +112,11 @@ void clear_apply_state(struct apply_state *state)
/* &state->fn_table is cleared at the end of apply_patch() */
}

static void mute_routine(const char *msg, va_list params)
{
/* do nothing */
}

int check_apply_state(struct apply_state *state, int force_apply)
{
int is_not_gitdir = !startup_info->have_repository;
@ -144,6 +149,13 @@ int check_apply_state(struct apply_state *state, int force_apply) @@ -144,6 +149,13 @@ int check_apply_state(struct apply_state *state, int force_apply)
if (!state->lock_file)
return error("BUG: state->lock_file should not be NULL");

if (state->apply_verbosity <= verbosity_silent) {
state->saved_error_routine = get_error_routine();
state->saved_warn_routine = get_warn_routine();
set_error_routine(mute_routine);
set_warn_routine(mute_routine);
}

return 0;
}

@ -4864,7 +4876,7 @@ int apply_all_patches(struct apply_state *state, @@ -4864,7 +4876,7 @@ int apply_all_patches(struct apply_state *state,
state->newfd = -1;
}

return !!errs;
res = !!errs;

end:
if (state->newfd >= 0) {
@ -4872,5 +4884,12 @@ end: @@ -4872,5 +4884,12 @@ end:
state->newfd = -1;
}

if (state->apply_verbosity <= verbosity_silent) {
set_error_routine(state->saved_error_routine);
set_warn_routine(state->saved_warn_routine);
}

if (res > -1)
return res;
return (res == -1 ? 1 : 128);
}

8
apply.h

@ -94,6 +94,14 @@ struct apply_state { @@ -94,6 +94,14 @@ struct apply_state {
*/
struct string_list fn_table;

/*
* This is to save reporting routines before using
* set_error_routine() or set_warn_routine() to install muting
* routines when in verbosity_silent mode.
*/
void (*saved_error_routine)(const char *err, va_list params);
void (*saved_warn_routine)(const char *warn, va_list params);

/* These control whitespace errors */
enum apply_ws_error_action ws_error_action;
enum apply_ws_ignore ws_ignore_action;

Loading…
Cancel
Save