1#ifndef APPLY_H 2#define APPLY_H 3 4#include"lockfile.h" 5#include"string-list.h" 6 7struct repository; 8 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 21enum apply_verbosity { 22 verbosity_silent = -1, 23 verbosity_normal =0, 24 verbosity_verbose =1 25}; 26 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 { 42const char*prefix; 43 44/* Lock file */ 45struct lock_file lock_file; 46 47/* These control what gets looked at and modified */ 48int apply;/* this is not a dry-run */ 49int cached;/* apply to the index only */ 50int check;/* preimage must match working tree, don't actually apply */ 51int check_index;/* preimage must match the indexed version */ 52int update_index;/* check_index && apply */ 53int ita_only;/* add intent-to-add entries to the index */ 54 55/* These control cosmetic aspect of the output */ 56int diffstat;/* just show a diffstat, and don't actually apply */ 57int numstat;/* just show a numeric diffstat, and don't actually apply */ 58int summary;/* just report creation, deletion, etc, and don't actually apply */ 59 60/* These boolean parameters control how the apply is done */ 61int allow_overlap; 62int apply_in_reverse; 63int apply_with_reject; 64int no_add; 65int threeway; 66int unidiff_zero; 67int unsafe_paths; 68 69/* Other non boolean parameters */ 70struct repository *repo; 71const char*index_file; 72enum apply_verbosity apply_verbosity; 73const char*fake_ancestor; 74const char*patch_input_file; 75int line_termination; 76struct strbuf root; 77int p_value; 78int p_value_known; 79unsigned int p_context; 80 81/* Exclude and include path parameters */ 82struct string_list limit_by_name; 83int has_include; 84 85/* Various "current state" */ 86int linenr;/* current line number */ 87struct 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 */ 94int max_change; 95int 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 */ 101struct string_list fn_table; 102 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 */ 108void(*saved_error_routine)(const char*err,va_list params); 109void(*saved_warn_routine)(const char*warn,va_list params); 110 111/* These control whitespace errors */ 112enum apply_ws_error_action ws_error_action; 113enum apply_ws_ignore ws_ignore_action; 114const char*whitespace_option; 115int whitespace_error; 116int squelch_whitespace_errors; 117int applied_after_fixing_ws; 118}; 119 120intapply_parse_options(int argc,const char**argv, 121struct apply_state *state, 122int*force_apply,int*options, 123const char*const*apply_usage); 124intinit_apply_state(struct apply_state *state, 125struct repository *repo, 126const char*prefix); 127voidclear_apply_state(struct apply_state *state); 128intcheck_apply_state(struct apply_state *state,int force_apply); 129 130/* 131 * Some aspects of the apply behavior are controlled by the following 132 * bits in the "options" parameter passed to apply_all_patches(). 133 */ 134#define APPLY_OPT_INACCURATE_EOF (1<<0)/* accept inaccurate eof */ 135#define APPLY_OPT_RECOUNT (1<<1)/* accept inaccurate line count */ 136 137intapply_all_patches(struct apply_state *state, 138int argc,const char**argv, 139int options); 140 141#endif