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

To libify the apply functionality the 'threeway' 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:10 UTC b12e888f7a9489b964ad266b27d7fcfa62fa78e4
1 file changed +7 -7
builtin/apply.c
+7 -7
@@ -41,6 +41,7 @@ struct apply_state {
41 int apply_in_reverse;
42 int apply_with_reject;
43 int apply_verbosely;
44 + int threeway;
45 int unidiff_zero;
46 };
47
@@ -53,7 +54,6 @@ static int state_p_value = 1;
54 static int p_value_known;
55 static int apply = 1;
56 static int no_add;
56 -static int threeway;
57 static int unsafe_paths;
58 static const char *fake_ancestor;
59 static int line_termination = '\n';
@@ -3491,7 +3491,7 @@ static int apply_data(struct apply_state *state, struct patch *patch,
3491 if (patch->direct_to_threeway ||
3492 apply_fragments(state, &image, patch) < 0) {
3493 /* Note: with --reject, apply_fragments() returns 0 */
3494 - if (!threeway || try_threeway(state, &image, patch, st, ce) < 0)
3494 + if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0)
3495 return -1;
3496 }
3497 patch->result = image.buf;
@@ -3786,7 +3786,7 @@ static int check_patch(struct apply_state *state, struct patch *patch)
3786 ((0 < patch->is_new) || patch->is_rename || patch->is_copy)) {
3787 int err = check_to_create(state, new_name, ok_if_exists);
3788
3789 - if (err && threeway) {
3789 + if (err && state->threeway) {
3790 patch->direct_to_threeway = 1;
3791 } else switch (err) {
3792 case 0:
@@ -4620,7 +4620,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
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)")),
4623 - OPT_BOOL('3', "3way", &threeway,
4623 + OPT_BOOL('3', "3way", &state.threeway,
4624 N_( "attempt three-way merge if a patch does not apply")),
4625 OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
4626 N_("build a temporary index based on embedded index information")),
@@ -4664,11 +4664,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4664 argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
4665 apply_usage, 0);
4666
4667 - if (state.apply_with_reject && threeway)
4667 + if (state.apply_with_reject && state.threeway)
4668 die("--reject and --3way cannot be used together.");
4669 - if (state.cached && threeway)
4669 + if (state.cached && state.threeway)
4670 die("--cached and --3way cannot be used together.");
4671 - if (threeway) {
4671 + if (state.threeway) {
4672 if (is_not_gitdir)
4673 die(_("--3way outside a repository"));
4674 state.check_index = 1;