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

To libify the apply functionality the 'apply_with_reject' 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 30b5ae4d41c7e5b5655fb0e737db4764a17033c0
1 file changed +7 -7
builtin/apply.c
+7 -7
@@ -31,6 +31,7 @@ struct apply_state {
31
32 /* These boolean parameters control how the apply is done */
33 int apply_in_reverse;
34 + int apply_with_reject;
35 int unidiff_zero;
36 };
37
@@ -50,7 +51,6 @@ static int diffstat;
51 static int numstat;
52 static int summary;
53 static int apply = 1;
53 -static int apply_with_reject;
54 static int apply_verbosely;
55 static int allow_overlap;
56 static int no_add;
@@ -3096,7 +3096,7 @@ static int apply_fragments(struct apply_state *state, struct image *img, struct
3096 nth++;
3097 if (apply_one_fragment(state, img, frag, inaccurate_eof, ws_rule, nth)) {
3098 error(_("patch failed: %s:%ld"), name, frag->oldpos);
3099 - if (!apply_with_reject)
3099 + if (!state->apply_with_reject)
3100 return -1;
3101 frag->rejected = 1;
3102 }
@@ -4462,11 +4462,11 @@ static int apply_patch(struct apply_state *state,
4462
4463 if ((state->check || apply) &&
4464 check_patch_list(state, list) < 0 &&
4465 - !apply_with_reject)
4465 + !state->apply_with_reject)
4466 exit(1);
4467
4468 if (apply && write_out_results(list)) {
4469 - if (apply_with_reject)
4469 + if (state->apply_with_reject)
4470 exit(1);
4471 /* with --3way, we still need to write the index out */
4472 return 1;
@@ -4631,7 +4631,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4631 N_("apply the patch in reverse")),
4632 OPT_BOOL(0, "unidiff-zero", &state.unidiff_zero,
4633 N_("don't expect at least one line of context")),
4634 - OPT_BOOL(0, "reject", &apply_with_reject,
4634 + OPT_BOOL(0, "reject", &state.apply_with_reject,
4635 N_("leave the rejected hunks in corresponding *.rej files")),
4636 OPT_BOOL(0, "allow-overlap", &allow_overlap,
4637 N_("allow overlapping hunks")),
@@ -4653,7 +4653,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4653 argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
4654 apply_usage, 0);
4655
4656 - if (apply_with_reject && threeway)
4656 + if (state.apply_with_reject && threeway)
4657 die("--reject and --3way cannot be used together.");
4658 if (cached && threeway)
4659 die("--cached and --3way cannot be used together.");
@@ -4662,7 +4662,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4662 die(_("--3way outside a repository"));
4663 state.check_index = 1;
4664 }
4665 - if (apply_with_reject)
4665 + if (state.apply_with_reject)
4666 apply = apply_verbosely = 1;
4667 if (!force_apply && (diffstat || numstat || summary || state.check || fake_ancestor))
4668 apply = 0;