Junio C Hamano | be3cfa8 | 2005-04-26 09:25:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 Junio C Hamano |
| 3 | */ |
Junio C Hamano | 86436c2 | 2005-04-25 18:22:47 -0700 | [diff] [blame] | 4 | #ifndef DIFF_H |
| 5 | #define DIFF_H |
| 6 | |
Junio C Hamano | 1b0c717 | 2006-03-29 22:55:43 -0800 | [diff] [blame] | 7 | #include "tree-walk.h" |
Linus Torvalds | 50f9a85 | 2006-01-31 14:10:56 -0800 | [diff] [blame] | 8 | |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 9 | struct rev_info; |
Linus Torvalds | ac1b3d1 | 2005-10-20 21:05:05 -0700 | [diff] [blame] | 10 | struct diff_options; |
Jeff King | 0424558 | 2006-09-07 02:35:42 -0400 | [diff] [blame] | 11 | struct diff_queue_struct; |
Linus Torvalds | ac1b3d1 | 2005-10-20 21:05:05 -0700 | [diff] [blame] | 12 | |
| 13 | typedef void (*change_fn_t)(struct diff_options *options, |
| 14 | unsigned old_mode, unsigned new_mode, |
| 15 | const unsigned char *old_sha1, |
| 16 | const unsigned char *new_sha1, |
| 17 | const char *base, const char *path); |
| 18 | |
| 19 | typedef void (*add_remove_fn_t)(struct diff_options *options, |
| 20 | int addremove, unsigned mode, |
| 21 | const unsigned char *sha1, |
| 22 | const char *base, const char *path); |
| 23 | |
Jeff King | 0424558 | 2006-09-07 02:35:42 -0400 | [diff] [blame] | 24 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, |
| 25 | struct diff_options *options, void *data); |
| 26 | |
Timo Hirvonen | c674434 | 2006-06-24 20:21:53 +0300 | [diff] [blame] | 27 | #define DIFF_FORMAT_RAW 0x0001 |
| 28 | #define DIFF_FORMAT_DIFFSTAT 0x0002 |
Junio C Hamano | 74e2abe | 2006-10-12 03:01:00 -0700 | [diff] [blame] | 29 | #define DIFF_FORMAT_NUMSTAT 0x0004 |
| 30 | #define DIFF_FORMAT_SUMMARY 0x0008 |
| 31 | #define DIFF_FORMAT_PATCH 0x0010 |
Nicolas Pitre | ebd124c | 2006-12-14 23:15:44 -0500 | [diff] [blame] | 32 | #define DIFF_FORMAT_SHORTSTAT 0x0020 |
Timo Hirvonen | c674434 | 2006-06-24 20:21:53 +0300 | [diff] [blame] | 33 | |
| 34 | /* These override all above */ |
Junio C Hamano | 74e2abe | 2006-10-12 03:01:00 -0700 | [diff] [blame] | 35 | #define DIFF_FORMAT_NAME 0x0100 |
| 36 | #define DIFF_FORMAT_NAME_STATUS 0x0200 |
| 37 | #define DIFF_FORMAT_CHECKDIFF 0x0400 |
Timo Hirvonen | c674434 | 2006-06-24 20:21:53 +0300 | [diff] [blame] | 38 | |
| 39 | /* Same as output_format = 0 but we know that -s flag was given |
| 40 | * and we should not give default value to output_format. |
| 41 | */ |
Junio C Hamano | 74e2abe | 2006-10-12 03:01:00 -0700 | [diff] [blame] | 42 | #define DIFF_FORMAT_NO_OUTPUT 0x0800 |
Timo Hirvonen | c674434 | 2006-06-24 20:21:53 +0300 | [diff] [blame] | 43 | |
Junio C Hamano | 74e2abe | 2006-10-12 03:01:00 -0700 | [diff] [blame] | 44 | #define DIFF_FORMAT_CALLBACK 0x1000 |
Jeff King | 0424558 | 2006-09-07 02:35:42 -0400 | [diff] [blame] | 45 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 46 | struct diff_options { |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 47 | const char *filter; |
| 48 | const char *orderfile; |
| 49 | const char *pickaxe; |
Junio C Hamano | 2f3f8b2 | 2006-11-02 00:02:11 -0800 | [diff] [blame] | 50 | const char *single_follow; |
Linus Torvalds | ac1b3d1 | 2005-10-20 21:05:05 -0700 | [diff] [blame] | 51 | unsigned recursive:1, |
Junio C Hamano | 80b1e51 | 2005-11-14 17:53:22 -0800 | [diff] [blame] | 52 | tree_in_recursive:1, |
Junio C Hamano | 0660626 | 2006-05-05 02:41:53 -0700 | [diff] [blame] | 53 | binary:1, |
Stephan Feder | 6d64ea9 | 2006-07-07 12:33:57 +0200 | [diff] [blame] | 54 | text:1, |
Junio C Hamano | 6973dca | 2006-04-21 23:57:45 -0700 | [diff] [blame] | 55 | full_index:1, |
| 56 | silent_on_remove:1, |
Sean | 4bbd261 | 2006-05-14 08:13:49 -0400 | [diff] [blame] | 57 | find_copies_harder:1, |
Johannes Schindelin | f59a59e | 2006-07-28 23:56:15 +0200 | [diff] [blame] | 58 | color_diff:1, |
| 59 | color_diff_words:1; |
Linus Torvalds | ee1e541 | 2006-05-13 13:23:48 -0700 | [diff] [blame] | 60 | int context; |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 61 | int break_opt; |
| 62 | int detect_rename; |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 63 | int line_termination; |
| 64 | int output_format; |
| 65 | int pickaxe_opts; |
| 66 | int rename_score; |
| 67 | int reverse_diff; |
Junio C Hamano | 8082d8d | 2005-09-21 00:18:27 -0700 | [diff] [blame] | 68 | int rename_limit; |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 69 | int setup; |
Junio C Hamano | 47dd0d5 | 2005-12-13 17:21:41 -0800 | [diff] [blame] | 70 | int abbrev; |
Timo Hirvonen | 39bc9a6 | 2006-06-25 13:54:14 +0300 | [diff] [blame] | 71 | const char *msg_sep; |
Johannes Schindelin | 698ce6f | 2006-05-20 15:40:29 +0200 | [diff] [blame] | 72 | const char *stat_sep; |
Johannes Schindelin | 0d21efa | 2006-06-14 17:40:23 +0200 | [diff] [blame] | 73 | long xdl_opts; |
Linus Torvalds | ac1b3d1 | 2005-10-20 21:05:05 -0700 | [diff] [blame] | 74 | |
Junio C Hamano | a254002 | 2006-09-26 18:53:02 -0700 | [diff] [blame] | 75 | int stat_width; |
| 76 | int stat_name_width; |
| 77 | |
Junio C Hamano | a8baa7b | 2006-04-10 16:39:11 -0700 | [diff] [blame] | 78 | int nr_paths; |
| 79 | const char **paths; |
| 80 | int *pathlens; |
Linus Torvalds | ac1b3d1 | 2005-10-20 21:05:05 -0700 | [diff] [blame] | 81 | change_fn_t change; |
| 82 | add_remove_fn_t add_remove; |
Jeff King | 0424558 | 2006-09-07 02:35:42 -0400 | [diff] [blame] | 83 | diff_format_fn_t format_callback; |
| 84 | void *format_callback_data; |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Jeff King | ce43697 | 2006-07-23 05:24:18 -0400 | [diff] [blame] | 87 | enum color_diff { |
| 88 | DIFF_RESET = 0, |
| 89 | DIFF_PLAIN = 1, |
| 90 | DIFF_METAINFO = 2, |
| 91 | DIFF_FRAGINFO = 3, |
| 92 | DIFF_FILE_OLD = 4, |
| 93 | DIFF_FILE_NEW = 5, |
| 94 | DIFF_COMMIT = 6, |
Junio C Hamano | 448c3ef | 2006-09-22 22:48:39 -0700 | [diff] [blame] | 95 | DIFF_WHITESPACE = 7, |
Jeff King | ce43697 | 2006-07-23 05:24:18 -0400 | [diff] [blame] | 96 | }; |
| 97 | const char *diff_get_color(int diff_use_color, enum color_diff ix); |
| 98 | |
Johannes Schindelin | 698ce6f | 2006-05-20 15:40:29 +0200 | [diff] [blame] | 99 | extern const char mime_boundary_leader[]; |
| 100 | |
Junio C Hamano | a8baa7b | 2006-04-10 16:39:11 -0700 | [diff] [blame] | 101 | extern void diff_tree_setup_paths(const char **paths, struct diff_options *); |
| 102 | extern void diff_tree_release_paths(struct diff_options *); |
Linus Torvalds | ac1b3d1 | 2005-10-20 21:05:05 -0700 | [diff] [blame] | 103 | extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2, |
| 104 | const char *base, struct diff_options *opt); |
| 105 | extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new, |
| 106 | const char *base, struct diff_options *opt); |
Rene Scharfe | 2b60356 | 2006-10-26 18:52:39 +0200 | [diff] [blame] | 107 | extern int diff_root_tree_sha1(const unsigned char *new, const char *base, |
| 108 | struct diff_options *opt); |
Linus Torvalds | ac1b3d1 | 2005-10-20 21:05:05 -0700 | [diff] [blame] | 109 | |
Junio C Hamano | ea726d0 | 2006-01-28 00:03:38 -0800 | [diff] [blame] | 110 | struct combine_diff_path { |
| 111 | struct combine_diff_path *next; |
| 112 | int len; |
| 113 | char *path; |
Junio C Hamano | 2454c96 | 2006-02-06 12:53:07 -0800 | [diff] [blame] | 114 | unsigned int mode; |
Junio C Hamano | ea726d0 | 2006-01-28 00:03:38 -0800 | [diff] [blame] | 115 | unsigned char sha1[20]; |
Junio C Hamano | 2454c96 | 2006-02-06 12:53:07 -0800 | [diff] [blame] | 116 | struct combine_diff_parent { |
Junio C Hamano | d416df8 | 2006-02-10 02:30:52 -0800 | [diff] [blame] | 117 | char status; |
Junio C Hamano | 2454c96 | 2006-02-06 12:53:07 -0800 | [diff] [blame] | 118 | unsigned int mode; |
| 119 | unsigned char sha1[20]; |
| 120 | } parent[FLEX_ARRAY]; |
Junio C Hamano | ea726d0 | 2006-01-28 00:03:38 -0800 | [diff] [blame] | 121 | }; |
Junio C Hamano | 2454c96 | 2006-02-06 12:53:07 -0800 | [diff] [blame] | 122 | #define combine_diff_path_size(n, l) \ |
| 123 | (sizeof(struct combine_diff_path) + \ |
| 124 | sizeof(struct combine_diff_parent) * (n) + (l) + 1) |
Junio C Hamano | ea726d0 | 2006-01-28 00:03:38 -0800 | [diff] [blame] | 125 | |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 126 | extern void show_combined_diff(struct combine_diff_path *elem, int num_parent, |
| 127 | int dense, struct rev_info *); |
Junio C Hamano | ea726d0 | 2006-01-28 00:03:38 -0800 | [diff] [blame] | 128 | |
Junio C Hamano | 0fe7c1d | 2006-04-29 01:24:49 -0700 | [diff] [blame] | 129 | extern void diff_tree_combined(const unsigned char *sha1, const unsigned char parent[][20], int num_parent, int dense, struct rev_info *rev); |
| 130 | |
Linus Torvalds | 9153983 | 2006-04-17 11:59:32 -0700 | [diff] [blame] | 131 | extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *); |
Junio C Hamano | af3feef | 2006-01-24 01:22:04 -0800 | [diff] [blame] | 132 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 133 | extern void diff_addremove(struct diff_options *, |
| 134 | int addremove, |
Junio C Hamano | 77eb272 | 2005-04-27 09:21:00 -0700 | [diff] [blame] | 135 | unsigned mode, |
| 136 | const unsigned char *sha1, |
| 137 | const char *base, |
| 138 | const char *path); |
| 139 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 140 | extern void diff_change(struct diff_options *, |
| 141 | unsigned mode1, unsigned mode2, |
| 142 | const unsigned char *sha1, |
| 143 | const unsigned char *sha2, |
| 144 | const char *base, const char *path); |
Junio C Hamano | 77eb272 | 2005-04-27 09:21:00 -0700 | [diff] [blame] | 145 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 146 | extern void diff_unmerge(struct diff_options *, |
Junio C Hamano | e9c8409 | 2007-01-05 01:25:18 -0800 | [diff] [blame] | 147 | const char *path, |
| 148 | unsigned mode, |
| 149 | const unsigned char *sha1); |
Junio C Hamano | 77eb272 | 2005-04-27 09:21:00 -0700 | [diff] [blame] | 150 | |
Junio C Hamano | 57fe64a | 2005-05-19 19:00:36 -0700 | [diff] [blame] | 151 | extern int diff_scoreopt_parse(const char *opt); |
| 152 | |
Junio C Hamano | 19feebc | 2005-05-27 15:54:37 -0700 | [diff] [blame] | 153 | #define DIFF_SETUP_REVERSE 1 |
Junio C Hamano | f0c6b2a | 2005-05-27 15:56:38 -0700 | [diff] [blame] | 154 | #define DIFF_SETUP_USE_CACHE 2 |
| 155 | #define DIFF_SETUP_USE_SIZE_CACHE 4 |
Junio C Hamano | ce24067 | 2005-06-03 01:36:43 -0700 | [diff] [blame] | 156 | |
Junio C Hamano | 83ad63c | 2006-07-08 01:05:16 -0700 | [diff] [blame] | 157 | extern int git_diff_ui_config(const char *var, const char *value); |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 158 | extern void diff_setup(struct diff_options *); |
| 159 | extern int diff_opt_parse(struct diff_options *, const char **, int); |
| 160 | extern int diff_setup_done(struct diff_options *); |
Junio C Hamano | 86436c2 | 2005-04-25 18:22:47 -0700 | [diff] [blame] | 161 | |
Junio C Hamano | 6b14d7f | 2005-05-22 10:04:37 -0700 | [diff] [blame] | 162 | #define DIFF_DETECT_RENAME 1 |
| 163 | #define DIFF_DETECT_COPY 2 |
| 164 | |
Junio C Hamano | 367cec1 | 2005-05-27 15:55:28 -0700 | [diff] [blame] | 165 | #define DIFF_PICKAXE_ALL 1 |
Petr Baudis | d01d8c6 | 2006-03-29 02:16:33 +0200 | [diff] [blame] | 166 | #define DIFF_PICKAXE_REGEX 2 |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 167 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 168 | extern void diffcore_std(struct diff_options *); |
Junio C Hamano | f2ce9fd | 2005-06-11 20:57:13 -0700 | [diff] [blame] | 169 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 170 | extern void diffcore_std_no_resolve(struct diff_options *); |
Junio C Hamano | befe863 | 2005-05-29 16:56:13 -0700 | [diff] [blame] | 171 | |
Junio C Hamano | dda2d79 | 2005-07-13 12:52:35 -0700 | [diff] [blame] | 172 | #define COMMON_DIFF_OPTIONS_HELP \ |
| 173 | "\ncommon diff options:\n" \ |
Junio C Hamano | 8082d8d | 2005-09-21 00:18:27 -0700 | [diff] [blame] | 174 | " -z output diff-raw with lines terminated with NUL.\n" \ |
| 175 | " -p output patch format.\n" \ |
| 176 | " -u synonym for -p.\n" \ |
Petr Baudis | 5c91da2 | 2006-04-11 13:22:17 +0200 | [diff] [blame] | 177 | " --patch-with-raw\n" \ |
| 178 | " output both a patch and the diff-raw format.\n" \ |
Johannes Schindelin | d75f795 | 2006-04-14 00:15:30 +0200 | [diff] [blame] | 179 | " --stat show diffstat instead of patch.\n" \ |
Junio C Hamano | 74e2abe | 2006-10-12 03:01:00 -0700 | [diff] [blame] | 180 | " --numstat show numeric diffstat instead of patch.\n" \ |
Johannes Schindelin | 2935327 | 2006-04-15 13:41:18 +0200 | [diff] [blame] | 181 | " --patch-with-stat\n" \ |
| 182 | " output a patch and prepend its diffstat.\n" \ |
Junio C Hamano | 8082d8d | 2005-09-21 00:18:27 -0700 | [diff] [blame] | 183 | " --name-only show only names of changed files.\n" \ |
Junio C Hamano | 946f5f7 | 2005-09-21 00:20:06 -0700 | [diff] [blame] | 184 | " --name-status show names and status of changed files.\n" \ |
Junio C Hamano | 47dd0d5 | 2005-12-13 17:21:41 -0800 | [diff] [blame] | 185 | " --full-index show full object name on index lines.\n" \ |
Junio C Hamano | 913419f | 2005-12-18 02:03:15 -0800 | [diff] [blame] | 186 | " --abbrev=<n> abbreviate object names in diff-tree header and diff-raw.\n" \ |
Junio C Hamano | 8082d8d | 2005-09-21 00:18:27 -0700 | [diff] [blame] | 187 | " -R swap input file pairs.\n" \ |
| 188 | " -B detect complete rewrites.\n" \ |
| 189 | " -M detect renames.\n" \ |
| 190 | " -C detect copies.\n" \ |
Junio C Hamano | dda2d79 | 2005-07-13 12:52:35 -0700 | [diff] [blame] | 191 | " --find-copies-harder\n" \ |
Junio C Hamano | 8082d8d | 2005-09-21 00:18:27 -0700 | [diff] [blame] | 192 | " try unchanged files as candidate for copy detection.\n" \ |
| 193 | " -l<n> limit rename attempts up to <n> paths.\n" \ |
| 194 | " -O<file> reorder diffs according to the <file>.\n" \ |
| 195 | " -S<string> find filepair whose only one side contains the string.\n" \ |
Junio C Hamano | dda2d79 | 2005-07-13 12:52:35 -0700 | [diff] [blame] | 196 | " --pickaxe-all\n" \ |
Stephan Feder | ca49920 | 2006-07-07 15:57:08 +0200 | [diff] [blame] | 197 | " show all files diff when -S is used and hit is found.\n" \ |
| 198 | " -a --text treat all files as text.\n" |
Junio C Hamano | dda2d79 | 2005-07-13 12:52:35 -0700 | [diff] [blame] | 199 | |
Junio C Hamano | 38c6f78 | 2005-05-21 19:40:36 -0700 | [diff] [blame] | 200 | extern int diff_queue_is_empty(void); |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 201 | extern void diff_flush(struct diff_options*); |
Junio C Hamano | 86436c2 | 2005-04-25 18:22:47 -0700 | [diff] [blame] | 202 | |
Junio C Hamano | e7baa4f | 2005-07-25 13:05:44 -0700 | [diff] [blame] | 203 | /* diff-raw status letters */ |
Junio C Hamano | ca8c915 | 2005-07-25 14:31:19 -0700 | [diff] [blame] | 204 | #define DIFF_STATUS_ADDED 'A' |
Junio C Hamano | e7baa4f | 2005-07-25 13:05:44 -0700 | [diff] [blame] | 205 | #define DIFF_STATUS_COPIED 'C' |
| 206 | #define DIFF_STATUS_DELETED 'D' |
| 207 | #define DIFF_STATUS_MODIFIED 'M' |
| 208 | #define DIFF_STATUS_RENAMED 'R' |
| 209 | #define DIFF_STATUS_TYPE_CHANGED 'T' |
| 210 | #define DIFF_STATUS_UNKNOWN 'X' |
| 211 | #define DIFF_STATUS_UNMERGED 'U' |
| 212 | |
| 213 | /* these are not diff-raw status letters proper, but used by |
| 214 | * diffcore-filter insn to specify additional restrictions. |
| 215 | */ |
Junio C Hamano | 0b34379 | 2005-10-04 17:44:17 -0700 | [diff] [blame] | 216 | #define DIFF_STATUS_FILTER_AON '*' |
Junio C Hamano | e7baa4f | 2005-07-25 13:05:44 -0700 | [diff] [blame] | 217 | #define DIFF_STATUS_FILTER_BROKEN 'B' |
| 218 | |
Junio C Hamano | 47dd0d5 | 2005-12-13 17:21:41 -0800 | [diff] [blame] | 219 | extern const char *diff_unique_abbrev(const unsigned char *, int); |
| 220 | |
Junio C Hamano | 6973dca | 2006-04-21 23:57:45 -0700 | [diff] [blame] | 221 | extern int run_diff_files(struct rev_info *revs, int silent_on_removed); |
| 222 | |
Junio C Hamano | 5c21ac0 | 2006-04-22 03:58:04 -0700 | [diff] [blame] | 223 | extern int run_diff_index(struct rev_info *revs, int cached); |
Junio C Hamano | e09ad6e | 2006-04-22 02:43:00 -0700 | [diff] [blame] | 224 | |
Junio C Hamano | 1cfe773 | 2007-01-30 01:11:08 -0800 | [diff] [blame] | 225 | extern int do_diff_cache(const unsigned char *, struct diff_options *); |
Johannes Schindelin | fcb3d0a | 2006-06-25 03:51:08 +0200 | [diff] [blame] | 226 | extern int diff_flush_patch_id(struct diff_options *, unsigned char *); |
| 227 | |
Junio C Hamano | 86436c2 | 2005-04-25 18:22:47 -0700 | [diff] [blame] | 228 | #endif /* DIFF_H */ |