apply: change error_routine when silent
[gitweb.git] / apply.c
diff --git a/apply.c b/apply.c
index a9384390f17f1aaa2a6b635122db9897ef348283..3a888c21bdbff56b94143da7cb404f0995dcfa4e 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -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)
        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,
                state->newfd = -1;
        }
 
-       return !!errs;
+       res = !!errs;
 
 end:
        if (state->newfd >= 0) {
@@ -4872,5 +4884,12 @@ int apply_all_patches(struct apply_state *state,
                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);
 }