builtin/apply: move 'whitespace_error' global into 'struct apply_state'
To libify the apply functionality the 'whitespace_error' 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
5460cd0b1000078846e2850eeaba3573965c1faf
1 file changed
+15
-13
builtin/apply.c
+15
-13
@@ -59,6 +59,9 @@ struct apply_state {
59
/* Exclude and include path parameters */
60
struct string_list limit_by_name;
61
int has_include;
62
+
63
+ /* These control whitespace errors */
64
+ int whitespace_error;
65
};
66
67
static int newfd = -1;
@@ -74,7 +77,6 @@ static enum ws_error_action {
77
die_on_ws_error,
78
correct_ws_error
79
} ws_error_action = warn_on_ws_error;
77
-static int whitespace_error;
80
static int squelch_whitespace_errors = 5;
81
static int applied_after_fixing_ws;
82
@@ -1596,9 +1598,9 @@ static void record_ws_error(struct apply_state *state,
1598
if (!result)
1599
return;
1600
1599
- whitespace_error++;
1601
+ state->whitespace_error++;
1602
if (squelch_whitespace_errors &&
1601
- squelch_whitespace_errors < whitespace_error)
1603
+ squelch_whitespace_errors < state->whitespace_error)
1604
return;
1605
1606
err = whitespace_error_string(result);
@@ -2855,7 +2857,7 @@ static int apply_one_fragment(struct apply_state *state,
2857
2858
start = newlines.len;
2859
if (first != '+' ||
2858
- !whitespace_error ||
2860
+ !state->whitespace_error ||
2861
ws_error_action != correct_ws_error) {
2862
strbuf_add(&newlines, patch + 1, plen);
2863
}
@@ -4528,7 +4530,7 @@ static int apply_patch(struct apply_state *state,
4530
if (!list && !skipped_patch)
4531
die(_("unrecognized input"));
4532
4531
- if (whitespace_error && (ws_error_action == die_on_ws_error))
4533
+ if (state->whitespace_error && (ws_error_action == die_on_ws_error))
4534
state->apply = 0;
4535
4536
state->update_index = state->check_index && state->apply;
@@ -4791,11 +4793,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4793
set_default_whitespace_mode(&state, whitespace_option);
4794
if (read_stdin)
4795
errs |= apply_patch(&state, 0, "<stdin>", options);
4794
- if (whitespace_error) {
4796
+ if (state.whitespace_error) {
4797
if (squelch_whitespace_errors &&
4796
- squelch_whitespace_errors < whitespace_error) {
4798
+ squelch_whitespace_errors < state.whitespace_error) {
4799
int squelched =
4798
- whitespace_error - squelch_whitespace_errors;
4800
+ state.whitespace_error - squelch_whitespace_errors;
4801
warning(Q_("squelched %d whitespace error",
4802
"squelched %d whitespace errors",
4803
squelched),
@@ -4804,18 +4806,18 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4806
if (ws_error_action == die_on_ws_error)
4807
die(Q_("%d line adds whitespace errors.",
4808
"%d lines add whitespace errors.",
4807
- whitespace_error),
4808
- whitespace_error);
4809
+ state.whitespace_error),
4810
+ state.whitespace_error);
4811
if (applied_after_fixing_ws && state.apply)
4812
warning("%d line%s applied after"
4813
" fixing whitespace errors.",
4814
applied_after_fixing_ws,
4815
applied_after_fixing_ws == 1 ? "" : "s");
4814
- else if (whitespace_error)
4816
+ else if (state.whitespace_error)
4817
warning(Q_("%d line adds whitespace errors.",
4818
"%d lines add whitespace errors.",
4817
- whitespace_error),
4818
- whitespace_error);
4819
+ state.whitespace_error),
4820
+ state.whitespace_error);
4821
}
4822
4823
if (state.update_index) {