diff options
author | Christian Couder <christian.couder@gmail.com> | 2016-05-24 10:11:06 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-06-01 10:10:16 -0700 |
commit | b802355863814b331ffc4ae029b228472e874d1f (patch) | |
tree | 37c9783f42d358bd8042776ad2a90aee7365ad3c /builtin | |
parent | 574f5a59d85153309ea9856f425ca610074e1116 (diff) | |
download | git-b802355863814b331ffc4ae029b228472e874d1f.tar.gz git-b802355863814b331ffc4ae029b228472e874d1f.tar.xz |
builtin/apply: move 'patch_input_file' global into 'struct apply_state'
To libify the apply functionality the 'patch_input_file' 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')
-rw-r--r-- | builtin/apply.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/builtin/apply.c b/builtin/apply.c index c0c18ce9f..fa9002898 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -49,6 +49,7 @@ struct apply_state { /* Other non boolean parameters */ const char *fake_ancestor; + const char *patch_input_file; int line_termination; unsigned int p_context; }; @@ -79,7 +80,6 @@ static enum ws_ignore { } ws_ignore_action = ignore_ws_none; -static const char *patch_input_file; static struct strbuf root = STRBUF_INIT; static void parse_whitespace_option(const char *option) @@ -1525,7 +1525,11 @@ static int find_header(struct apply_state *state, return -1; } -static void record_ws_error(unsigned result, const char *line, int len, int linenr) +static void record_ws_error(struct apply_state *state, + unsigned result, + const char *line, + int len, + int linenr) { char *err; @@ -1539,15 +1543,18 @@ static void record_ws_error(unsigned result, const char *line, int len, int line err = whitespace_error_string(result); fprintf(stderr, "%s:%d: %s.\n%.*s\n", - patch_input_file, linenr, err, len, line); + state->patch_input_file, linenr, err, len, line); free(err); } -static void check_whitespace(const char *line, int len, unsigned ws_rule) +static void check_whitespace(struct apply_state *state, + const char *line, + int len, + unsigned ws_rule) { unsigned result = ws_check(line + 1, len - 1, ws_rule); - record_ws_error(result, line + 1, len - 2, state_linenr); + record_ws_error(state, result, line + 1, len - 2, state_linenr); } /* @@ -1602,12 +1609,12 @@ static int parse_fragment(struct apply_state *state, trailing++; if (!state->apply_in_reverse && ws_error_action == correct_ws_error) - check_whitespace(line, len, patch->ws_rule); + check_whitespace(state, line, len, patch->ws_rule); break; case '-': if (state->apply_in_reverse && ws_error_action != nowarn_ws_error) - check_whitespace(line, len, patch->ws_rule); + check_whitespace(state, line, len, patch->ws_rule); deleted++; oldlines--; trailing = 0; @@ -1615,7 +1622,7 @@ static int parse_fragment(struct apply_state *state, case '+': if (!state->apply_in_reverse && ws_error_action != nowarn_ws_error) - check_whitespace(line, len, patch->ws_rule); + check_whitespace(state, line, len, patch->ws_rule); added++; newlines--; trailing = 0; @@ -2904,7 +2911,7 @@ static int apply_one_fragment(struct apply_state *state, preimage.nr + applied_pos >= img->nr && (ws_rule & WS_BLANK_AT_EOF) && ws_error_action != nowarn_ws_error) { - record_ws_error(WS_BLANK_AT_EOF, "+", 1, + record_ws_error(state, WS_BLANK_AT_EOF, "+", 1, found_new_blank_lines_at_end); if (ws_error_action == correct_ws_error) { while (new_blank_lines_at_end--) @@ -4427,7 +4434,7 @@ static int apply_patch(struct apply_state *state, struct patch *list = NULL, **listp = &list; int skipped_patch = 0; - patch_input_file = filename; + state->patch_input_file = filename; read_patch_file(&buf, fd); offset = 0; while (offset < buf.len) { |