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