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

To libify the apply functionality the 'unsafe_paths' 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 6c0c2bf56c7a3484d157661fb4660f5aefe67a83
1 file changed +4 -4
builtin/apply.c
+4 -4
@@ -44,6 +44,7 @@ struct apply_state {
44 int no_add;
45 int threeway;
46 int unidiff_zero;
47 + int unsafe_paths;
48 };
49
50 /*
@@ -54,7 +55,6 @@ static int newfd = -1;
55 static int state_p_value = 1;
56 static int p_value_known;
57 static int apply = 1;
57 -static int unsafe_paths;
58 static const char *fake_ancestor;
59 static int line_termination = '\n';
60 static unsigned int p_context = UINT_MAX;
@@ -3827,7 +3827,7 @@ static int check_patch(struct apply_state *state, struct patch *patch)
3827 }
3828 }
3829
3830 - if (!unsafe_paths)
3830 + if (!state->unsafe_paths)
3831 die_on_unsafe_path(patch);
3832
3833 /*
@@ -4616,7 +4616,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4616 N_("make sure the patch is applicable to the current index")),
4617 OPT_BOOL(0, "cached", &state.cached,
4618 N_("apply a patch without touching the working tree")),
4619 - OPT_BOOL(0, "unsafe-paths", &unsafe_paths,
4619 + OPT_BOOL(0, "unsafe-paths", &state.unsafe_paths,
4620 N_("accept a patch that touches outside the working area")),
4621 OPT_BOOL(0, "apply", &force_apply,
4622 N_("also apply the patch (use with --stat/--summary/--check)")),
@@ -4685,7 +4685,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4685 state.check_index = 1;
4686 }
4687 if (state.check_index)
4688 - unsafe_paths = 0;
4688 + state.unsafe_paths = 0;
4689
4690 for (i = 0; i < argc; i++) {
4691 const char *arg = argv[i];