builtin/apply: move 'line_termination' global into 'struct apply_state'
authorChristian Couder <christian.couder@gmail.com>
Tue, 24 May 2016 08:11:02 +0000 (10:11 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Jun 2016 17:10:16 +0000 (10:10 -0700)
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>
builtin/apply.c
index 4ef83c1be573d2c26f58d60646de8fa37e5df1ac..95cd60a3ee73fd810feeec1ae7d4e7da1ee13109 100644 (file)
@@ -45,6 +45,9 @@ struct apply_state {
        int threeway;
        int unidiff_zero;
        int unsafe_paths;
        int threeway;
        int unidiff_zero;
        int unsafe_paths;
+
+       /* Other non boolean parameters */
+       int line_termination;
 };
 
 /*
 };
 
 /*
@@ -56,7 +59,6 @@ static int state_p_value = 1;
 static int p_value_known;
 static int apply = 1;
 static const char *fake_ancestor;
 static int p_value_known;
 static int apply = 1;
 static const char *fake_ancestor;
-static int line_termination = '\n';
 static unsigned int p_context = UINT_MAX;
 static const char * const apply_usage[] = {
        N_("git apply [<options>] [<patch>...]"),
 static unsigned int p_context = UINT_MAX;
 static const char * const apply_usage[] = {
        N_("git apply [<options>] [<patch>...]"),
@@ -3977,7 +3979,8 @@ static void stat_patch_list(struct patch *patch)
        print_stat_summary(stdout, files, adds, dels);
 }
 
        print_stat_summary(stdout, files, adds, dels);
 }
 
-static void numstat_patch_list(struct patch *patch)
+static void numstat_patch_list(struct apply_state *state,
+                              struct patch *patch)
 {
        for ( ; patch; patch = patch->next) {
                const char *name;
 {
        for ( ; patch; patch = patch->next) {
                const char *name;
@@ -3986,7 +3989,7 @@ static void numstat_patch_list(struct patch *patch)
                        printf("-\t-\t");
                else
                        printf("%d\t%d\t", patch->lines_added, patch->lines_deleted);
                        printf("-\t-\t");
                else
                        printf("%d\t%d\t", patch->lines_added, patch->lines_deleted);
-               write_name_quoted(name, stdout, line_termination);
+               write_name_quoted(name, stdout, state->line_termination);
        }
 }
 
        }
 }
 
@@ -4490,7 +4493,7 @@ static int apply_patch(struct apply_state *state,
                stat_patch_list(list);
 
        if (state->numstat)
                stat_patch_list(list);
 
        if (state->numstat)
-               numstat_patch_list(list);
+               numstat_patch_list(state, list);
 
        if (state->summary)
                summary_patch_list(list);
 
        if (state->summary)
                summary_patch_list(list);
@@ -4565,6 +4568,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
        memset(state, 0, sizeof(*state));
        state->prefix = prefix;
        state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
        memset(state, 0, sizeof(*state));
        state->prefix = prefix;
        state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
+       state->line_termination = '\n';
 
        git_apply_config();
        if (apply_default_whitespace)
 
        git_apply_config();
        if (apply_default_whitespace)
@@ -4625,7 +4629,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
                OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
                        N_("build a temporary index based on embedded index information")),
                /* Think twice before adding "--nul" synonym to this */
                OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
                        N_("build a temporary index based on embedded index information")),
                /* Think twice before adding "--nul" synonym to this */
-               OPT_SET_INT('z', NULL, &line_termination,
+               OPT_SET_INT('z', NULL, &state.line_termination,
                        N_("paths are separated with NUL character"), '\0'),
                OPT_INTEGER('C', NULL, &p_context,
                                N_("ensure at least <n> lines of context match")),
                        N_("paths are separated with NUL character"), '\0'),
                OPT_INTEGER('C', NULL, &p_context,
                                N_("ensure at least <n> lines of context match")),