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

To libify the apply functionality the 'diffstat' 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 c4f5c39862671e7de1ffca959220ef94385b1972
1 file changed +6 -5
builtin/apply.c
+6 -5
@@ -31,6 +31,9 @@ struct apply_state {
31 int check_index; /* preimage must match the indexed version */
32 int update_index; /* check_index && apply */
33
34 + /* These control cosmetic aspect of the output */
35 + int diffstat; /* just show a diffstat, and don't actually apply */
36 +
37 /* These boolean parameters control how the apply is done */
38 int allow_overlap;
39 int apply_in_reverse;
@@ -40,7 +43,6 @@ struct apply_state {
43 };
44
45 /*
43 - * --stat does just a diffstat, and doesn't actually apply
46 * --numstat does numeric diffstat, and doesn't actually apply
47 * --index-info shows the old and new index info for paths if available.
48 */
@@ -48,7 +50,6 @@ static int newfd = -1;
50
51 static int state_p_value = 1;
52 static int p_value_known;
51 -static int diffstat;
53 static int numstat;
54 static int summary;
55 static int apply = 1;
@@ -4486,7 +4487,7 @@ static int apply_patch(struct apply_state *state,
4487 if (fake_ancestor)
4488 build_fake_ancestor(list, fake_ancestor);
4489
4489 - if (diffstat)
4490 + if (state->diffstat)
4491 stat_patch_list(list);
4492
4493 if (numstat)
@@ -4602,7 +4603,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4603 0, option_parse_p },
4604 OPT_BOOL(0, "no-add", &no_add,
4605 N_("ignore additions made by the patch")),
4605 - OPT_BOOL(0, "stat", &diffstat,
4606 + OPT_BOOL(0, "stat", &state.diffstat,
4607 N_("instead of applying the patch, output diffstat for the input")),
4608 OPT_NOOP_NOARG(0, "allow-binary-replacement"),
4609 OPT_NOOP_NOARG(0, "binary"),
@@ -4675,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;
4678 - if (!force_apply && (diffstat || numstat || summary || state.check || fake_ancestor))
4679 + if (!force_apply && (state.diffstat || numstat || summary || state.check || fake_ancestor))
4680 apply = 0;
4681 if (state.check_index && is_not_gitdir)
4682 die(_("--index outside a repository"));