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 int 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))
88 void clear_apply_state(struct apply_state *state)
90 string_list_clear(&state->limit_by_name, 0);
91 string_list_clear(&state->symlink_changes, 0);
92 strbuf_release(&state->root);
94 /* &state->fn_table is cleared at the end of apply_patch() */
97 int check_apply_state(struct apply_state *state, int force_apply)
99 int is_not_gitdir = !startup_info->have_repository;
101 if (state->apply_with_reject && state->threeway)
102 return error("--reject and --3way cannot be used together.");
103 if (state->cached && state->threeway)
104 return error("--cached and --3way cannot be used together.");
105 if (state->threeway) {
107 return error(_("--3way outside a repository"));
108 state->check_index = 1;
110 if (state->apply_with_reject)
111 state->apply = state->apply_verbosely = 1;
112 if (!force_apply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor))
114 if (state->check_index && is_not_gitdir)
115 return error(_("--index outside a repository"));
118 return error(_("--cached outside a repository"));
119 state->check_index = 1;
121 if (state->check_index)
122 state->unsafe_paths = 0;
123 if (!state->lock_file)
124 return error("BUG: state->lock_file should not be NULL");