5 static void git_apply_config(void)
7 git_config_get_string_const("apply.whitespace", &apply_default_whitespace
);
8 git_config_get_string_const("apply.ignorewhitespace", &apply_default_ignorewhitespace
);
9 git_config(git_default_config
, NULL
);
12 int parse_whitespace_option(struct apply_state
*state
, const char *option
)
15 state
->ws_error_action
= warn_on_ws_error
;
18 if (!strcmp(option
, "warn")) {
19 state
->ws_error_action
= warn_on_ws_error
;
22 if (!strcmp(option
, "nowarn")) {
23 state
->ws_error_action
= nowarn_ws_error
;
26 if (!strcmp(option
, "error")) {
27 state
->ws_error_action
= die_on_ws_error
;
30 if (!strcmp(option
, "error-all")) {
31 state
->ws_error_action
= die_on_ws_error
;
32 state
->squelch_whitespace_errors
= 0;
35 if (!strcmp(option
, "strip") || !strcmp(option
, "fix")) {
36 state
->ws_error_action
= correct_ws_error
;
39 return error(_("unrecognized whitespace option '%s'"), option
);
42 int parse_ignorewhitespace_option(struct apply_state
*state
,
45 if (!option
|| !strcmp(option
, "no") ||
46 !strcmp(option
, "false") || !strcmp(option
, "never") ||
47 !strcmp(option
, "none")) {
48 state
->ws_ignore_action
= ignore_ws_none
;
51 if (!strcmp(option
, "change")) {
52 state
->ws_ignore_action
= ignore_ws_change
;
55 return error(_("unrecognized whitespace ignore option '%s'"), option
);
58 void init_apply_state(struct apply_state
*state
,
60 struct lock_file
*lock_file
)
62 memset(state
, 0, sizeof(*state
));
63 state
->prefix
= prefix
;
64 state
->prefix_length
= state
->prefix
? strlen(state
->prefix
) : 0;
65 state
->lock_file
= lock_file
;
68 state
->line_termination
= '\n';
70 state
->p_context
= UINT_MAX
;
71 state
->squelch_whitespace_errors
= 5;
72 state
->ws_error_action
= warn_on_ws_error
;
73 state
->ws_ignore_action
= ignore_ws_none
;
75 string_list_init(&state
->fn_table
, 0);
76 string_list_init(&state
->limit_by_name
, 0);
77 string_list_init(&state
->symlink_changes
, 0);
78 strbuf_init(&state
->root
, 0);
81 if (apply_default_whitespace
&& parse_whitespace_option(state
, apply_default_whitespace
))
83 if (apply_default_ignorewhitespace
&& parse_ignorewhitespace_option(state
, apply_default_ignorewhitespace
))
87 void clear_apply_state(struct apply_state
*state
)
89 string_list_clear(&state
->limit_by_name
, 0);
90 string_list_clear(&state
->symlink_changes
, 0);
91 strbuf_release(&state
->root
);
93 /* &state->fn_table is cleared at the end of apply_patch() */