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

To libify the apply functionality the 'fake_ancestor' variable should not be static and global to the file. Let's move it into 'struct apply_state'. By the way remove a comment about '--index-info' that was renamed '--build-fake-ancestor' in commit 26b28007689d27a921ea90e5a29fc8eb74b0d297 (apply: get rid of --index-info in favor of --build-fake-ancestor, Sep 17 2007). 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 a0bfaf0796e416bb1cecd03e30af3e189a039a29
1 file changed +5 -8
builtin/apply.c
+5 -8
@@ -47,18 +47,15 @@ struct apply_state {
47 int unsafe_paths;
48
49 /* Other non boolean parameters */
50 + const char *fake_ancestor;
51 int line_termination;
52 };
53
53 -/*
54 - * --index-info shows the old and new index info for paths if available.
55 - */
54 static int newfd = -1;
55
56 static int state_p_value = 1;
57 static int p_value_known;
58 static int apply = 1;
61 -static const char *fake_ancestor;
59 static unsigned int p_context = UINT_MAX;
60 static const char * const apply_usage[] = {
61 N_("git apply [<options>] [<patch>...]"),
@@ -4486,8 +4483,8 @@ static int apply_patch(struct apply_state *state,
4483 return 1;
4484 }
4485
4489 - if (fake_ancestor)
4490 - build_fake_ancestor(list, fake_ancestor);
4486 + if (state->fake_ancestor)
4487 + build_fake_ancestor(list, state->fake_ancestor);
4488
4489 if (state->diffstat)
4490 stat_patch_list(list);
@@ -4626,7 +4623,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4623 N_("also apply the patch (use with --stat/--summary/--check)")),
4624 OPT_BOOL('3', "3way", &state.threeway,
4625 N_( "attempt three-way merge if a patch does not apply")),
4629 - OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
4626 + OPT_FILENAME(0, "build-fake-ancestor", &state.fake_ancestor,
4627 N_("build a temporary index based on embedded index information")),
4628 /* Think twice before adding "--nul" synonym to this */
4629 OPT_SET_INT('z', NULL, &state.line_termination,
@@ -4679,7 +4676,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4676 }
4677 if (state.apply_with_reject)
4678 apply = state.apply_verbosely = 1;
4682 - if (!force_apply && (state.diffstat || state.numstat || state.summary || state.check || fake_ancestor))
4679 + if (!force_apply && (state.diffstat || state.numstat || state.summary || state.check || state.fake_ancestor))
4680 apply = 0;
4681 if (state.check_index && is_not_gitdir)
4682 die(_("--index outside a repository"));