Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 1 | #ifndef APPLY_H |
| 2 | #define APPLY_H |
| 3 | |
| 4 | enum apply_ws_error_action { |
| 5 | nowarn_ws_error, |
| 6 | warn_on_ws_error, |
| 7 | die_on_ws_error, |
| 8 | correct_ws_error |
| 9 | }; |
| 10 | |
| 11 | enum apply_ws_ignore { |
| 12 | ignore_ws_none, |
| 13 | ignore_ws_change |
| 14 | }; |
| 15 | |
Christian Couder | a46160d | 2016-09-04 22:18:25 +0200 | [diff] [blame] | 16 | enum apply_verbosity { |
| 17 | verbosity_silent = -1, |
| 18 | verbosity_normal = 0, |
| 19 | verbosity_verbose = 1 |
| 20 | }; |
| 21 | |
Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 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 | |
| 36 | struct apply_state { |
| 37 | const char *prefix; |
Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 38 | |
Martin Ågren | d13cd4c | 2017-10-05 22:32:10 +0200 | [diff] [blame] | 39 | /* Lock file */ |
Martin Ågren | 6d058c8 | 2017-10-05 22:32:09 +0200 | [diff] [blame] | 40 | struct lock_file lock_file; |
Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 41 | |
| 42 | /* These control what gets looked at and modified */ |
| 43 | int apply; /* this is not a dry-run */ |
| 44 | int cached; /* apply to the index only */ |
| 45 | int check; /* preimage must match working tree, don't actually apply */ |
| 46 | int check_index; /* preimage must match the indexed version */ |
| 47 | int update_index; /* check_index && apply */ |
| 48 | |
| 49 | /* These control cosmetic aspect of the output */ |
| 50 | int diffstat; /* just show a diffstat, and don't actually apply */ |
| 51 | int numstat; /* just show a numeric diffstat, and don't actually apply */ |
| 52 | int summary; /* just report creation, deletion, etc, and don't actually apply */ |
| 53 | |
| 54 | /* These boolean parameters control how the apply is done */ |
| 55 | int allow_overlap; |
| 56 | int apply_in_reverse; |
| 57 | int apply_with_reject; |
Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 58 | int no_add; |
| 59 | int threeway; |
| 60 | int unidiff_zero; |
| 61 | int unsafe_paths; |
| 62 | |
| 63 | /* Other non boolean parameters */ |
Christian Couder | 5b0b57f | 2016-09-04 22:18:32 +0200 | [diff] [blame] | 64 | const char *index_file; |
Christian Couder | a46160d | 2016-09-04 22:18:25 +0200 | [diff] [blame] | 65 | enum apply_verbosity apply_verbosity; |
Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 66 | const char *fake_ancestor; |
| 67 | const char *patch_input_file; |
| 68 | int line_termination; |
| 69 | struct strbuf root; |
| 70 | int p_value; |
| 71 | int p_value_known; |
| 72 | unsigned int p_context; |
| 73 | |
| 74 | /* Exclude and include path parameters */ |
| 75 | struct string_list limit_by_name; |
| 76 | int has_include; |
| 77 | |
| 78 | /* Various "current state" */ |
| 79 | int linenr; /* current line number */ |
| 80 | struct string_list symlink_changes; /* we have to track symlinks */ |
| 81 | |
| 82 | /* |
| 83 | * For "diff-stat" like behaviour, we keep track of the biggest change |
| 84 | * we've seen, and the longest filename. That allows us to do simple |
| 85 | * scaling. |
| 86 | */ |
| 87 | int max_change; |
| 88 | int max_len; |
| 89 | |
| 90 | /* |
| 91 | * Records filenames that have been touched, in order to handle |
| 92 | * the case where more than one patches touch the same file. |
| 93 | */ |
| 94 | struct string_list fn_table; |
| 95 | |
Christian Couder | 45b78d8 | 2016-09-04 22:18:29 +0200 | [diff] [blame] | 96 | /* |
| 97 | * This is to save reporting routines before using |
| 98 | * set_error_routine() or set_warn_routine() to install muting |
| 99 | * routines when in verbosity_silent mode. |
| 100 | */ |
| 101 | void (*saved_error_routine)(const char *err, va_list params); |
| 102 | void (*saved_warn_routine)(const char *warn, va_list params); |
| 103 | |
Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 104 | /* These control whitespace errors */ |
| 105 | enum apply_ws_error_action ws_error_action; |
| 106 | enum apply_ws_ignore ws_ignore_action; |
| 107 | const char *whitespace_option; |
| 108 | int whitespace_error; |
| 109 | int squelch_whitespace_errors; |
| 110 | int applied_after_fixing_ws; |
| 111 | }; |
| 112 | |
Christian Couder | 7e1bad2 | 2016-09-04 22:18:30 +0200 | [diff] [blame] | 113 | extern int apply_parse_options(int argc, const char **argv, |
| 114 | struct apply_state *state, |
| 115 | int *force_apply, int *options, |
| 116 | const char * const *apply_usage); |
Christian Couder | 2f5a6d1 | 2016-08-08 23:03:08 +0200 | [diff] [blame] | 117 | extern int init_apply_state(struct apply_state *state, |
Martin Ågren | 6d058c8 | 2017-10-05 22:32:09 +0200 | [diff] [blame] | 118 | const char *prefix); |
Christian Couder | bb493a5 | 2016-08-08 23:03:07 +0200 | [diff] [blame] | 119 | extern void clear_apply_state(struct apply_state *state); |
Christian Couder | b6446d5 | 2016-08-08 23:03:10 +0200 | [diff] [blame] | 120 | extern int check_apply_state(struct apply_state *state, int force_apply); |
Christian Couder | bb493a5 | 2016-08-08 23:03:07 +0200 | [diff] [blame] | 121 | |
Christian Couder | 803bf4e | 2016-09-04 22:18:21 +0200 | [diff] [blame] | 122 | /* |
| 123 | * Some aspects of the apply behavior are controlled by the following |
| 124 | * bits in the "options" parameter passed to apply_all_patches(). |
| 125 | */ |
| 126 | #define APPLY_OPT_INACCURATE_EOF (1<<0) /* accept inaccurate eof */ |
| 127 | #define APPLY_OPT_RECOUNT (1<<1) /* accept inaccurate line count */ |
| 128 | |
Christian Couder | 13b5af2 | 2016-04-22 20:55:46 +0200 | [diff] [blame] | 129 | extern int apply_all_patches(struct apply_state *state, |
| 130 | int argc, |
| 131 | const char **argv, |
| 132 | int options); |
| 133 | |
Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 134 | #endif |