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