builtin/apply: move 'whitespace_option' into 'struct apply_state'
This will enable further refactoring, and it is more coherent and simpler if all the option_parse_*() functions are passed a 'struct apply_state' instance in opt->value. 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
161fcbe9884466e95cf5b1c7cd22f64a16a24045
1 file changed
+6
-7
builtin/apply.c
+6
-7
@@ -61,6 +61,7 @@ struct apply_state {
61
int has_include;
62
63
/* These control whitespace errors */
64
+ const char *whitespace_option;
65
int whitespace_error;
66
};
67
@@ -4619,9 +4620,9 @@ static int option_parse_space_change(const struct option *opt,
4620
static int option_parse_whitespace(const struct option *opt,
4621
const char *arg, int unset)
4622
{
4622
- const char **whitespace_option = opt->value;
4623
+ struct apply_state *state = opt->value;
4624
4624
- *whitespace_option = arg;
4625
+ state->whitespace_option = arg;
4626
parse_whitespace_option(arg);
4627
return 0;
4628
}
@@ -4670,8 +4671,6 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4671
int read_stdin = 1;
4672
struct apply_state state;
4673
4673
- const char *whitespace_option = NULL;
4674
-
4674
struct option builtin_apply_options[] = {
4675
{ OPTION_CALLBACK, 0, "exclude", &state, N_("path"),
4676
N_("don't apply changes matching the given path"),
@@ -4711,7 +4710,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4710
N_("paths are separated with NUL character"), '\0'),
4711
OPT_INTEGER('C', NULL, &state.p_context,
4712
N_("ensure at least <n> lines of context match")),
4714
- { OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"),
4713
+ { OPTION_CALLBACK, 0, "whitespace", &state, N_("action"),
4714
N_("detect new or modified lines that have whitespace errors"),
4715
0, option_parse_whitespace },
4716
{ OPTION_CALLBACK, 0, "ignore-space-change", NULL, NULL,
@@ -4786,11 +4785,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4785
if (fd < 0)
4786
die_errno(_("can't open patch '%s'"), arg);
4787
read_stdin = 0;
4789
- set_default_whitespace_mode(&state, whitespace_option);
4788
+ set_default_whitespace_mode(&state, state.whitespace_option);
4789
errs |= apply_patch(&state, fd, arg, options);
4790
close(fd);
4791
}
4793
- set_default_whitespace_mode(&state, whitespace_option);
4792
+ set_default_whitespace_mode(&state, state.whitespace_option);
4793
if (read_stdin)
4794
errs |= apply_patch(&state, 0, "<stdin>", options);
4795
if (state.whitespace_error) {