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