Signed-off-by: Christian Couder <chrisc...@tuxfamily.org>
---
 apply.c | 29 +++++++++++++++++++++++++----
 apply.h |  3 +++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/apply.c b/apply.c
index e0fdd1d..1dafc82 100644
--- a/apply.c
+++ b/apply.c
@@ -100,6 +100,11 @@ int init_apply_state(struct apply_state *state,
        return 0;
 }
 
+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;
@@ -132,6 +137,13 @@ int check_apply_state(struct apply_state *state, int 
force_apply)
        if (state->be_silent && state->apply_verbosely)
                return error(_("incompatible internal 'be_silent' and 
'apply_verbosely' flags"));
 
+       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;
 }
 
@@ -4750,6 +4762,7 @@ int apply_all_patches(struct apply_state *state,
 {
        int i;
        int res;
+       int retval = -1;
        int errs = 0;
        int read_stdin = 1;
 
@@ -4822,17 +4835,25 @@ int apply_all_patches(struct apply_state *state,
        if (state->update_index) {
                res = write_locked_index(&the_index, state->lock_file, 
COMMIT_LOCK);
                state->newfd = -1;
-               if (res)
-                       return error(_("Unable to write new index file"));
+               if (res) {
+                       error(_("Unable to write new index file"));
+                       goto rollback_end;
+               }
        }
 
-       return !!errs;
+       retval = !!errs;
 
 rollback_end:
        if (state->newfd >= 0) {
                rollback_lock_file(state->lock_file);
                state->newfd = -1;
        }
-       return -1;
+
+       if (state->be_silent) {
+               set_error_routine(state->saved_error_routine);
+               set_warn_routine(state->saved_warn_routine);
+       }
+
+       return retval;
 }
 
diff --git a/apply.h b/apply.h
index 2dd3706..029b79f 100644
--- a/apply.h
+++ b/apply.h
@@ -46,6 +46,9 @@ struct apply_state {
        int apply_verbosely;
        int be_silent;
 
+       void (*saved_error_routine)(const char *err, va_list params);
+       void (*saved_warn_routine)(const char *warn, va_list params);
+
        /* --cached updates only the cache without ever touching the working 
tree. */
        int cached;
 
-- 
2.8.2.490.g3dabe57

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to