Skip to content

Commit 45b78d8

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 725149b commit 45b78d8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

apply.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ void clear_apply_state(struct apply_state *state)
112112
/* &state->fn_table is cleared at the end of apply_patch() */
113113
}
114114

115+
static void mute_routine(const char *msg, va_list params)
116+
{
117+
/* do nothing */
118+
}
119+
115120
int check_apply_state(struct apply_state *state, int force_apply)
116121
{
117122
int is_not_gitdir = !startup_info->have_repository;
@@ -144,6 +149,13 @@ int check_apply_state(struct apply_state *state, int force_apply)
144149
if (!state->lock_file)
145150
return error("BUG: state->lock_file should not be NULL");
146151

152+
if (state->apply_verbosity <= verbosity_silent) {
153+
state->saved_error_routine = get_error_routine();
154+
state->saved_warn_routine = get_warn_routine();
155+
set_error_routine(mute_routine);
156+
set_warn_routine(mute_routine);
157+
}
158+
147159
return 0;
148160
}
149161

@@ -4864,13 +4876,20 @@ int apply_all_patches(struct apply_state *state,
48644876
state->newfd = -1;
48654877
}
48664878

4867-
return !!errs;
4879+
res = !!errs;
48684880

48694881
end:
48704882
if (state->newfd >= 0) {
48714883
rollback_lock_file(state->lock_file);
48724884
state->newfd = -1;
48734885
}
48744886

4887+
if (state->apply_verbosity <= verbosity_silent) {
4888+
set_error_routine(state->saved_error_routine);
4889+
set_warn_routine(state->saved_warn_routine);
4890+
}
4891+
4892+
if (res > -1)
4893+
return res;
48754894
return (res == -1 ? 1 : 128);
48764895
}

apply.h

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ struct apply_state {
9494
*/
9595
struct string_list fn_table;
9696

97+
/*
98+
* This is to save reporting routines before using
99+
* set_error_routine() or set_warn_routine() to install muting
100+
* routines when in verbosity_silent mode.
101+
*/
102+
void (*saved_error_routine)(const char *err, va_list params);
103+
void (*saved_warn_routine)(const char *warn, va_list params);
104+
97105
/* These control whitespace errors */
98106
enum apply_ws_error_action ws_error_action;
99107
enum apply_ws_ignore ws_ignore_action;

0 commit comments

Comments
 (0)