builtin/apply: move 'squelch_whitespace_errors' into 'struct apply_state'
To libify the apply functionality the 'squelch_whitespace_errors' variable should not be static and global to the file. Let's move it into 'struct apply_state'. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 24, 2016 at 10:11 UTC
70e1d53df17bc8fa81f3583a50f76753a8bac154
1 file changed
+11
-11
builtin/apply.c
+11
-11
@@ -63,6 +63,7 @@ struct apply_state {
63
/* These control whitespace errors */
64
const char *whitespace_option;
65
int whitespace_error;
66
+ int squelch_whitespace_errors;
67
};
68
69
static int newfd = -1;
@@ -78,7 +79,6 @@ static enum ws_error_action {
79
die_on_ws_error,
80
correct_ws_error
81
} ws_error_action = warn_on_ws_error;
81
-static int squelch_whitespace_errors = 5;
82
static int applied_after_fixing_ws;
83
84
static enum ws_ignore {
@@ -87,7 +87,7 @@ static enum ws_ignore {
87
} ws_ignore_action = ignore_ws_none;
88
89
90
-static void parse_whitespace_option(const char *option)
90
+static void parse_whitespace_option(struct apply_state *state, const char *option)
91
{
92
if (!option) {
93
ws_error_action = warn_on_ws_error;
@@ -107,7 +107,7 @@ static void parse_whitespace_option(const char *option)
107
}
108
if (!strcmp(option, "error-all")) {
109
ws_error_action = die_on_ws_error;
110
- squelch_whitespace_errors = 0;
110
+ state->squelch_whitespace_errors = 0;
111
return;
112
}
113
if (!strcmp(option, "strip") || !strcmp(option, "fix")) {
@@ -1599,8 +1599,8 @@ static void record_ws_error(struct apply_state *state,
1599
return;
1600
1601
state->whitespace_error++;
1602
- if (squelch_whitespace_errors &&
1603
- squelch_whitespace_errors < state->whitespace_error)
1602
+ if (state->squelch_whitespace_errors &&
1603
+ state->squelch_whitespace_errors < state->whitespace_error)
1604
return;
1605
1606
err = whitespace_error_string(result);
@@ -4620,9 +4620,8 @@ static int option_parse_whitespace(const struct option *opt,
4620
const char *arg, int unset)
4621
{
4622
struct apply_state *state = opt->value;
4623
-
4623
state->whitespace_option = arg;
4625
- parse_whitespace_option(arg);
4624
+ parse_whitespace_option(state, arg);
4625
return 0;
4626
}
4627
@@ -4645,11 +4644,12 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
4644
state->line_termination = '\n';
4645
state->p_value = 1;
4646
state->p_context = UINT_MAX;
4647
+ state->squelch_whitespace_errors = 5;
4648
strbuf_init(&state->root, 0);
4649
4650
git_apply_config();
4651
if (apply_default_whitespace)
4652
- parse_whitespace_option(apply_default_whitespace);
4652
+ parse_whitespace_option(state, apply_default_whitespace);
4653
if (apply_default_ignorewhitespace)
4654
parse_ignorewhitespace_option(apply_default_ignorewhitespace);
4655
}
@@ -4792,10 +4792,10 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4792
if (read_stdin)
4793
errs |= apply_patch(&state, 0, "<stdin>", options);
4794
if (state.whitespace_error) {
4795
- if (squelch_whitespace_errors &&
4796
- squelch_whitespace_errors < state.whitespace_error) {
4795
+ if (state.squelch_whitespace_errors &&
4796
+ state.squelch_whitespace_errors < state.whitespace_error) {
4797
int squelched =
4798
- state.whitespace_error - squelch_whitespace_errors;
4798
+ state.whitespace_error - state.squelch_whitespace_errors;
4799
warning(Q_("squelched %d whitespace error",
4800
"squelched %d whitespace errors",
4801
squelched),