builtin/apply: move 'p_context' global into 'struct apply_state'

To libify the apply functionality the 'p_context' 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 a48f9bb1b31329b29eed9808844c147f613b59ad
1 file changed +4 -3
builtin/apply.c
+4 -3
@@ -49,6 +49,7 @@ struct apply_state {
49 /* Other non boolean parameters */
50 const char *fake_ancestor;
51 int line_termination;
52 + unsigned int p_context;
53 };
54
55 static int newfd = -1;
@@ -56,7 +57,6 @@ static int newfd = -1;
57 static int state_p_value = 1;
58 static int p_value_known;
59 static int apply = 1;
59 -static unsigned int p_context = UINT_MAX;
60 static const char * const apply_usage[] = {
61 N_("git apply [<options>] [<patch>...]"),
62 NULL
@@ -2872,7 +2872,7 @@ static int apply_one_fragment(struct apply_state *state,
2872 break;
2873
2874 /* Am I at my context limits? */
2875 - if ((leading <= p_context) && (trailing <= p_context))
2875 + if ((leading <= state->p_context) && (trailing <= state->p_context))
2876 break;
2877 if (match_beginning || match_end) {
2878 match_beginning = match_end = 0;
@@ -4566,6 +4566,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
4566 state->prefix = prefix;
4567 state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
4568 state->line_termination = '\n';
4569 + state->p_context = UINT_MAX;
4570
4571 git_apply_config();
4572 if (apply_default_whitespace)
@@ -4628,7 +4629,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4629 /* Think twice before adding "--nul" synonym to this */
4630 OPT_SET_INT('z', NULL, &state.line_termination,
4631 N_("paths are separated with NUL character"), '\0'),
4631 - OPT_INTEGER('C', NULL, &p_context,
4632 + OPT_INTEGER('C', NULL, &state.p_context,
4633 N_("ensure at least <n> lines of context match")),
4634 { OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"),
4635 N_("detect new or modified lines that have whitespace errors"),