|
9 | 9 | #include "object.h"
|
10 | 10 | #include "oidset.h"
|
11 | 11 |
|
| 12 | +/** |
| 13 | + * The diff API is for programs that compare two sets of files (e.g. two trees, |
| 14 | + * one tree and the index) and present the found difference in various ways. |
| 15 | + * The calling program is responsible for feeding the API pairs of files, one |
| 16 | + * from the "old" set and the corresponding one from "new" set, that are |
| 17 | + * different. |
| 18 | + * The library called through this API is called diffcore, and is responsible |
| 19 | + * for two things. |
| 20 | + * |
| 21 | + * - finding total rewrites (`-B`), renames (`-M`) and copies (`-C`), and |
| 22 | + * changes that touch a string (`-S`), as specified by the caller. |
| 23 | + * |
| 24 | + * - outputting the differences in various formats, as specified by the caller. |
| 25 | + * |
| 26 | + * Calling sequence |
| 27 | + * ---------------- |
| 28 | + * |
| 29 | + * - Prepare `struct diff_options` to record the set of diff options, and then |
| 30 | + * call `repo_diff_setup()` to initialize this structure. This sets up the |
| 31 | + * vanilla default. |
| 32 | + * |
| 33 | + * - Fill in the options structure to specify desired output format, rename |
| 34 | + * detection, etc. `diff_opt_parse()` can be used to parse options given |
| 35 | + * from the command line in a way consistent with existing git-diff family |
| 36 | + * of programs. |
| 37 | + * |
| 38 | + * - Call `diff_setup_done()`; this inspects the options set up so far for |
| 39 | + * internal consistency and make necessary tweaking to it (e.g. if textual |
| 40 | + * patch output was asked, recursive behaviour is turned on); the callback |
| 41 | + * set_default in diff_options can be used to tweak this more. |
| 42 | + * |
| 43 | + * - As you find different pairs of files, call `diff_change()` to feed |
| 44 | + * modified files, `diff_addremove()` to feed created or deleted files, or |
| 45 | + * `diff_unmerge()` to feed a file whose state is 'unmerged' to the API. |
| 46 | + * These are thin wrappers to a lower-level `diff_queue()` function that is |
| 47 | + * flexible enough to record any of these kinds of changes. |
| 48 | + * |
| 49 | + * - Once you finish feeding the pairs of files, call `diffcore_std()`. |
| 50 | + * This will tell the diffcore library to go ahead and do its work. |
| 51 | + * |
| 52 | + * - Calling `diff_flush()` will produce the output. |
| 53 | + */ |
| 54 | + |
12 | 55 | struct combine_diff_path;
|
13 | 56 | struct commit;
|
14 | 57 | struct diff_filespec;
|
@@ -65,21 +108,66 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
|
65 | 108 |
|
66 | 109 | #define DIFF_FLAGS_INIT { 0 }
|
67 | 110 | struct diff_flags {
|
| 111 | + |
| 112 | + /** |
| 113 | + * Tells if tree traversal done by tree-diff should recursively descend |
| 114 | + * into a tree object pair that are different in preimage and postimage set. |
| 115 | + */ |
68 | 116 | unsigned recursive;
|
69 | 117 | unsigned tree_in_recursive;
|
| 118 | + |
| 119 | + /* Affects the way how a file that is seemingly binary is treated. */ |
70 | 120 | unsigned binary;
|
71 | 121 | unsigned text;
|
| 122 | + |
| 123 | + /** |
| 124 | + * Tells the patch output format not to use abbreviated object names on the |
| 125 | + * "index" lines. |
| 126 | + */ |
72 | 127 | unsigned full_index;
|
| 128 | + |
| 129 | + /* Affects if diff-files shows removed files. */ |
73 | 130 | unsigned silent_on_remove;
|
| 131 | + |
| 132 | + /** |
| 133 | + * Tells the diffcore library that the caller is feeding unchanged |
| 134 | + * filepairs to allow copies from unmodified files be detected. |
| 135 | + */ |
74 | 136 | unsigned find_copies_harder;
|
| 137 | + |
75 | 138 | unsigned follow_renames;
|
76 | 139 | unsigned rename_empty;
|
| 140 | + |
| 141 | + /* Internal; used for optimization to see if there is any change. */ |
77 | 142 | unsigned has_changes;
|
| 143 | + |
78 | 144 | unsigned quick;
|
| 145 | + |
| 146 | + /** |
| 147 | + * Tells diff-files that the input is not tracked files but files in random |
| 148 | + * locations on the filesystem. |
| 149 | + */ |
79 | 150 | unsigned no_index;
|
| 151 | + |
| 152 | + /** |
| 153 | + * Tells output routine that it is Ok to call user specified patch output |
| 154 | + * routine. Plumbing disables this to ensure stable output. |
| 155 | + */ |
80 | 156 | unsigned allow_external;
|
| 157 | + |
| 158 | + /** |
| 159 | + * For communication between the calling program and the options parser; |
| 160 | + * tell the calling program to signal the presence of difference using |
| 161 | + * program exit code. |
| 162 | + */ |
81 | 163 | unsigned exit_with_status;
|
| 164 | + |
| 165 | + /** |
| 166 | + * Tells the library that the calling program is feeding the filepairs |
| 167 | + * reversed; `one` is two, and `two` is one. |
| 168 | + */ |
82 | 169 | unsigned reverse_diff;
|
| 170 | + |
83 | 171 | unsigned check_failed;
|
84 | 172 | unsigned relative_name;
|
85 | 173 | unsigned ignore_submodules;
|
@@ -131,36 +219,72 @@ enum diff_submodule_format {
|
131 | 219 | DIFF_SUBMODULE_INLINE_DIFF
|
132 | 220 | };
|
133 | 221 |
|
| 222 | +/** |
| 223 | + * the set of options the calling program wants to affect the operation of |
| 224 | + * diffcore library with. |
| 225 | + */ |
134 | 226 | struct diff_options {
|
135 | 227 | const char *orderfile;
|
| 228 | + |
| 229 | + /** |
| 230 | + * A constant string (can and typically does contain newlines to look for |
| 231 | + * a block of text, not just a single line) to filter out the filepairs |
| 232 | + * that do not change the number of strings contained in its preimage and |
| 233 | + * postimage of the diff_queue. |
| 234 | + */ |
136 | 235 | const char *pickaxe;
|
| 236 | + |
137 | 237 | const char *single_follow;
|
138 | 238 | const char *a_prefix, *b_prefix;
|
139 | 239 | const char *line_prefix;
|
140 | 240 | size_t line_prefix_length;
|
| 241 | + |
| 242 | + /** |
| 243 | + * collection of boolean options that affects the operation, but some do |
| 244 | + * not have anything to do with the diffcore library. |
| 245 | + */ |
141 | 246 | struct diff_flags flags;
|
142 | 247 |
|
143 | 248 | /* diff-filter bits */
|
144 | 249 | unsigned int filter;
|
145 | 250 |
|
146 | 251 | int use_color;
|
| 252 | + |
| 253 | + /* Number of context lines to generate in patch output. */ |
147 | 254 | int context;
|
| 255 | + |
148 | 256 | int interhunkcontext;
|
| 257 | + |
| 258 | + /* Affects the way detection logic for complete rewrites, renames and |
| 259 | + * copies. |
| 260 | + */ |
149 | 261 | int break_opt;
|
150 | 262 | int detect_rename;
|
| 263 | + |
151 | 264 | int irreversible_delete;
|
152 | 265 | int skip_stat_unmatch;
|
153 | 266 | int line_termination;
|
| 267 | + |
| 268 | + /* The output format used when `diff_flush()` is run. */ |
154 | 269 | int output_format;
|
| 270 | + |
155 | 271 | unsigned pickaxe_opts;
|
| 272 | + |
| 273 | + /* Affects the way detection logic for complete rewrites, renames and |
| 274 | + * copies. |
| 275 | + */ |
156 | 276 | int rename_score;
|
157 | 277 | int rename_limit;
|
| 278 | + |
158 | 279 | int needed_rename_limit;
|
159 | 280 | int degraded_cc_to_c;
|
160 | 281 | int show_rename_progress;
|
161 | 282 | int dirstat_permille;
|
162 | 283 | int setup;
|
| 284 | + |
| 285 | + /* Number of hexdigits to abbreviate raw format output to. */ |
163 | 286 | int abbrev;
|
| 287 | + |
164 | 288 | int ita_invisible_in_index;
|
165 | 289 | /* white-space error highlighting */
|
166 | 290 | #define WSEH_NEW (1<<12)
|
@@ -192,6 +316,7 @@ struct diff_options {
|
192 | 316 | /* to support internal diff recursion by --follow hack*/
|
193 | 317 | int found_follow;
|
194 | 318 |
|
| 319 | + /* Callback which allows tweaking the options in diff_setup_done(). */ |
195 | 320 | void (*set_default)(struct diff_options *);
|
196 | 321 |
|
197 | 322 | FILE *file;
|
@@ -270,6 +395,7 @@ enum color_diff {
|
270 | 395 | DIFF_FILE_OLD_BOLD = 21,
|
271 | 396 | DIFF_FILE_NEW_BOLD = 22,
|
272 | 397 | };
|
| 398 | + |
273 | 399 | const char *diff_get_color(int diff_use_color, enum color_diff ix);
|
274 | 400 | #define diff_get_color_opt(o, ix) \
|
275 | 401 | diff_get_color((o)->use_color, ix)
|
|
0 commit comments