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

To libify the apply functionality the 'line_termination' 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 f4c9eaa49c5ed87b304a40b95b1d06d46a8cbfa9
1 file changed +9 -5
builtin/apply.c
+9 -5
@@ -45,6 +45,9 @@ struct apply_state {
45 int threeway;
46 int unidiff_zero;
47 int unsafe_paths;
48 +
49 + /* Other non boolean parameters */
50 + int line_termination;
51 };
52
53 /*
@@ -56,7 +59,6 @@ static int state_p_value = 1;
59 static int p_value_known;
60 static int apply = 1;
61 static const char *fake_ancestor;
59 -static int line_termination = '\n';
62 static unsigned int p_context = UINT_MAX;
63 static const char * const apply_usage[] = {
64 N_("git apply [<options>] [<patch>...]"),
@@ -3977,7 +3979,8 @@ static void stat_patch_list(struct patch *patch)
3979 print_stat_summary(stdout, files, adds, dels);
3980 }
3981
3980 -static void numstat_patch_list(struct patch *patch)
3982 +static void numstat_patch_list(struct apply_state *state,
3983 + struct patch *patch)
3984 {
3985 for ( ; patch; patch = patch->next) {
3986 const char *name;
@@ -3986,7 +3989,7 @@ static void numstat_patch_list(struct patch *patch)
3989 printf("-\t-\t");
3990 else
3991 printf("%d\t%d\t", patch->lines_added, patch->lines_deleted);
3989 - write_name_quoted(name, stdout, line_termination);
3992 + write_name_quoted(name, stdout, state->line_termination);
3993 }
3994 }
3995
@@ -4490,7 +4493,7 @@ static int apply_patch(struct apply_state *state,
4493 stat_patch_list(list);
4494
4495 if (state->numstat)
4493 - numstat_patch_list(list);
4496 + numstat_patch_list(state, list);
4497
4498 if (state->summary)
4499 summary_patch_list(list);
@@ -4565,6 +4568,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
4568 memset(state, 0, sizeof(*state));
4569 state->prefix = prefix;
4570 state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
4571 + state->line_termination = '\n';
4572
4573 git_apply_config();
4574 if (apply_default_whitespace)
@@ -4625,7 +4629,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4629 OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
4630 N_("build a temporary index based on embedded index information")),
4631 /* Think twice before adding "--nul" synonym to this */
4628 - OPT_SET_INT('z', NULL, &line_termination,
4632 + OPT_SET_INT('z', NULL, &state.line_termination,
4633 N_("paths are separated with NUL character"), '\0'),
4634 OPT_INTEGER('C', NULL, &p_context,
4635 N_("ensure at least <n> lines of context match")),