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 * For communication between the calling program and the options parser;
178 * tell the calling program to signal the presence of difference using
179 * program exit code.
180 */
181 unsigned exit_with_status;
182
183 /**
184 * Tells the library that the calling program is feeding the filepairs
185 * reversed; `one` is two, and `two` is one.
186 */
187 unsigned reverse_diff;
188
189 unsigned check_failed;
190 unsigned relative_name;
191 unsigned ignore_submodules;
192 unsigned dirstat_cumulative;
193 unsigned dirstat_by_file;
194 unsigned allow_textconv;
195 unsigned textconv_set_via_cmdline;
196 unsigned diff_from_contents;
197 unsigned dirty_submodules;
198 unsigned ignore_untracked_in_submodules;
199 unsigned ignore_submodule_set;
200 unsigned ignore_dirty_submodules;
201 unsigned override_submodule_config;
202 unsigned dirstat_by_line;
203 unsigned funccontext;
204 unsigned default_follow_renames;
205 unsigned stat_with_summary;
206 unsigned suppress_diff_headers;
207 unsigned dual_color_diffed_diffs;
208 unsigned suppress_hunk_header_line_count;
209 };
210
211 static inline void diff_flags_or(struct diff_flags *a,
212 const struct diff_flags *b)
213 {
214 char *tmp_a = (char *)a;
215 const char *tmp_b = (const char *)b;
216
217 for (size_t i = 0; i < sizeof(struct diff_flags); i++)
218 tmp_a[i] |= tmp_b[i];
219 }
220
221 #define DIFF_XDL_TST(opts, flag) ((opts)->xdl_opts & XDF_##flag)
222 #define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag)
223 #define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag)
224
225 #define DIFF_WITH_ALG(opts, flag) (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag)
226
227 enum diff_words_type {
228 DIFF_WORDS_NONE = 0,
229 DIFF_WORDS_PORCELAIN,
230 DIFF_WORDS_PLAIN,
231 DIFF_WORDS_COLOR
232 };
233
234 enum diff_submodule_format {
235 DIFF_SUBMODULE_SHORT = 0,
236 DIFF_SUBMODULE_LOG,
237 DIFF_SUBMODULE_INLINE_DIFF
238 };
239
240 /**
241 * the set of options the calling program wants to affect the operation of
242 * diffcore library with.
243 */
244 struct diff_options {
245 char *orderfile;
246
247 /*
248 * "--rotate-to=<file>" would start showing at <file> and when
249 * the output reaches the end, wrap around by default.
250 * Setting skip_instead_of_rotate to true stops the output at the
251 * end, effectively discarding the earlier part of the output
252 * before <file>'s diff (this is used to implement the
253 * "--skip-to=<file>" option).
254 *
255 * When rotate_to_strict is set, it is an error if there is no
256 * <file> in the diff. Otherwise, the output starts at the
257 * path that is the same as, or first path that sorts after,
258 * <file>. Because it is unreasonable to require the exact
259 * match for "git log -p --rotate-to=<file>" (i.e. not all
260 * commit would touch that single <file>), "git log" sets it
261 * to false. "git diff" sets it to true to detect an error
262 * in the command line option.
263 */
264 const char *rotate_to;
265 int skip_instead_of_rotate;
266 int rotate_to_strict;
267
268 /**
269 * A constant string (can and typically does contain newlines to look for
270 * a block of text, not just a single line) to filter out the filepairs
271 * that do not change the number of strings contained in its preimage and
272 * postimage of the diff_queue.
273 */
274 const char *pickaxe;
275 unsigned pickaxe_opts;
276
277 /* -I<regex> */
278 regex_t **ignore_regex;
279 size_t ignore_regex_nr, ignore_regex_alloc;
280
281 const char *single_follow;
282 const char *a_prefix, *b_prefix;
283 const char *line_prefix;
284
285 /**
286 * collection of boolean options that affects the operation, but some do
287 * not have anything to do with the diffcore library.
288 */
289 struct diff_flags flags;
290
291 /* diff-filter bits */
292 unsigned int filter, filter_not;
293
294 enum git_colorbool use_color;
295
296 /* Number of context lines to generate in patch output. */
297 unsigned int context;
298
299 unsigned int interhunkcontext;
300
301 /* Affects the way detection logic for complete rewrites, renames and
302 * copies.
303 */
304 int break_opt;
305 int detect_rename;
306
307 int irreversible_delete;
308 int skip_stat_unmatch;
309 int line_termination;
310
311 /* The output format used when `diff_flush()` is run. */
312 int output_format;
313
314 /* Affects the way detection logic for complete rewrites, renames and
315 * copies.
316 */
317 int rename_score;
318 int rename_limit;
319
320 int needed_rename_limit;
321 int degraded_cc_to_c;
322 int show_rename_progress;
323 int dirstat_permille;
324 int setup;
325
326 /* Number of hexdigits to abbreviate raw format output to. */
327 int abbrev;
328
329 /* If non-zero, then stop computing after this many changes. */
330 int max_changes;
331
332 int ita_invisible_in_index;
333 /* white-space error highlighting */
334 #define WSEH_NEW (1<<16)
335 #define WSEH_CONTEXT (1<<17)
336 #define WSEH_OLD (1<<18)
337 unsigned ws_error_highlight;
338 const char *prefix;
339 int prefix_length;
340 const char *stat_sep;
341 int xdl_opts;
342 int ignore_driver_algorithm;
343
344 /* see Documentation/diff-options.adoc */
345 char **anchors;
346 size_t anchors_nr, anchors_alloc;
347
348 int stat_width;
349 int stat_name_width;
350 int stat_graph_width;
351 int stat_count;
352 const char *word_regex;
353 enum diff_words_type word_diff;
354 enum diff_submodule_format submodule_format;
355
356 struct oidset *objfind;
357
358 /* this is set by diffcore for DIFF_FORMAT_PATCH */
359 int found_changes;
360
361 /* to support internal diff recursion by --follow hack*/
362 int found_follow;
363
364 /*
365 * By default, diffcore_std() resolves the statuses for queued diff file
366 * pairs by calling diff_resolve_rename_copy(). If status information
367 * has already been manually set, this option prevents diffcore_std()
368 * from resetting statuses.
369 */
370 int skip_resolving_statuses;
371
372 /* Callback which allows tweaking the options in diff_setup_done(). */
373 void (*set_default)(struct diff_options *);
374
375 FILE *file;
376 int close_file;
377
378 #define OUTPUT_INDICATOR_NEW 0
379 #define OUTPUT_INDICATOR_OLD 1
380 #define OUTPUT_INDICATOR_CONTEXT 2
381 char output_indicators[3];
382
383 struct pathspec pathspec;
384 pathchange_fn_t pathchange;
385 change_fn_t change;
386 add_remove_fn_t add_remove;
387 void *change_fn_data;
388 diff_format_fn_t format_callback;
389 void *format_callback_data;
390 diff_prefix_fn_t output_prefix;
391 void *output_prefix_data;
392
393 int diff_path_counter;
394
395 struct emitted_diff_symbols *emitted_symbols;
396 enum {
397 COLOR_MOVED_NO = 0,
398 COLOR_MOVED_PLAIN = 1,
399 COLOR_MOVED_BLOCKS = 2,
400 COLOR_MOVED_ZEBRA = 3,
401 COLOR_MOVED_ZEBRA_DIM = 4,
402 } color_moved;
403 #define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
404 #define COLOR_MOVED_MIN_ALNUM_COUNT 20
405
406 /* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
407 #define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
408 #define COLOR_MOVED_WS_ERROR (1<<0)
409 unsigned color_moved_ws_handling;
410
411 struct repository *repo;
412 struct strmap *additional_path_headers;
413
414 int no_free;
415
416 /*
417 * The value '0' is a valid max-depth (for no recursion), and value '-1'
418 * also (for unlimited recursion), so the extra "valid" flag is used to
419 * determined whether the user specified option --max-depth.
420 */
421 int max_depth;
422 int max_depth_valid;
423 };
424
425 unsigned diff_filter_bit(char status);
426
427 void diff_emit_submodule_del(struct diff_options *o, const char *line);
428 void diff_emit_submodule_add(struct diff_options *o, const char *line);
429 void diff_emit_submodule_untracked(struct diff_options *o, const char *path);
430 void diff_emit_submodule_modified(struct diff_options *o, const char *path);
431 void diff_emit_submodule_header(struct diff_options *o, const char *header);
432 void diff_emit_submodule_error(struct diff_options *o, const char *err);
433 void diff_emit_submodule_pipethrough(struct diff_options *o,
434 const char *line, int len);
435
436 struct diffstat_t {
437 int nr;
438 int alloc;
439 struct diffstat_file {
440 char *from_name;
441 char *name;
442 char *print_name;
443 const char *comments;
444 unsigned is_unmerged:1;
445 unsigned is_binary:1;
446 unsigned is_renamed:1;
447 unsigned is_interesting:1;
448 uintmax_t added, deleted;
449 } **files;
450 };
451
452 enum color_diff {
453 DIFF_RESET = 0,
454 DIFF_CONTEXT = 1,
455 DIFF_METAINFO = 2,
456 DIFF_FRAGINFO = 3,
457 DIFF_FILE_OLD = 4,
458 DIFF_FILE_NEW = 5,
459 DIFF_COMMIT = 6,
460 DIFF_WHITESPACE = 7,
461 DIFF_FUNCINFO = 8,
462 DIFF_FILE_OLD_MOVED = 9,
463 DIFF_FILE_OLD_MOVED_ALT = 10,
464 DIFF_FILE_OLD_MOVED_DIM = 11,
465 DIFF_FILE_OLD_MOVED_ALT_DIM = 12,
466 DIFF_FILE_NEW_MOVED = 13,
467 DIFF_FILE_NEW_MOVED_ALT = 14,
468 DIFF_FILE_NEW_MOVED_DIM = 15,
469 DIFF_FILE_NEW_MOVED_ALT_DIM = 16,
470 DIFF_CONTEXT_DIM = 17,
471 DIFF_FILE_OLD_DIM = 18,
472 DIFF_FILE_NEW_DIM = 19,
473 DIFF_CONTEXT_BOLD = 20,
474 DIFF_FILE_OLD_BOLD = 21,
475 DIFF_FILE_NEW_BOLD = 22,
476 };
477
478 const char *diff_get_color(enum git_colorbool diff_use_color, enum color_diff ix);
479 #define diff_get_color_opt(o, ix) \
480 diff_get_color((o)->use_color, ix)
481
482
483 const char *diff_line_prefix(struct diff_options *);
484
485
486 extern const char mime_boundary_leader[];
487
488 struct combine_diff_path *diff_tree_paths(
489 const struct object_id *oid,
490 const struct object_id **parents_oid, int nparent,
491 struct strbuf *base, struct diff_options *opt);
492 void diff_tree_oid(const struct object_id *old_oid,
493 const struct object_id *new_oid,
494 const char *base, struct diff_options *opt);
495 void diff_root_tree_oid(const struct object_id *new_oid, const char *base,
496 struct diff_options *opt);
497
498 struct combine_diff_path {
499 struct combine_diff_path *next;
500 char *path;
501 unsigned int mode;
502 struct object_id oid;
503 struct combine_diff_parent {
504 char status;
505 unsigned int mode;
506 struct object_id oid;
507 /*
508 * This per-parent path is filled only when doing a combined
509 * diff with revs.combined_all_paths set, and only if the path
510 * differs from the post-image (e.g., a rename or copy).
511 * Otherwise it is left NULL.
512 */
513 char *path;
514 } parent[FLEX_ARRAY];
515 };
516 struct combine_diff_path *combine_diff_path_new(const char *path,
517 size_t path_len,
518 unsigned int mode,
519 const struct object_id *oid,
520 size_t num_parents);
521
522 void show_combined_diff(struct combine_diff_path *elem, int num_parent,
523 struct rev_info *);
524
525 void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, struct rev_info *rev);
526
527 void diff_tree_combined_merge(const struct commit *commit, struct rev_info *rev);
528
529 void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
530 void diff_set_noprefix(struct diff_options *options);
531 void diff_set_default_prefix(struct diff_options *options);
532
533 int diff_can_quit_early(struct diff_options *);
534
535 /*
536 * Stages changes in the provided diff queue for file additions and deletions.
537 * If a file pair gets queued, it is returned.
538 */
539 struct diff_filepair *diff_queue_addremove(struct diff_queue_struct *queue,
540 struct diff_options *,
541 int addremove, unsigned mode,
542 const struct object_id *oid,
543 int oid_valid, const char *fullpath,
544 unsigned dirty_submodule);
545
546 /*
547 * Stages changes in the provided diff queue for file modifications.
548 * If a file pair gets queued, it is returned.
549 */
550 struct diff_filepair *diff_queue_change(struct diff_queue_struct *queue,
551 struct diff_options *,
552 unsigned mode1, unsigned mode2,
553 const struct object_id *old_oid,
554 const struct object_id *new_oid,
555 int old_oid_valid, int new_oid_valid,
556 const char *fullpath,
557 unsigned dirty_submodule1,
558 unsigned dirty_submodule2);
559
560 void diff_addremove(struct diff_options *,
561 int addremove,
562 unsigned mode,
563 const struct object_id *oid,
564 int oid_valid,
565 const char *fullpath, unsigned dirty_submodule);
566
567 void diff_change(struct diff_options *,
568 unsigned mode1, unsigned mode2,
569 const struct object_id *old_oid,
570 const struct object_id *new_oid,
571 int old_oid_valid, int new_oid_valid,
572 const char *fullpath,
573 unsigned dirty_submodule1, unsigned dirty_submodule2);
574
575 void diff_same(struct diff_options *,
576 unsigned mode,
577 const struct object_id *oid,
578 const char *fullpath);
579
580 struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
581
582 void compute_diffstat(struct diff_options *options, struct diffstat_t *diffstat,
583 struct diff_queue_struct *q);
584 void free_diffstat_info(struct diffstat_t *diffstat);
585
586 #define DIFF_SETUP_REVERSE 1
587 #define DIFF_SETUP_USE_SIZE_CACHE 4
588
589 /*
590 * Poor man's alternative to parse-option, to allow both stuck form
591 * (--option=value) and separate form (--option value).
592 */
593 int parse_long_opt(const char *opt, const char **argv,
594 const char **optarg);
595
596 struct config_context;
597 int git_diff_basic_config(const char *var, const char *value,
598 const struct config_context *ctx, void *cb);
599 int git_diff_heuristic_config(const char *var, const char *value, void *cb);
600 void init_diff_ui_defaults(void);
601 int git_diff_ui_config(const char *var, const char *value,
602 const struct config_context *ctx, void *cb);
603 void repo_diff_setup(struct repository *, struct diff_options *);
604 struct option *add_diff_options(const struct option *, struct diff_options *);
605 int diff_opt_parse(struct diff_options *, const char **, int, const char *);
606 void diff_setup_done(struct diff_options *);
607
608 /*
609 * Returns true if the pathspec can work with --follow mode. If die_on_error is
610 * set, die() with a specific error message rather than returning false.
611 */
612 int diff_check_follow_pathspec(struct pathspec *ps, int die_on_error);
613
614 int git_config_rename(const char *var, const char *value);
615
616 #define DIFF_DETECT_RENAME 1
617 #define DIFF_DETECT_COPY 2
618
619 #define DIFF_PICKAXE_ALL 1
620 #define DIFF_PICKAXE_REGEX 2
621
622 #define DIFF_PICKAXE_KIND_S 4 /* traditional plumbing counter */
623 #define DIFF_PICKAXE_KIND_G 8 /* grep in the patch */
624 #define DIFF_PICKAXE_KIND_OBJFIND 16 /* specific object IDs */
625
626 #define DIFF_PICKAXE_KINDS_MASK (DIFF_PICKAXE_KIND_S | \
627 DIFF_PICKAXE_KIND_G | \
628 DIFF_PICKAXE_KIND_OBJFIND)
629 #define DIFF_PICKAXE_KINDS_G_REGEX_MASK (DIFF_PICKAXE_KIND_G | \
630 DIFF_PICKAXE_REGEX)
631 #define DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK (DIFF_PICKAXE_ALL | \
632 DIFF_PICKAXE_KIND_OBJFIND)
633
634 #define DIFF_PICKAXE_IGNORE_CASE 32
635
636 void init_diffstat_widths(struct diff_options *);
637 void diffcore_std(struct diff_options *);
638 void diffcore_fix_diff_index(void);
639
640 #define COMMON_DIFF_OPTIONS_HELP \
641 "\ncommon diff options:\n" \
642 " -z output diff-raw with lines terminated with NUL.\n" \
643 " -p output patch format.\n" \
644 " -u synonym for -p.\n" \
645 " --patch-with-raw\n" \
646 " output both a patch and the diff-raw format.\n" \
647 " --stat show diffstat instead of patch.\n" \
648 " --numstat show numeric diffstat instead of patch.\n" \
649 " --patch-with-stat\n" \
650 " output a patch and prepend its diffstat.\n" \
651 " --name-only show only names of changed files.\n" \
652 " --name-status show names and status of changed files.\n" \
653 " --full-index show full object name on index lines.\n" \
654 " --abbrev=<n> abbreviate object names in diff-tree header and diff-raw.\n" \
655 " -R swap input file pairs.\n" \
656 " -B detect complete rewrites.\n" \
657 " -M detect renames.\n" \
658 " -C detect copies.\n" \
659 " --find-copies-harder\n" \
660 " try unchanged files as candidate for copy detection.\n" \
661 " -l<n> limit rename attempts up to <n> paths.\n" \
662 " -O<file> reorder diffs according to the <file>.\n" \
663 " -S<string> find filepair whose only one side contains the string.\n" \
664 " --pickaxe-all\n" \
665 " show all files diff when -S is used and hit is found.\n" \
666 " -a --text treat all files as text.\n"
667
668 int diff_queue_is_empty(struct diff_options *o);
669 void diff_flush(struct diff_options*);
670 void diff_free(struct diff_options*);
671 void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
672
673 /* diff-raw status letters */
674 #define DIFF_STATUS_ADDED 'A'
675 #define DIFF_STATUS_COPIED 'C'
676 #define DIFF_STATUS_DELETED 'D'
677 #define DIFF_STATUS_MODIFIED 'M'
678 #define DIFF_STATUS_RENAMED 'R'
679 #define DIFF_STATUS_TYPE_CHANGED 'T'
680 #define DIFF_STATUS_UNKNOWN 'X'
681 #define DIFF_STATUS_UNMERGED 'U'
682
683 /* these are not diff-raw status letters proper, but used by
684 * diffcore-filter insn to specify additional restrictions.
685 */
686 #define DIFF_STATUS_FILTER_AON '*'
687 #define DIFF_STATUS_FILTER_BROKEN 'B'
688
689 /*
690 * This is different from repo_find_unique_abbrev() in that
691 * it stuffs the result with dots for alignment.
692 */
693 const char *diff_aligned_abbrev(const struct object_id *sha1, int);
694
695 void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb);
696
697 /* do not report anything on removed paths */
698 #define DIFF_SILENT_ON_REMOVED 01
699 /* report racily-clean paths as modified */
700 #define DIFF_RACY_IS_MODIFIED 02
701 void run_diff_files(struct rev_info *revs, unsigned int option);
702
703 #define DIFF_INDEX_CACHED 01
704 #define DIFF_INDEX_MERGE_BASE 02
705 void run_diff_index(struct rev_info *revs, unsigned int option);
706
707 int do_diff_cache(const struct object_id *, struct diff_options *);
708 int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
709 void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx);
710
711 int diff_result_code(struct rev_info *);
712
713 int diff_no_index(struct rev_info *, const struct git_hash_algo *algop,
714 int implicit_no_index, int, const char **);
715
716 int index_differs_from(struct repository *r, const char *def,
717 const struct diff_flags *flags,
718 int ita_invisible_in_index);
719
720 /*
721 * Emit an interdiff of two object ID's to 'diff_options.file' optionally
722 * indented by 'indent' spaces.
723 */
724 void show_interdiff(const struct object_id *, const struct object_id *,
725 int indent, struct diff_options *);
726
727 /*
728 * Fill the contents of the filespec "df", respecting any textconv defined by
729 * its userdiff driver. The "driver" parameter must come from a
730 * previous call to get_textconv(), and therefore should either be NULL or have
731 * textconv enabled.
732 *
733 * Note that the memory ownership of the resulting buffer depends on whether
734 * the driver field is NULL. If it is, then the memory belongs to the filespec
735 * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
736 * that should be freed by the caller.
737 */
738 size_t fill_textconv(struct repository *r,
739 struct userdiff_driver *driver,
740 struct diff_filespec *df,
741 char **outbuf);
742
743 /*
744 * Look up the userdiff driver for the given filespec, and return it if
745 * and only if it has textconv enabled (otherwise return NULL). The result
746 * can be passed to fill_textconv().
747 */
748 struct userdiff_driver *get_textconv(struct repository *r,
749 struct diff_filespec *one);
750
751 /*
752 * Prepare diff_filespec and convert it using diff textconv API
753 * if the textconv driver exists.
754 * Return 1 if the conversion succeeds, 0 otherwise.
755 */
756 int textconv_object(struct repository *repo,
757 const char *path,
758 unsigned mode,
759 const struct object_id *oid, int oid_valid,
760 char **buf, unsigned long *buf_size);
761
762 int parse_rename_score(const char **cp_p);
763
764 long parse_algorithm_value(const char *value);
765
766 void print_stat_summary(FILE *fp, int files,
767 int insertions, int deletions);
768 void setup_diff_pager(struct diff_options *);
769
770 extern int diff_auto_refresh_index;
771
772 #endif /* DIFF_H */