summaryrefslogtreecommitdiff
path: root/builtin/apply.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2016-05-24 08:11:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-06-01 17:10:16 (GMT)
commit5460cd0b1000078846e2850eeaba3573965c1faf (patch)
treeb227fe8e931a9d457fffb6c602f3bb9e91b10d27 /builtin/apply.c
parent36371e4c7ef87a2895b954284c29e8beff576084 (diff)
downloadgit-5460cd0b1000078846e2850eeaba3573965c1faf.zip
git-5460cd0b1000078846e2850eeaba3573965c1faf.tar.gz
git-5460cd0b1000078846e2850eeaba3573965c1faf.tar.bz2
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>
Diffstat (limited to 'builtin/apply.c')
-rw-r--r--builtin/apply.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index 5dc1d89..44717b2 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -59,6 +59,9 @@ struct apply_state {
/* Exclude and include path parameters */
struct string_list limit_by_name;
int has_include;
+
+ /* These control whitespace errors */
+ int whitespace_error;
};
static int newfd = -1;
@@ -74,7 +77,6 @@ static enum ws_error_action {
die_on_ws_error,
correct_ws_error
} ws_error_action = warn_on_ws_error;
-static int whitespace_error;
static int squelch_whitespace_errors = 5;
static int applied_after_fixing_ws;
@@ -1596,9 +1598,9 @@ static void record_ws_error(struct apply_state *state,
if (!result)
return;
- whitespace_error++;
+ state->whitespace_error++;
if (squelch_whitespace_errors &&
- squelch_whitespace_errors < whitespace_error)
+ squelch_whitespace_errors < state->whitespace_error)
return;
err = whitespace_error_string(result);
@@ -2855,7 +2857,7 @@ static int apply_one_fragment(struct apply_state *state,
start = newlines.len;
if (first != '+' ||
- !whitespace_error ||
+ !state->whitespace_error ||
ws_error_action != correct_ws_error) {
strbuf_add(&newlines, patch + 1, plen);
}
@@ -4528,7 +4530,7 @@ static int apply_patch(struct apply_state *state,
if (!list && !skipped_patch)
die(_("unrecognized input"));
- if (whitespace_error && (ws_error_action == die_on_ws_error))
+ if (state->whitespace_error && (ws_error_action == die_on_ws_error))
state->apply = 0;
state->update_index = state->check_index && state->apply;
@@ -4791,11 +4793,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
set_default_whitespace_mode(&state, whitespace_option);
if (read_stdin)
errs |= apply_patch(&state, 0, "<stdin>", options);
- if (whitespace_error) {
+ if (state.whitespace_error) {
if (squelch_whitespace_errors &&
- squelch_whitespace_errors < whitespace_error) {
+ squelch_whitespace_errors < state.whitespace_error) {
int squelched =
- whitespace_error - squelch_whitespace_errors;
+ state.whitespace_error - squelch_whitespace_errors;
warning(Q_("squelched %d whitespace error",
"squelched %d whitespace errors",
squelched),
@@ -4804,18 +4806,18 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
if (ws_error_action == die_on_ws_error)
die(Q_("%d line adds whitespace errors.",
"%d lines add whitespace errors.",
- whitespace_error),
- whitespace_error);
+ state.whitespace_error),
+ state.whitespace_error);
if (applied_after_fixing_ws && state.apply)
warning("%d line%s applied after"
" fixing whitespace errors.",
applied_after_fixing_ws,
applied_after_fixing_ws == 1 ? "" : "s");
- else if (whitespace_error)
+ else if (state.whitespace_error)
warning(Q_("%d line adds whitespace errors.",
"%d lines add whitespace errors.",
- whitespace_error),
- whitespace_error);
+ state.whitespace_error),
+ state.whitespace_error);
}
if (state.update_index) {