6 #include "string-list.h"
10 enum apply_ws_error_action
{
17 enum apply_ws_ignore
{
22 enum apply_verbosity
{
23 verbosity_silent
= -1,
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.
36 * See also "struct string_list symlink_changes" in "struct
39 #define APPLY_SYMLINK_GOES_AWAY 01
40 #define APPLY_SYMLINK_IN_RESULT 02
46 struct lock_file lock_file
;
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 */
54 int ita_only
; /* add intent-to-add entries to the index */
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 */
61 /* These boolean parameters control how the apply is done */
64 int apply_with_reject
;
70 /* Other non boolean parameters */
71 struct repository
*repo
;
72 const char *index_file
;
73 enum apply_verbosity apply_verbosity
;
74 const char *fake_ancestor
;
75 const char *patch_input_file
;
80 unsigned int p_context
;
82 /* Exclude and include path parameters */
83 struct string_list limit_by_name
;
86 /* Various "current state" */
87 int linenr
; /* current line number */
88 struct string_list symlink_changes
; /* we have to track symlinks */
91 * For "diff-stat" like behaviour, we keep track of the biggest change
92 * we've seen, and the longest filename. That allows us to do simple
99 * Records filenames that have been touched, in order to handle
100 * the case where more than one patches touch the same file.
102 struct string_list fn_table
;
105 * This is to save reporting routines before using
106 * set_error_routine() or set_warn_routine() to install muting
107 * routines when in verbosity_silent mode.
109 void (*saved_error_routine
)(const char *err
, va_list params
);
110 void (*saved_warn_routine
)(const char *warn
, va_list params
);
112 /* These control whitespace errors */
113 enum apply_ws_error_action ws_error_action
;
114 enum apply_ws_ignore ws_ignore_action
;
115 const char *whitespace_option
;
116 int whitespace_error
;
117 int squelch_whitespace_errors
;
118 int applied_after_fixing_ws
;
122 * This represents a "patch" to a file, both metainfo changes
123 * such as creation/deletion, filemode and content changes represented
124 * as a series of fragments.
127 char *new_name
, *old_name
, *def_name
;
128 unsigned int old_mode
, new_mode
;
129 int is_new
, is_delete
; /* -1 = unknown, 0 = false, 1 = true */
132 int lines_added
, lines_deleted
;
134 int extension_linenr
; /* first line specifying delete/new/rename/copy */
135 unsigned int is_toplevel_relative
:1;
136 unsigned int inaccurate_eof
:1;
137 unsigned int is_binary
:1;
138 unsigned int is_copy
:1;
139 unsigned int is_rename
:1;
140 unsigned int recount
:1;
141 unsigned int conflicted_threeway
:1;
142 unsigned int direct_to_threeway
:1;
143 unsigned int crlf_in_old
:1;
144 struct fragment
*fragments
;
147 char old_oid_prefix
[GIT_MAX_HEXSZ
+ 1];
148 char new_oid_prefix
[GIT_MAX_HEXSZ
+ 1];
151 /* three-way fallback result */
152 struct object_id threeway_stage
[3];
155 int apply_parse_options(int argc
, const char **argv
,
156 struct apply_state
*state
,
157 int *force_apply
, int *options
,
158 const char * const *apply_usage
);
159 int init_apply_state(struct apply_state
*state
,
160 struct repository
*repo
,
162 void clear_apply_state(struct apply_state
*state
);
163 int check_apply_state(struct apply_state
*state
, int force_apply
);
166 * Parse a git diff header, starting at line. Fills the relevant
167 * metadata information in 'struct patch'.
169 * Returns -1 on failure, the length of the parsed header otherwise.
171 int parse_git_diff_header(struct strbuf
*root
,
177 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
,