1#ifndef APPLY_H 2#define APPLY_H 3 4enum apply_ws_error_action { 5 nowarn_ws_error, 6 warn_on_ws_error, 7 die_on_ws_error, 8 correct_ws_error 9}; 10 11enum apply_ws_ignore { 12 ignore_ws_none, 13 ignore_ws_change 14}; 15 16enum apply_verbosity { 17 verbosity_silent = -1, 18 verbosity_normal =0, 19 verbosity_verbose =1 20}; 21 22/* 23 * We need to keep track of how symlinks in the preimage are 24 * manipulated by the patches. A patch to add a/b/c where a/b 25 * is a symlink should not be allowed to affect the directory 26 * the symlink points at, but if the same patch removes a/b, 27 * it is perfectly fine, as the patch removes a/b to make room 28 * to create a directory a/b so that a/b/c can be created. 29 * 30 * See also "struct string_list symlink_changes" in "struct 31 * apply_state". 32 */ 33#define APPLY_SYMLINK_GOES_AWAY 01 34#define APPLY_SYMLINK_IN_RESULT 02 35 36struct apply_state { 37const char*prefix; 38int prefix_length; 39 40/* These are lock_file related */ 41struct lock_file *lock_file; 42int newfd; 43 44/* These control what gets looked at and modified */ 45int apply;/* this is not a dry-run */ 46int cached;/* apply to the index only */ 47int check;/* preimage must match working tree, don't actually apply */ 48int check_index;/* preimage must match the indexed version */ 49int update_index;/* check_index && apply */ 50 51/* These control cosmetic aspect of the output */ 52int diffstat;/* just show a diffstat, and don't actually apply */ 53int numstat;/* just show a numeric diffstat, and don't actually apply */ 54int summary;/* just report creation, deletion, etc, and don't actually apply */ 55 56/* These boolean parameters control how the apply is done */ 57int allow_overlap; 58int apply_in_reverse; 59int apply_with_reject; 60int no_add; 61int threeway; 62int unidiff_zero; 63int unsafe_paths; 64 65/* Other non boolean parameters */ 66const char*index_file; 67enum apply_verbosity apply_verbosity; 68const char*fake_ancestor; 69const char*patch_input_file; 70int line_termination; 71struct strbuf root; 72int p_value; 73int p_value_known; 74unsigned int p_context; 75 76/* Exclude and include path parameters */ 77struct string_list limit_by_name; 78int has_include; 79 80/* Various "current state" */ 81int linenr;/* current line number */ 82struct string_list symlink_changes;/* we have to track symlinks */ 83 84/* 85 * For "diff-stat" like behaviour, we keep track of the biggest change 86 * we've seen, and the longest filename. That allows us to do simple 87 * scaling. 88 */ 89int max_change; 90int max_len; 91 92/* 93 * Records filenames that have been touched, in order to handle 94 * the case where more than one patches touch the same file. 95 */ 96struct string_list fn_table; 97 98/* 99 * This is to save reporting routines before using 100 * set_error_routine() or set_warn_routine() to install muting 101 * routines when in verbosity_silent mode. 102 */ 103void(*saved_error_routine)(const char*err,va_list params); 104void(*saved_warn_routine)(const char*warn,va_list params); 105 106/* These control whitespace errors */ 107enum apply_ws_error_action ws_error_action; 108enum apply_ws_ignore ws_ignore_action; 109const char*whitespace_option; 110int whitespace_error; 111int squelch_whitespace_errors; 112int applied_after_fixing_ws; 113}; 114 115externintapply_parse_options(int argc,const char**argv, 116struct apply_state *state, 117int*force_apply,int*options, 118const char*const*apply_usage); 119externintinit_apply_state(struct apply_state *state, 120const char*prefix, 121struct lock_file *lock_file); 122externvoidclear_apply_state(struct apply_state *state); 123externintcheck_apply_state(struct apply_state *state,int force_apply); 124 125/* 126 * Some aspects of the apply behavior are controlled by the following 127 * bits in the "options" parameter passed to apply_all_patches(). 128 */ 129#define APPLY_OPT_INACCURATE_EOF (1<<0)/* accept inaccurate eof */ 130#define APPLY_OPT_RECOUNT (1<<1)/* accept inaccurate line count */ 131 132externintapply_all_patches(struct apply_state *state, 133int argc, 134const char**argv, 135int options); 136 137#endif