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

To libify the apply functionality the 'check' 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 22a7233584b1983e2a7337d3b0f2c13f0cc34651
1 file changed +7 -7
builtin/apply.c
+7 -7
@@ -25,13 +25,14 @@ struct apply_state {
25 const char *prefix;
26 int prefix_length;
27
28 + /* These control what gets looked at and modified */
29 + int check; /* preimage must match working tree, don't actually apply */
30 +
31 /* These boolean parameters control how the apply is done */
32 int unidiff_zero;
33 };
34
35 /*
33 - * --check turns on checking that the working tree matches the
34 - * files that are being modified, but doesn't apply the patch
36 * --stat does just a diffstat, and doesn't actually apply
37 * --numstat does numeric diffstat, and doesn't actually apply
38 * --index-info shows the old and new index info for paths if available.
@@ -48,7 +49,6 @@ static int cached;
49 static int diffstat;
50 static int numstat;
51 static int summary;
51 -static int check;
52 static int apply = 1;
53 static int apply_in_reverse;
54 static int apply_with_reject;
@@ -2053,7 +2053,7 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si
2053 * without metadata change. A binary patch appears
2054 * empty to us here.
2055 */
2056 - if ((apply || check) &&
2056 + if ((apply || state->check) &&
2057 (!patch->is_binary && !metadata_changes(patch)))
2058 die(_("patch with only garbage at line %d"), state_linenr);
2059 }
@@ -4440,7 +4440,7 @@ static int apply_patch(struct apply_state *state,
4440 die(_("unable to read index file"));
4441 }
4442
4443 - if ((check || apply) &&
4443 + if ((state->check || apply) &&
4444 check_patch_list(state, list) < 0 &&
4445 !apply_with_reject)
4446 exit(1);
@@ -4579,7 +4579,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4579 N_("show number of added and deleted lines in decimal notation")),
4580 OPT_BOOL(0, "summary", &summary,
4581 N_("instead of applying the patch, output a summary for the input")),
4582 - OPT_BOOL(0, "check", &check,
4582 + OPT_BOOL(0, "check", &state.check,
4583 N_("instead of applying the patch, see if the patch is applicable")),
4584 OPT_BOOL(0, "index", &check_index,
4585 N_("make sure the patch is applicable to the current index")),
@@ -4644,7 +4644,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4644 }
4645 if (apply_with_reject)
4646 apply = apply_verbosely = 1;
4647 - if (!force_apply && (diffstat || numstat || summary || check || fake_ancestor))
4647 + if (!force_apply && (diffstat || numstat || summary || state.check || fake_ancestor))
4648 apply = 0;
4649 if (check_index && is_not_gitdir)
4650 die(_("--index outside a repository"));