Merge branch 'jk/t9001-deflake'
[git/gitster.git] / apply.h
blob90e887ec0edadf68acf5dd534b7c3e9aa9a917c2
1 #ifndef APPLY_H
2 #define APPLY_H
4 #include "hash.h"
5 #include "lockfile.h"
6 #include "string-list.h"
7 #include "strmap.h"
9 struct repository;
11 enum apply_ws_error_action {
12 nowarn_ws_error,
13 warn_on_ws_error,
14 die_on_ws_error,
15 correct_ws_error
18 enum apply_ws_ignore {
19 ignore_ws_none,
20 ignore_ws_change
23 enum apply_verbosity {
24 verbosity_silent = -1,
25 verbosity_normal = 0,
26 verbosity_verbose = 1
29 struct apply_state {
30 const char *prefix;
32 /* Lock file */
33 struct lock_file lock_file;
35 /* These control what gets looked at and modified */
36 int apply; /* this is not a dry-run */
37 int cached; /* apply to the index only */
38 int check; /* preimage must match working tree, don't actually apply */
39 int check_index; /* preimage must match the indexed version */
40 int update_index; /* check_index && apply */
41 int ita_only; /* add intent-to-add entries to the index */
43 /* These control cosmetic aspect of the output */
44 int diffstat; /* just show a diffstat, and don't actually apply */
45 int numstat; /* just show a numeric diffstat, and don't actually apply */
46 int summary; /* just report creation, deletion, etc, and don't actually apply */
48 /* These boolean parameters control how the apply is done */
49 int allow_overlap;
50 int apply_in_reverse;
51 int apply_with_reject;
52 int no_add;
53 int threeway;
54 int unidiff_zero;
55 int unsafe_paths;
56 int allow_empty;
58 /* Other non boolean parameters */
59 struct repository *repo;
60 const char *index_file;
61 enum apply_verbosity apply_verbosity;
62 int merge_variant;
63 char *fake_ancestor;
64 const char *patch_input_file;
65 int line_termination;
66 struct strbuf root;
67 int p_value;
68 int p_value_known;
69 unsigned int p_context;
71 /* Exclude and include path parameters */
72 struct string_list limit_by_name;
73 int has_include;
75 /* Various "current state" */
76 int linenr; /* current line number */
78 * We need to keep track of how symlinks in the preimage are
79 * manipulated by the patches. A patch to add a/b/c where a/b
80 * is a symlink should not be allowed to affect the directory
81 * the symlink points at, but if the same patch removes a/b,
82 * it is perfectly fine, as the patch removes a/b to make room
83 * to create a directory a/b so that a/b/c can be created.
85 struct strset removed_symlinks;
86 struct strset kept_symlinks;
89 * For "diff-stat" like behaviour, we keep track of the biggest change
90 * we've seen, and the longest filename. That allows us to do simple
91 * scaling.
93 int max_change;
94 int max_len;
97 * Records filenames that have been touched, in order to handle
98 * the case where more than one patches touch the same file.
100 struct string_list fn_table;
103 * This is to save reporting routines before using
104 * set_error_routine() or set_warn_routine() to install muting
105 * routines when in verbosity_silent mode.
107 void (*saved_error_routine)(const char *err, va_list params);
108 void (*saved_warn_routine)(const char *warn, va_list params);
110 /* These control whitespace errors */
111 enum apply_ws_error_action ws_error_action;
112 enum apply_ws_ignore ws_ignore_action;
113 const char *whitespace_option;
114 int whitespace_error;
115 int squelch_whitespace_errors;
116 int applied_after_fixing_ws;
120 * This represents a "patch" to a file, both metainfo changes
121 * such as creation/deletion, filemode and content changes represented
122 * as a series of fragments.
124 struct patch {
125 char *new_name, *old_name, *def_name;
126 unsigned int old_mode, new_mode;
127 int is_new, is_delete; /* -1 = unknown, 0 = false, 1 = true */
128 int rejected;
129 unsigned ws_rule;
130 int lines_added, lines_deleted;
131 int score;
132 int extension_linenr; /* first line specifying delete/new/rename/copy */
133 unsigned int is_toplevel_relative:1;
134 unsigned int inaccurate_eof:1;
135 unsigned int is_binary:1;
136 unsigned int is_copy:1;
137 unsigned int is_rename:1;
138 unsigned int recount:1;
139 unsigned int conflicted_threeway:1;
140 unsigned int direct_to_threeway:1;
141 unsigned int crlf_in_old:1;
142 struct fragment *fragments;
143 char *result;
144 size_t resultsize;
145 char old_oid_prefix[GIT_MAX_HEXSZ + 1];
146 char new_oid_prefix[GIT_MAX_HEXSZ + 1];
147 struct patch *next;
149 /* three-way fallback result */
150 struct object_id threeway_stage[3];
153 int apply_parse_options(int argc, const char **argv,
154 struct apply_state *state,
155 int *force_apply, int *options,
156 const char * const *apply_usage);
157 int init_apply_state(struct apply_state *state,
158 struct repository *repo,
159 const char *prefix);
160 void clear_apply_state(struct apply_state *state);
161 int check_apply_state(struct apply_state *state, int force_apply);
164 * Parse a git diff header, starting at line. Fills the relevant
165 * metadata information in 'struct patch'.
167 * Returns -1 on failure, the length of the parsed header otherwise.
169 int parse_git_diff_header(struct strbuf *root,
170 int *linenr,
171 int p_value,
172 const char *line,
173 int len,
174 unsigned int size,
175 struct patch *patch);
177 void release_patch(struct patch *patch);
180 * Some aspects of the apply behavior are controlled by the following
181 * bits in the "options" parameter passed to apply_all_patches().
183 #define APPLY_OPT_INACCURATE_EOF (1<<0) /* accept inaccurate eof */
184 #define APPLY_OPT_RECOUNT (1<<1) /* accept inaccurate line count */
186 int apply_all_patches(struct apply_state *state,
187 int argc, const char **argv,
188 int options);
190 #endif