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 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 { 126char*new_name, *old_name, *def_name; 127unsigned int old_mode, new_mode; 128int is_new, is_delete;/* -1 = unknown, 0 = false, 1 = true */ 129int rejected; 130unsigned ws_rule; 131int lines_added, lines_deleted; 132int score; 133int extension_linenr;/* first line specifying delete/new/rename/copy */ 134unsigned int is_toplevel_relative:1; 135unsigned int inaccurate_eof:1; 136unsigned int is_binary:1; 137unsigned int is_copy:1; 138unsigned int is_rename:1; 139unsigned int recount:1; 140unsigned int conflicted_threeway:1; 141unsigned int direct_to_threeway:1; 142unsigned int crlf_in_old:1; 143struct fragment *fragments; 144char*result; 145size_t resultsize; 146char old_oid_prefix[GIT_MAX_HEXSZ +1]; 147char new_oid_prefix[GIT_MAX_HEXSZ +1]; 148struct patch *next; 149 150/* three-way fallback result */ 151struct object_id threeway_stage[3]; 152}; 153 154intapply_parse_options(int argc,const char**argv, 155struct apply_state *state, 156int*force_apply,int*options, 157const char*const*apply_usage); 158intinit_apply_state(struct apply_state *state, 159struct repository *repo, 160const char*prefix); 161voidclear_apply_state(struct apply_state *state); 162intcheck_apply_state(struct apply_state *state,int force_apply); 163 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 */ 170intparse_git_diff_header(struct strbuf *root, 171int*linenr, 172int p_value, 173const char*line, 174int len, 175unsigned int size, 176struct patch *patch); 177 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 185intapply_all_patches(struct apply_state *state, 186int argc,const char**argv, 187int options); 188 189#endif