Raw
1 /*
2 * Copyright (C) 2005 Junio C Hamano
3 */
4 #ifndef DIFF_H
5 #define DIFF_H
6
7 #include "hash.h"
8 #include "pathspec.h"
9 #include "strbuf.h"
10 #include "color.h"
11
12 struct oidset;
13
14 /**
15 * The diff API is for programs that compare two sets of files (e.g. two trees,
16 * one tree and the index) and present the found difference in various ways.
17 * The calling program is responsible for feeding the API pairs of files, one
18 * from the "old" set and the corresponding one from "new" set, that are
19 * different.
20 * The library called through this API is called diffcore, and is responsible
21 * for two things.
22 *
23 * - finding total rewrites (`-B`), renames (`-M`) and copies (`-C`), and
24 * changes that touch a string (`-S`), as specified by the caller.
25 *
26 * - outputting the differences in various formats, as specified by the caller.
27 *
28 * Calling sequence
29 * ----------------
30 *
31 * - Prepare `struct diff_options` to record the set of diff options, and then
32 * call `repo_diff_setup()` to initialize this structure. This sets up the
33 * vanilla default.
34 *
35 * - Fill in the options structure to specify desired output format, rename
36 * detection, etc. `diff_opt_parse()` can be used to parse options given
37 * from the command line in a way consistent with existing git-diff family
38 * of programs.
39 *
40 * - Call `diff_setup_done()`; this inspects the options set up so far for
41 * internal consistency and make necessary tweaking to it (e.g. if textual
42 * patch output was asked, recursive behaviour is turned on); the callback
43 * set_default in diff_options can be used to tweak this more.
44 *
45 * - As you find different pairs of files, call `diff_change()` to feed
46 * modified files, `diff_addremove()` to feed created or deleted files, or
47 * `diff_unmerge()` to feed a file whose state is 'unmerged' to the API.
48 * These are thin wrappers to a lower-level `diff_queue()` function that is
49 * flexible enough to record any of these kinds of changes.
50 *
51 * - Once you finish feeding the pairs of files, call `diffcore_std()`.
52 * This will tell the diffcore library to go ahead and do its work.
53 *
54 * - Calling `diff_flush()` will produce the output, it will call
55 * `diff_free()` to free any resources, e.g. those allocated in
56 * `diff_opt_parse()`.
57 *
58 * - Set `.no_free = 1` before calling `diff_flush()` to defer the
59 * freeing of allocated memory in diff_options. This is useful when
60 * `diff_flush()` is being called in a loop, rather than as a
61 * one-off. When setting `.no_free = 1` you must ensure that
62 * `diff_free()` is called at the end, either by flipping the flag
63 * before the last `diff_flush()` call, or by flipping it before
64 * calling `diff_free()` yourself.
65 */
66
67 struct combine_diff_path;
68 struct commit;
69 struct diff_filespec;
70 struct diff_options;
71 struct diff_queue_struct;
72 struct oid_array;
73 struct option;
74 struct repository;
75 struct rev_info;
76 struct userdiff_driver;
77
78 typedef int (*pathchange_fn_t)(struct diff_options *options,
79 struct combine_diff_path *path);
80
81 typedef void (*change_fn_t)(struct diff_options *options,
82 unsigned old_mode, unsigned new_mode,
83 const struct object_id *old_oid,
84 const struct object_id *new_oid,
85 int old_oid_valid, int new_oid_valid,
86 const char *fullpath,
87 unsigned old_dirty_submodule, unsigned new_dirty_submodule);
88
89 typedef void (*add_remove_fn_t)(struct diff_options *options,
90 int addremove, unsigned mode,
91 const struct object_id *oid,
92 int oid_valid,
93 const char *fullpath, unsigned dirty_submodule);
94
95 typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
96 struct diff_options *options, void *data);
97
98 typedef const char *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
99
100 #define DIFF_FORMAT_RAW 0x0001
101 #define DIFF_FORMAT_DIFFSTAT 0x0002
102 #define DIFF_FORMAT_NUMSTAT 0x0004
103 #define DIFF_FORMAT_SUMMARY 0x0008
104 #define DIFF_FORMAT_PATCH 0x0010
105 #define DIFF_FORMAT_SHORTSTAT 0x0020
106 #define DIFF_FORMAT_DIRSTAT 0x0040
107
108 /* These override all above */
109 #define DIFF_FORMAT_NAME 0x0100
110 #define DIFF_FORMAT_NAME_STATUS 0x0200
111 #define DIFF_FORMAT_CHECKDIFF 0x0400
112
113 /* Same as output_format = 0 but we know that -s flag was given
114 * and we should not give default value to output_format.
115 */
116 #define DIFF_FORMAT_NO_OUTPUT 0x0800
117
118 #define DIFF_FORMAT_CALLBACK 0x1000
119
120 #define DIFF_FLAGS_INIT { 0 }
121 struct diff_flags {
122
123 /**
124 * Tells if tree traversal done by tree-diff should recursively descend
125 * into a tree object pair that are different in preimage and postimage set.
126 */
127 unsigned recursive;
128 unsigned tree_in_recursive;
129
130 /*
131 * Historically diff_tree_combined() overrides recursive to 1. To
132 * suppress this behavior, set the flag below.
133 * It has no effect if recursive is already set to 1.
134 */
135 unsigned no_recursive_diff_tree_combined;
136
137 /* Affects the way how a file that is seemingly binary is treated. */
138 unsigned binary;
139 unsigned text;
140
141 /**
142 * Tells the patch output format not to use abbreviated object names on the
143 * "index" lines.
144 */
145 unsigned full_index;
146
147 /* Affects if diff-files shows removed files. */
148 unsigned silent_on_remove;
149
150 /**
151 * Tells the diffcore library that the caller is feeding unchanged
152 * filepairs to allow copies from unmodified files be detected.
153 */
154 unsigned find_copies_harder;
155
156 unsigned follow_renames;
157 unsigned rename_empty;
158
159 /* Internal; used for optimization to see if there is any change. */
160 unsigned has_changes;
161
162 unsigned quick;
163
164 /**
165 * Tells diff-files that the input is not tracked files but files in random
166 * locations on the filesystem.
167 */
168 unsigned no_index;
169
170 /**
171 * Tells output routine that it is Ok to call user specified patch output
172 * routine. Plumbing disables this to ensure stable output.
173 */
174 unsigned allow_external;
175
176 /**
177 * Allows diff.<driver>.process to be consulted. Set by the
178 * porcelain commands whose output may reflect a diff process
179 * (diff, log, show, blame) and by --ext-diff or --diff-process;
180 * plumbing does not set it by default, so its output stays
181 * builtin. Cleared by --no-ext-diff or --no-diff-process.
182 */
183 unsigned allow_diff_process;
184
185 /**
186 * For communication between the calling program and the options parser;
187 * tell the calling program to signal the presence of difference using
188 * program exit code.
189 */
190 unsigned exit_with_status;
191
192 /**
193 * Tells the library that the calling program is feeding the filepairs
194 * reversed; `one` is two, and `two` is one.
195 */
196 unsigned reverse_diff;
197
198 unsigned check_failed;
199 unsigned relative_name;
200 unsigned ignore_submodules;
201 unsigned dirstat_cumulative;
202 unsigned dirstat_by_file;
203 unsigned allow_textconv;
204 unsigned textconv_set_via_cmdline;
205 unsigned diff_from_contents;
206 unsigned dirty_submodules;
207 unsigned ignore_untracked_in_submodules;
208 unsigned ignore_submodule_set;
209 unsigned ignore_dirty_submodules;
210 unsigned override_submodule_config;
211 unsigned dirstat_by_line;
212 unsigned funccontext;
213 unsigned default_follow_renames;
214 unsigned stat_with_summary;
215 unsigned suppress_diff_headers;
216 unsigned dual_color_diffed_diffs;
217 unsigned suppress_hunk_header_line_count;
218
219 /*
220 * Do not serve the diffstat from the precomputed-hunks store.
221 * Set by format-patch so a generated patch carries the builtin
222 * counts and does not depend on the sender's local store state.
223 */
224 unsigned no_precomputed_hunks;
225 };
226
227 static inline void diff_flags_or(struct diff_flags *a,
228 const struct diff_flags *b)
229 {
230 char *tmp_a = (char *)a;
231 const char *tmp_b = (const char *)b;
232
233 for (size_t i = 0; i < sizeof(struct diff_flags); i++)
234 tmp_a[i] |= tmp_b[i];
235 }
236
237 #define DIFF_XDL_TST(opts, flag) ((opts)->xdl_opts & XDF_##flag)
238 #define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag)
239 #define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag)
240
241 #define DIFF_WITH_ALG(opts, flag) (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag)
242
243 /*
244 * The xdl_opts bits git turns on by default that a from-scratch xdl_opts
245 * (git blame's own option parsing) does not set, and so must OR in to match
246 * a store warmed at the default diff settings; a diff_options-based consumer
247 * (diffstat) already has them in o->xdl_opts. Today this is only the indent
248 * heuristic. It does NOT cover a non-default diff.algorithm: a repo that
249 * configures one records under that algorithm, and a consumer keying without
250 * it misses (a lost hit, not wrong output).
251 */
252 #define DIFF_HUNKS_DEFAULT_XDL_OPTS XDF_INDENT_HEURISTIC
253
254 enum diff_words_type {
255 DIFF_WORDS_NONE = 0,
256 DIFF_WORDS_PORCELAIN,
257 DIFF_WORDS_PLAIN,
258 DIFF_WORDS_COLOR
259 };
260
261 enum diff_submodule_format {
262 DIFF_SUBMODULE_SHORT = 0,
263 DIFF_SUBMODULE_LOG,
264 DIFF_SUBMODULE_INLINE_DIFF
265 };
266
267 /**
268 * the set of options the calling program wants to affect the operation of
269 * diffcore library with.
270 */
271 struct diff_options {
272 char *orderfile;
273
274 /*
275 * "--rotate-to=<file>" would start showing at <file> and when
276 * the output reaches the end, wrap around by default.
277 * Setting skip_instead_of_rotate to true stops the output at the
278 * end, effectively discarding the earlier part of the output
279 * before <file>'s diff (this is used to implement the
280 * "--skip-to=<file>" option).
281 *
282 * When rotate_to_strict is set, it is an error if there is no
283 * <file> in the diff. Otherwise, the output starts at the
284 * path that is the same as, or first path that sorts after,
285 * <file>. Because it is unreasonable to require the exact
286 * match for "git log -p --rotate-to=<file>" (i.e. not all
287 * commit would touch that single <file>), "git log" sets it
288 * to false. "git diff" sets it to true to detect an error
289 * in the command line option.
290 */
291 const char *rotate_to;
292 int skip_instead_of_rotate;
293 int rotate_to_strict;
294
295 /**
296 * A constant string (can and typically does contain newlines to look for
297 * a block of text, not just a single line) to filter out the filepairs
298 * that do not change the number of strings contained in its preimage and
299 * postimage of the diff_queue.
300 */
301 const char *pickaxe;
302 unsigned pickaxe_opts;
303
304 /* -I<regex> */
305 regex_t **ignore_regex;
306 size_t ignore_regex_nr, ignore_regex_alloc;
307
308 const char *single_follow;
309 const char *a_prefix, *b_prefix;
310 const char *line_prefix;
311
312 /**
313 * collection of boolean options that affects the operation, but some do
314 * not have anything to do with the diffcore library.
315 */
316 struct diff_flags flags;
317
318 /* diff-filter bits */
319 unsigned int filter, filter_not;
320
321 enum git_colorbool use_color;
322
323 /* Number of context lines to generate in patch output. */
324 unsigned int context;
325
326 unsigned int interhunkcontext;
327
328 /* Affects the way detection logic for complete rewrites, renames and
329 * copies.
330 */
331 int break_opt;
332 int detect_rename;
333
334 int irreversible_delete;
335 int skip_stat_unmatch;
336 int line_termination;
337
338 /* The output format used when `diff_flush()` is run. */
339 int output_format;
340
341 /* Affects the way detection logic for complete rewrites, renames and
342 * copies.
343 */
344 int rename_score;
345 int rename_limit;
346
347 int needed_rename_limit;
348 int degraded_cc_to_c;
349 int show_rename_progress;
350 int dirstat_permille;
351 int setup;
352
353 /* Number of hexdigits to abbreviate raw format output to. */
354 int abbrev;
355
356 /* If non-zero, then stop computing after this many changes. */
357 int max_changes;
358
359 int ita_invisible_in_index;
360 /* white-space error highlighting */
361 #define WSEH_NEW (1<<16)
362 #define WSEH_CONTEXT (1<<17)
363 #define WSEH_OLD (1<<18)
364 unsigned ws_error_highlight;
365 const char *prefix;
366 int prefix_length;
367 const char *stat_sep;
368 int xdl_opts;
369 int ignore_driver_algorithm;
370
371 /* see Documentation/diff-options.adoc */
372 char **anchors;
373 size_t anchors_nr, anchors_alloc;
374
375 int stat_width;
376 int stat_name_width;
377 int stat_graph_width;
378 int stat_count;
379 const char *word_regex;
380 enum diff_words_type word_diff;
381 enum diff_submodule_format submodule_format;
382
383 struct oidset *objfind;
384
385 /* this is set by diffcore for DIFF_FORMAT_PATCH */
386 int found_changes;
387
388 /* to support internal diff recursion by --follow hack*/
389 int found_follow;
390
391 /*
392 * By default, diffcore_std() resolves the statuses for queued diff file
393 * pairs by calling diff_resolve_rename_copy(). If status information
394 * has already been manually set, this option prevents diffcore_std()
395 * from resetting statuses.
396 */
397 int skip_resolving_statuses;
398
399 /* Callback which allows tweaking the options in diff_setup_done(). */
400 void (*set_default)(struct diff_options *);
401
402 FILE *file;
403 int close_file;
404
405 #define OUTPUT_INDICATOR_NEW 0
406 #define OUTPUT_INDICATOR_OLD 1
407 #define OUTPUT_INDICATOR_CONTEXT 2
408 char output_indicators[3];
409
410 struct pathspec pathspec;
411 pathchange_fn_t pathchange;
412 change_fn_t change;
413 add_remove_fn_t add_remove;
414 void *change_fn_data;
415 diff_format_fn_t format_callback;
416 void *format_callback_data;
417 diff_prefix_fn_t output_prefix;
418 void *output_prefix_data;
419
420 int diff_path_counter;
421
422 struct emitted_diff_symbols *emitted_symbols;
423 enum {
424 COLOR_MOVED_NO = 0,
425 COLOR_MOVED_PLAIN = 1,
426 COLOR_MOVED_BLOCKS = 2,
427 COLOR_MOVED_ZEBRA = 3,
428 COLOR_MOVED_ZEBRA_DIM = 4,
429 } color_moved;
430 #define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
431 #define COLOR_MOVED_MIN_ALNUM_COUNT 20
432
433 /* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
434 #define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
435 #define COLOR_MOVED_WS_ERROR (1<<0)
436 unsigned color_moved_ws_handling;
437
438 struct repository *repo;
439 struct strmap *additional_path_headers;
440
441 int no_free;
442
443 /*
444 * The value '0' is a valid max-depth (for no recursion), and value '-1'
445 * also (for unlimited recursion), so the extra "valid" flag is used to
446 * determined whether the user specified option --max-depth.
447 */
448 int max_depth;
449 int max_depth_valid;
450
451 /*
452 * Precomputed diff hunks (see diff-hunks.h). diffstat consults the
453 * hunk provider interface before running xdiff, keyed by each file
454 * pair's blob object IDs. When hunks_writer is set (a warming run),
455 * diffstat also records the hunks it computes; the writer is
456 * attached only for the stat output formats.
457 */
458 struct diff_hunks_writer *hunks_writer;
459 };
460
461 unsigned diff_filter_bit(char status);
462
463 void diff_emit_submodule_del(struct diff_options *o, const char *line);
464 void diff_emit_submodule_add(struct diff_options *o, const char *line);
465 void diff_emit_submodule_untracked(struct diff_options *o, const char *path);
466 void diff_emit_submodule_modified(struct diff_options *o, const char *path);
467 void diff_emit_submodule_header(struct diff_options *o, const char *header);
468 void diff_emit_submodule_error(struct diff_options *o, const char *err);
469 void diff_emit_submodule_pipethrough(struct diff_options *o,
470 const char *line, int len);
471
472 struct diffstat_t {
473 int nr;
474 int alloc;
475 struct diffstat_file {
476 char *from_name;
477 char *name;
478 char *print_name;
479 const char *comments;
480 unsigned is_unmerged:1;
481 unsigned is_binary:1;
482 unsigned is_renamed:1;
483 unsigned is_interesting:1;
484 uintmax_t added, deleted;
485 } **files;
486 };
487
488 enum color_diff {
489 DIFF_RESET = 0,
490 DIFF_CONTEXT = 1,
491 DIFF_METAINFO = 2,
492 DIFF_FRAGINFO = 3,
493 DIFF_FILE_OLD = 4,
494 DIFF_FILE_NEW = 5,
495 DIFF_COMMIT = 6,
496 DIFF_WHITESPACE = 7,
497 DIFF_FUNCINFO = 8,
498 DIFF_FILE_OLD_MOVED = 9,
499 DIFF_FILE_OLD_MOVED_ALT = 10,
500 DIFF_FILE_OLD_MOVED_DIM = 11,
501 DIFF_FILE_OLD_MOVED_ALT_DIM = 12,
502 DIFF_FILE_NEW_MOVED = 13,
503 DIFF_FILE_NEW_MOVED_ALT = 14,
504 DIFF_FILE_NEW_MOVED_DIM = 15,
505 DIFF_FILE_NEW_MOVED_ALT_DIM = 16,
506 DIFF_CONTEXT_DIM = 17,
507 DIFF_FILE_OLD_DIM = 18,
508 DIFF_FILE_NEW_DIM = 19,
509 DIFF_CONTEXT_BOLD = 20,
510 DIFF_FILE_OLD_BOLD = 21,
511 DIFF_FILE_NEW_BOLD = 22,
512 };
513
514 const char *diff_get_color(enum git_colorbool diff_use_color, enum color_diff ix);
515 #define diff_get_color_opt(o, ix) \
516 diff_get_color((o)->use_color, ix)
517
518
519 const char *diff_line_prefix(struct diff_options *);
520
521
522 extern const char mime_boundary_leader[];
523
524 struct combine_diff_path *diff_tree_paths(
525 const struct object_id *oid,
526 const struct object_id **parents_oid, int nparent,
527 struct strbuf *base, struct diff_options *opt);
528 void diff_tree_oid(const struct object_id *old_oid,
529 const struct object_id *new_oid,
530 const char *base, struct diff_options *opt);
531 void diff_root_tree_oid(const struct object_id *new_oid, const char *base,
532 struct diff_options *opt);
533
534 struct combine_diff_path {
535 struct combine_diff_path *next;
536 char *path;
537 unsigned int mode;
538 struct object_id oid;
539 struct combine_diff_parent {
540 char status;
541 unsigned int mode;
542 struct object_id oid;
543 /*
544 * This per-parent path is filled only when doing a combined
545 * diff with revs.combined_all_paths set, and only if the path
546 * differs from the post-image (e.g., a rename or copy).
547 * Otherwise it is left NULL.
548 */
549 char *path;
550 } parent[FLEX_ARRAY];
551 };
552 struct combine_diff_path *combine_diff_path_new(const char *path,
553 size_t path_len,
554 unsigned int mode,
555 const struct object_id *oid,
556 size_t num_parents);
557
558 void show_combined_diff(struct combine_diff_path *elem, int num_parent,
559 struct rev_info *);
560
561 void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, struct rev_info *rev);
562
563 void diff_tree_combined_merge(const struct commit *commit, struct rev_info *rev);
564
565 void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
566 void diff_set_noprefix(struct diff_options *options);
567 void diff_set_default_prefix(struct diff_options *options);
568
569 int diff_can_quit_early(struct diff_options *);
570
571 /*
572 * Stages changes in the provided diff queue for file additions and deletions.
573 * If a file pair gets queued, it is returned.
574 */
575 struct diff_filepair *diff_queue_addremove(struct diff_queue_struct *queue,
576 struct diff_options *,
577 int addremove, unsigned mode,
578 const struct object_id *oid,
579 int oid_valid, const char *fullpath,
580 unsigned dirty_submodule);
581
582 /*
583 * Stages changes in the provided diff queue for file modifications.
584 * If a file pair gets queued, it is returned.
585 */
586 struct diff_filepair *diff_queue_change(struct diff_queue_struct *queue,
587 struct diff_options *,
588 unsigned mode1, unsigned mode2,
589 const struct object_id *old_oid,
590 const struct object_id *new_oid,
591 int old_oid_valid, int new_oid_valid,
592 const char *fullpath,
593 unsigned dirty_submodule1,
594 unsigned dirty_submodule2);
595
596 void diff_addremove(struct diff_options *,
597 int addremove,
598 unsigned mode,
599 const struct object_id *oid,
600 int oid_valid,
601 const char *fullpath, unsigned dirty_submodule);
602
603 void diff_change(struct diff_options *,
604 unsigned mode1, unsigned mode2,
605 const struct object_id *old_oid,
606 const struct object_id *new_oid,
607 int old_oid_valid, int new_oid_valid,
608 const char *fullpath,
609 unsigned dirty_submodule1, unsigned dirty_submodule2);
610
611 void diff_same(struct diff_options *,
612 unsigned mode,
613 const struct object_id *oid,
614 const char *fullpath);
615
616 struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
617
618 void compute_diffstat(struct diff_options *options, struct diffstat_t *diffstat,
619 struct diff_queue_struct *q);
620 void free_diffstat_info(struct diffstat_t *diffstat);
621
622 #define DIFF_SETUP_REVERSE 1
623 #define DIFF_SETUP_USE_SIZE_CACHE 4
624
625 /*
626 * Poor man's alternative to parse-option, to allow both stuck form
627 * (--option=value) and separate form (--option value).
628 */
629 int parse_long_opt(const char *opt, const char **argv,
630 const char **optarg);
631
632 struct config_context;
633 int git_diff_basic_config(const char *var, const char *value,
634 const struct config_context *ctx, void *cb);
635 int git_diff_heuristic_config(const char *var, const char *value, void *cb);
636 void init_diff_ui_defaults(void);
637 int git_diff_ui_config(const char *var, const char *value,
638 const struct config_context *ctx, void *cb);
639 void repo_diff_setup(struct repository *, struct diff_options *);
640 struct option *add_diff_options(const struct option *, struct diff_options *);
641 int diff_opt_parse(struct diff_options *, const char **, int, const char *);
642 void diff_setup_done(struct diff_options *);
643
644 /*
645 * Returns true if the pathspec can work with --follow mode. If die_on_error is
646 * set, die() with a specific error message rather than returning false.
647 */
648 int diff_check_follow_pathspec(struct pathspec *ps, int die_on_error);
649
650 int git_config_rename(const char *var, const char *value);
651
652 #define DIFF_DETECT_RENAME 1
653 #define DIFF_DETECT_COPY 2
654
655 #define DIFF_PICKAXE_ALL 1
656 #define DIFF_PICKAXE_REGEX 2
657
658 #define DIFF_PICKAXE_KIND_S 4 /* traditional plumbing counter */
659 #define DIFF_PICKAXE_KIND_G 8 /* grep in the patch */
660 #define DIFF_PICKAXE_KIND_OBJFIND 16 /* specific object IDs */
661
662 #define DIFF_PICKAXE_KINDS_MASK (DIFF_PICKAXE_KIND_S | \
663 DIFF_PICKAXE_KIND_G | \
664 DIFF_PICKAXE_KIND_OBJFIND)
665 #define DIFF_PICKAXE_KINDS_G_REGEX_MASK (DIFF_PICKAXE_KIND_G | \
666 DIFF_PICKAXE_REGEX)
667 #define DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK (DIFF_PICKAXE_ALL | \
668 DIFF_PICKAXE_KIND_OBJFIND)
669
670 #define DIFF_PICKAXE_IGNORE_CASE 32
671
672 void init_diffstat_widths(struct diff_options *);
673 void diffcore_std(struct diff_options *);
674 void diffcore_fix_diff_index(void);
675
676 #define COMMON_DIFF_OPTIONS_HELP \
677 "\ncommon diff options:\n" \
678 " -z output diff-raw with lines terminated with NUL.\n" \
679 " -p output patch format.\n" \
680 " -u synonym for -p.\n" \
681 " --patch-with-raw\n" \
682 " output both a patch and the diff-raw format.\n" \
683 " --stat show diffstat instead of patch.\n" \
684 " --numstat show numeric diffstat instead of patch.\n" \
685 " --patch-with-stat\n" \
686 " output a patch and prepend its diffstat.\n" \
687 " --name-only show only names of changed files.\n" \
688 " --name-status show names and status of changed files.\n" \
689 " --full-index show full object name on index lines.\n" \
690 " --abbrev=<n> abbreviate object names in diff-tree header and diff-raw.\n" \
691 " -R swap input file pairs.\n" \
692 " -B detect complete rewrites.\n" \
693 " -M detect renames.\n" \
694 " -C detect copies.\n" \
695 " --find-copies-harder\n" \
696 " try unchanged files as candidate for copy detection.\n" \
697 " -l<n> limit rename attempts up to <n> paths.\n" \
698 " -O<file> reorder diffs according to the <file>.\n" \
699 " -S<string> find filepair whose only one side contains the string.\n" \
700 " --pickaxe-all\n" \
701 " show all files diff when -S is used and hit is found.\n" \
702 " -a --text treat all files as text.\n"
703
704 int diff_queue_is_empty(struct diff_options *o);
705 void diff_flush(struct diff_options*);
706 void diff_free(struct diff_options*);
707
708 /*
709 * Attach a diff-hunks writer to a diff producing a stat format, so a
710 * warming run records the hunks it computes; a no-op when writing is off
711 * or for other formats. (Reading is separate: consumers consult the
712 * providers through diff_provider_consult(); see diff-provider.h.) Pair
713 * with diff_hunks_detach() once the diff is done.
714 */
715 void diff_hunks_attach(struct diff_options *o);
716 void diff_hunks_detach(struct diff_options *o);
717
718 void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
719
720 /* diff-raw status letters */
721 #define DIFF_STATUS_ADDED 'A'
722 #define DIFF_STATUS_COPIED 'C'
723 #define DIFF_STATUS_DELETED 'D'
724 #define DIFF_STATUS_MODIFIED 'M'
725 #define DIFF_STATUS_RENAMED 'R'
726 #define DIFF_STATUS_TYPE_CHANGED 'T'
727 #define DIFF_STATUS_UNKNOWN 'X'
728 #define DIFF_STATUS_UNMERGED 'U'
729
730 /* these are not diff-raw status letters proper, but used by
731 * diffcore-filter insn to specify additional restrictions.
732 */
733 #define DIFF_STATUS_FILTER_AON '*'
734 #define DIFF_STATUS_FILTER_BROKEN 'B'
735
736 /*
737 * This is different from repo_find_unique_abbrev() in that
738 * it stuffs the result with dots for alignment.
739 */
740 const char *diff_aligned_abbrev(const struct object_id *sha1, int);
741
742 void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb);
743
744 /* do not report anything on removed paths */
745 #define DIFF_SILENT_ON_REMOVED 01
746 /* report racily-clean paths as modified */
747 #define DIFF_RACY_IS_MODIFIED 02
748 void run_diff_files(struct rev_info *revs, unsigned int option);
749
750 #define DIFF_INDEX_CACHED 01
751 #define DIFF_INDEX_MERGE_BASE 02
752 void run_diff_index(struct rev_info *revs, unsigned int option);
753
754 int do_diff_cache(const struct object_id *, struct diff_options *);
755 int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
756 void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx);
757
758 int diff_result_code(struct rev_info *);
759
760 int diff_no_index(struct rev_info *, const struct git_hash_algo *algop,
761 int implicit_no_index, int, const char **);
762
763 int index_differs_from(struct repository *r, const char *def,
764 const struct diff_flags *flags,
765 int ita_invisible_in_index);
766
767 /*
768 * Emit an interdiff of two object ID's to 'diff_options.file' optionally
769 * indented by 'indent' spaces.
770 */
771 void show_interdiff(const struct object_id *, const struct object_id *,
772 int indent, struct diff_options *);
773
774 /*
775 * Fill the contents of the filespec "df", respecting any textconv defined by
776 * its userdiff driver. The "driver" parameter must come from a
777 * previous call to get_textconv(), and therefore should either be NULL or have
778 * textconv enabled.
779 *
780 * Note that the memory ownership of the resulting buffer depends on whether
781 * the driver field is NULL. If it is, then the memory belongs to the filespec
782 * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
783 * that should be freed by the caller.
784 */
785 size_t fill_textconv(struct repository *r,
786 struct userdiff_driver *driver,
787 struct diff_filespec *df,
788 char **outbuf);
789
790 /*
791 * Look up the userdiff driver for the given filespec, and return it if
792 * and only if it has textconv enabled (otherwise return NULL). The result
793 * can be passed to fill_textconv().
794 */
795 struct userdiff_driver *get_textconv(struct repository *r,
796 struct diff_filespec *one);
797
798 /*
799 * Prepare diff_filespec and convert it using diff textconv API
800 * if the textconv driver exists.
801 * Return 1 if the conversion succeeds, 0 otherwise.
802 */
803 int textconv_object(struct repository *repo,
804 const char *path,
805 unsigned mode,
806 const struct object_id *oid, int oid_valid,
807 char **buf, unsigned long *buf_size);
808
809 int parse_rename_score(const char **cp_p);
810
811 long parse_algorithm_value(const char *value);
812
813 void print_stat_summary(FILE *fp, int files,
814 int insertions, int deletions);
815 void setup_diff_pager(struct diff_options *);
816
817 extern int diff_auto_refresh_index;
818
819 #endif /* DIFF_H */