To avoid printing anything when applying with be_silent set, let's save the existing warn and error routines before applying and replace them with a routine that does nothing. Then after applying, let's restore the saved routines. Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- apply.c | 21 ++++++++++++++++++++- apply.h | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apply.c b/apply.c index e2acc18..de86f40 100644 --- a/apply.c +++ b/apply.c @@ -109,6 +109,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 *bla, va_list params) +{ + /* do nothing */ +} + int check_apply_state(struct apply_state *state, int force_apply) { int is_not_gitdir = !startup_info->have_repository; @@ -143,6 +148,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->be_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; } @@ -4860,7 +4872,7 @@ int apply_all_patches(struct apply_state *state, state->newfd = -1; } - return !!errs; + res = !!errs; end: if (state->newfd >= 0) { @@ -4868,5 +4880,12 @@ end: state->newfd = -1; } + if (state->be_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); } diff --git a/apply.h b/apply.h index 44bed19..51a930a 100644 --- a/apply.h +++ b/apply.h @@ -89,6 +89,10 @@ struct apply_state { */ struct string_list fn_table; + /* This is to save some reporting routines */ + 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; -- 2.9.0.172.gfb57a78 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html