blob: 6703a4fb4f0302f4adf1065e91cd1bb27e5c973a [file] [log] [blame]
Junio C Hamanobe3cfa82005-04-26 09:25:05 -07001/*
2 * Copyright (C) 2005 Junio C Hamano
3 */
Junio C Hamano86436c22005-04-25 18:22:47 -07004#ifndef DIFF_H
5#define DIFF_H
6
Junio C Hamano1b0c7172006-03-29 22:55:43 -08007#include "tree-walk.h"
Linus Torvalds50f9a852006-01-31 14:10:56 -08008
Linus Torvalds91539832006-04-17 11:59:32 -07009struct rev_info;
Linus Torvaldsac1b3d12005-10-20 21:05:05 -070010struct diff_options;
Jeff King04245582006-09-07 02:35:42 -040011struct diff_queue_struct;
Linus Torvaldsac1b3d12005-10-20 21:05:05 -070012
13typedef 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,
Dmitry Potapovfd55a192008-07-16 18:54:02 +040017 const char *fullpath);
Linus Torvaldsac1b3d12005-10-20 21:05:05 -070018
19typedef void (*add_remove_fn_t)(struct diff_options *options,
20 int addremove, unsigned mode,
21 const unsigned char *sha1,
Dmitry Potapovfd55a192008-07-16 18:54:02 +040022 const char *fullpath);
Linus Torvaldsac1b3d12005-10-20 21:05:05 -070023
Jeff King04245582006-09-07 02:35:42 -040024typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
25 struct diff_options *options, void *data);
26
Timo Hirvonenc6744342006-06-24 20:21:53 +030027#define DIFF_FORMAT_RAW 0x0001
28#define DIFF_FORMAT_DIFFSTAT 0x0002
Junio C Hamano74e2abe2006-10-12 03:01:00 -070029#define DIFF_FORMAT_NUMSTAT 0x0004
30#define DIFF_FORMAT_SUMMARY 0x0008
31#define DIFF_FORMAT_PATCH 0x0010
Nicolas Pitreebd124c2006-12-14 23:15:44 -050032#define DIFF_FORMAT_SHORTSTAT 0x0020
Linus Torvalds7df7c012008-02-12 13:26:31 -080033#define DIFF_FORMAT_DIRSTAT 0x0040
Timo Hirvonenc6744342006-06-24 20:21:53 +030034
35/* These override all above */
Junio C Hamano74e2abe2006-10-12 03:01:00 -070036#define DIFF_FORMAT_NAME 0x0100
37#define DIFF_FORMAT_NAME_STATUS 0x0200
38#define DIFF_FORMAT_CHECKDIFF 0x0400
Timo Hirvonenc6744342006-06-24 20:21:53 +030039
40/* Same as output_format = 0 but we know that -s flag was given
41 * and we should not give default value to output_format.
42 */
Junio C Hamano74e2abe2006-10-12 03:01:00 -070043#define DIFF_FORMAT_NO_OUTPUT 0x0800
Timo Hirvonenc6744342006-06-24 20:21:53 +030044
Junio C Hamano74e2abe2006-10-12 03:01:00 -070045#define DIFF_FORMAT_CALLBACK 0x1000
Jeff King04245582006-09-07 02:35:42 -040046
Pierre Habouzit8f67f8a2007-11-10 20:05:14 +010047#define DIFF_OPT_RECURSIVE (1 << 0)
48#define DIFF_OPT_TREE_IN_RECURSIVE (1 << 1)
49#define DIFF_OPT_BINARY (1 << 2)
50#define DIFF_OPT_TEXT (1 << 3)
51#define DIFF_OPT_FULL_INDEX (1 << 4)
52#define DIFF_OPT_SILENT_ON_REMOVE (1 << 5)
53#define DIFF_OPT_FIND_COPIES_HARDER (1 << 6)
54#define DIFF_OPT_FOLLOW_RENAMES (1 << 7)
55#define DIFF_OPT_COLOR_DIFF (1 << 8)
56#define DIFF_OPT_COLOR_DIFF_WORDS (1 << 9)
57#define DIFF_OPT_HAS_CHANGES (1 << 10)
58#define DIFF_OPT_QUIET (1 << 11)
59#define DIFF_OPT_NO_INDEX (1 << 12)
60#define DIFF_OPT_ALLOW_EXTERNAL (1 << 13)
61#define DIFF_OPT_EXIT_WITH_STATUS (1 << 14)
62#define DIFF_OPT_REVERSE_DIFF (1 << 15)
Wincent Colaiuta62c64892007-12-13 21:24:52 +010063#define DIFF_OPT_CHECK_FAILED (1 << 16)
Junio C Hamanocd676a52008-02-12 14:26:02 -080064#define DIFF_OPT_RELATIVE_NAME (1 << 17)
Johannes Schindelin50fd9bd2008-05-14 18:03:31 +010065#define DIFF_OPT_IGNORE_SUBMODULES (1 << 18)
Junio C Hamanof88d2252008-09-02 17:28:59 -070066#define DIFF_OPT_DIRSTAT_CUMULATIVE (1 << 19)
Heikki Orsilafd337772008-09-05 22:27:35 +030067#define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
Jeff Kingc7534ef2008-10-26 00:45:55 -040068#define DIFF_OPT_ALLOW_TEXTCONV (1 << 21)
Pierre Habouzit8f67f8a2007-11-10 20:05:14 +010069#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
70#define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)
71#define DIFF_OPT_CLR(opts, flag) ((opts)->flags &= ~DIFF_OPT_##flag)
72
Junio C Hamano6b5ee132005-09-21 00:00:47 -070073struct diff_options {
Junio C Hamano6b5ee132005-09-21 00:00:47 -070074 const char *filter;
75 const char *orderfile;
76 const char *pickaxe;
Junio C Hamano2f3f8b22006-11-02 00:02:11 -080077 const char *single_follow;
Johannes Schindelineab9a402007-12-18 19:32:14 +000078 const char *a_prefix, *b_prefix;
Pierre Habouzit8f67f8a2007-11-10 20:05:14 +010079 unsigned flags;
Linus Torvaldsee1e5412006-05-13 13:23:48 -070080 int context;
René Scharfe6d0e6742008-12-28 19:45:32 +010081 int interhunkcontext;
Junio C Hamano6b5ee132005-09-21 00:00:47 -070082 int break_opt;
83 int detect_rename;
Junio C Hamanofb132272007-08-03 13:33:31 -070084 int skip_stat_unmatch;
Junio C Hamano6b5ee132005-09-21 00:00:47 -070085 int line_termination;
86 int output_format;
87 int pickaxe_opts;
88 int rename_score;
Junio C Hamano8082d8d2005-09-21 00:18:27 -070089 int rename_limit;
Jeff Kingb8960bb2008-04-30 13:25:53 -040090 int warn_on_too_large_rename;
Linus Torvalds7df7c012008-02-12 13:26:31 -080091 int dirstat_percent;
Junio C Hamano6b5ee132005-09-21 00:00:47 -070092 int setup;
Junio C Hamano47dd0d52005-12-13 17:21:41 -080093 int abbrev;
Junio C Hamanocd676a52008-02-12 14:26:02 -080094 const char *prefix;
95 int prefix_length;
Johannes Schindelin698ce6f2006-05-20 15:40:29 +020096 const char *stat_sep;
Johannes Schindelin0d21efa2006-06-14 17:40:23 +020097 long xdl_opts;
Linus Torvaldsac1b3d12005-10-20 21:05:05 -070098
Junio C Hamanoa2540022006-09-26 18:53:02 -070099 int stat_width;
100 int stat_name_width;
Johannes Schindelin2b6a5412009-01-17 17:29:45 +0100101 const char *word_regex;
Junio C Hamanoa2540022006-09-26 18:53:02 -0700102
Johannes Schindelin34a5e1a2007-02-25 23:34:54 +0100103 /* this is set by diffcore for DIFF_FORMAT_PATCH */
104 int found_changes;
105
Daniel Barkalowc0c77732008-03-09 22:43:39 -0400106 FILE *file;
107 int close_file;
108
Junio C Hamanoa8baa7b2006-04-10 16:39:11 -0700109 int nr_paths;
110 const char **paths;
111 int *pathlens;
Linus Torvaldsac1b3d12005-10-20 21:05:05 -0700112 change_fn_t change;
113 add_remove_fn_t add_remove;
Jeff King04245582006-09-07 02:35:42 -0400114 diff_format_fn_t format_callback;
115 void *format_callback_data;
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700116};
117
Jeff Kingce436972006-07-23 05:24:18 -0400118enum color_diff {
119 DIFF_RESET = 0,
120 DIFF_PLAIN = 1,
121 DIFF_METAINFO = 2,
122 DIFF_FRAGINFO = 3,
123 DIFF_FILE_OLD = 4,
124 DIFF_FILE_NEW = 5,
125 DIFF_COMMIT = 6,
Junio C Hamano448c3ef2006-09-22 22:48:39 -0700126 DIFF_WHITESPACE = 7,
Jeff Kingce436972006-07-23 05:24:18 -0400127};
128const char *diff_get_color(int diff_use_color, enum color_diff ix);
Pierre Habouzit8f67f8a2007-11-10 20:05:14 +0100129#define diff_get_color_opt(o, ix) \
130 diff_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
131
Jeff Kingce436972006-07-23 05:24:18 -0400132
Johannes Schindelin698ce6f2006-05-20 15:40:29 +0200133extern const char mime_boundary_leader[];
134
Junio C Hamanoa8baa7b2006-04-10 16:39:11 -0700135extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
136extern void diff_tree_release_paths(struct diff_options *);
Linus Torvaldsac1b3d12005-10-20 21:05:05 -0700137extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
138 const char *base, struct diff_options *opt);
139extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
140 const char *base, struct diff_options *opt);
Rene Scharfe2b603562006-10-26 18:52:39 +0200141extern int diff_root_tree_sha1(const unsigned char *new, const char *base,
142 struct diff_options *opt);
Linus Torvaldsac1b3d12005-10-20 21:05:05 -0700143
Junio C Hamanoea726d02006-01-28 00:03:38 -0800144struct combine_diff_path {
145 struct combine_diff_path *next;
146 int len;
147 char *path;
Junio C Hamano2454c962006-02-06 12:53:07 -0800148 unsigned int mode;
Junio C Hamanoea726d02006-01-28 00:03:38 -0800149 unsigned char sha1[20];
Junio C Hamano2454c962006-02-06 12:53:07 -0800150 struct combine_diff_parent {
Junio C Hamanod416df82006-02-10 02:30:52 -0800151 char status;
Junio C Hamano2454c962006-02-06 12:53:07 -0800152 unsigned int mode;
153 unsigned char sha1[20];
154 } parent[FLEX_ARRAY];
Junio C Hamanoea726d02006-01-28 00:03:38 -0800155};
Junio C Hamano2454c962006-02-06 12:53:07 -0800156#define combine_diff_path_size(n, l) \
157 (sizeof(struct combine_diff_path) + \
158 sizeof(struct combine_diff_parent) * (n) + (l) + 1)
Junio C Hamanoea726d02006-01-28 00:03:38 -0800159
Linus Torvalds91539832006-04-17 11:59:32 -0700160extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
161 int dense, struct rev_info *);
Junio C Hamanoea726d02006-01-28 00:03:38 -0800162
Junio C Hamano0fe7c1d2006-04-29 01:24:49 -0700163extern void diff_tree_combined(const unsigned char *sha1, const unsigned char parent[][20], int num_parent, int dense, struct rev_info *rev);
164
Linus Torvalds91539832006-04-17 11:59:32 -0700165extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *);
Junio C Hamanoaf3feef2006-01-24 01:22:04 -0800166
Junio C Hamanoa5a818e2008-08-18 20:08:09 -0700167void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
168
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700169extern void diff_addremove(struct diff_options *,
170 int addremove,
Junio C Hamano77eb2722005-04-27 09:21:00 -0700171 unsigned mode,
172 const unsigned char *sha1,
Dmitry Potapovfd55a192008-07-16 18:54:02 +0400173 const char *fullpath);
Junio C Hamano77eb2722005-04-27 09:21:00 -0700174
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700175extern void diff_change(struct diff_options *,
176 unsigned mode1, unsigned mode2,
177 const unsigned char *sha1,
178 const unsigned char *sha2,
Dmitry Potapovfd55a192008-07-16 18:54:02 +0400179 const char *fullpath);
Junio C Hamano77eb2722005-04-27 09:21:00 -0700180
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700181extern void diff_unmerge(struct diff_options *,
Junio C Hamanoe9c84092007-01-05 01:25:18 -0800182 const char *path,
183 unsigned mode,
184 const unsigned char *sha1);
Junio C Hamano77eb2722005-04-27 09:21:00 -0700185
Junio C Hamano19feebc2005-05-27 15:54:37 -0700186#define DIFF_SETUP_REVERSE 1
Junio C Hamanof0c6b2a2005-05-27 15:56:38 -0700187#define DIFF_SETUP_USE_CACHE 2
188#define DIFF_SETUP_USE_SIZE_CACHE 4
Junio C Hamanoce240672005-06-03 01:36:43 -0700189
Johannes Schindelinef90d6d2008-05-14 18:46:53 +0100190extern int git_diff_basic_config(const char *var, const char *value, void *cb);
191extern int git_diff_ui_config(const char *var, const char *value, void *cb);
Matthias Kestenholz6b2f2d92008-02-18 08:26:03 +0100192extern int diff_use_color_default;
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700193extern void diff_setup(struct diff_options *);
194extern int diff_opt_parse(struct diff_options *, const char **, int);
195extern int diff_setup_done(struct diff_options *);
Junio C Hamano86436c22005-04-25 18:22:47 -0700196
Junio C Hamano6b14d7f2005-05-22 10:04:37 -0700197#define DIFF_DETECT_RENAME 1
198#define DIFF_DETECT_COPY 2
199
Junio C Hamano367cec12005-05-27 15:55:28 -0700200#define DIFF_PICKAXE_ALL 1
Petr Baudisd01d8c62006-03-29 02:16:33 +0200201#define DIFF_PICKAXE_REGEX 2
Junio C Hamanof345b0a2005-05-30 00:08:37 -0700202
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700203extern void diffcore_std(struct diff_options *);
Junio C Hamanof2ce9fd2005-06-11 20:57:13 -0700204
Junio C Hamanodda2d792005-07-13 12:52:35 -0700205#define COMMON_DIFF_OPTIONS_HELP \
206"\ncommon diff options:\n" \
Junio C Hamano8082d8d2005-09-21 00:18:27 -0700207" -z output diff-raw with lines terminated with NUL.\n" \
208" -p output patch format.\n" \
209" -u synonym for -p.\n" \
Petr Baudis5c91da22006-04-11 13:22:17 +0200210" --patch-with-raw\n" \
211" output both a patch and the diff-raw format.\n" \
Johannes Schindelind75f7952006-04-14 00:15:30 +0200212" --stat show diffstat instead of patch.\n" \
Junio C Hamano74e2abe2006-10-12 03:01:00 -0700213" --numstat show numeric diffstat instead of patch.\n" \
Johannes Schindelin29353272006-04-15 13:41:18 +0200214" --patch-with-stat\n" \
215" output a patch and prepend its diffstat.\n" \
Junio C Hamano8082d8d2005-09-21 00:18:27 -0700216" --name-only show only names of changed files.\n" \
Junio C Hamano946f5f72005-09-21 00:20:06 -0700217" --name-status show names and status of changed files.\n" \
Junio C Hamano47dd0d52005-12-13 17:21:41 -0800218" --full-index show full object name on index lines.\n" \
Junio C Hamano913419f2005-12-18 02:03:15 -0800219" --abbrev=<n> abbreviate object names in diff-tree header and diff-raw.\n" \
Junio C Hamano8082d8d2005-09-21 00:18:27 -0700220" -R swap input file pairs.\n" \
221" -B detect complete rewrites.\n" \
222" -M detect renames.\n" \
223" -C detect copies.\n" \
Junio C Hamanodda2d792005-07-13 12:52:35 -0700224" --find-copies-harder\n" \
Junio C Hamano8082d8d2005-09-21 00:18:27 -0700225" try unchanged files as candidate for copy detection.\n" \
226" -l<n> limit rename attempts up to <n> paths.\n" \
227" -O<file> reorder diffs according to the <file>.\n" \
228" -S<string> find filepair whose only one side contains the string.\n" \
Junio C Hamanodda2d792005-07-13 12:52:35 -0700229" --pickaxe-all\n" \
Stephan Federca499202006-07-07 15:57:08 +0200230" show all files diff when -S is used and hit is found.\n" \
231" -a --text treat all files as text.\n"
Junio C Hamanodda2d792005-07-13 12:52:35 -0700232
Junio C Hamano38c6f782005-05-21 19:40:36 -0700233extern int diff_queue_is_empty(void);
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700234extern void diff_flush(struct diff_options*);
Junio C Hamano86436c22005-04-25 18:22:47 -0700235
Junio C Hamanoe7baa4f2005-07-25 13:05:44 -0700236/* diff-raw status letters */
Junio C Hamanoca8c9152005-07-25 14:31:19 -0700237#define DIFF_STATUS_ADDED 'A'
Junio C Hamanoe7baa4f2005-07-25 13:05:44 -0700238#define DIFF_STATUS_COPIED 'C'
239#define DIFF_STATUS_DELETED 'D'
240#define DIFF_STATUS_MODIFIED 'M'
241#define DIFF_STATUS_RENAMED 'R'
242#define DIFF_STATUS_TYPE_CHANGED 'T'
243#define DIFF_STATUS_UNKNOWN 'X'
244#define DIFF_STATUS_UNMERGED 'U'
245
246/* these are not diff-raw status letters proper, but used by
247 * diffcore-filter insn to specify additional restrictions.
248 */
Junio C Hamano0b343792005-10-04 17:44:17 -0700249#define DIFF_STATUS_FILTER_AON '*'
Junio C Hamanoe7baa4f2005-07-25 13:05:44 -0700250#define DIFF_STATUS_FILTER_BROKEN 'B'
251
Junio C Hamano47dd0d52005-12-13 17:21:41 -0800252extern const char *diff_unique_abbrev(const unsigned char *, int);
253
Junio C Hamano4bd5b7d2007-11-10 00:15:03 -0800254/* do not report anything on removed paths */
255#define DIFF_SILENT_ON_REMOVED 01
Junio C Hamanofb63d7f2007-11-09 18:22:52 -0800256/* report racily-clean paths as modified */
257#define DIFF_RACY_IS_MODIFIED 02
Junio C Hamano4bd5b7d2007-11-10 00:15:03 -0800258extern int run_diff_files(struct rev_info *revs, unsigned int option);
Junio C Hamano5c21ac02006-04-22 03:58:04 -0700259extern int run_diff_index(struct rev_info *revs, int cached);
Junio C Hamanoe09ad6e2006-04-22 02:43:00 -0700260
Junio C Hamano1cfe7732007-01-30 01:11:08 -0800261extern int do_diff_cache(const unsigned char *, struct diff_options *);
Johannes Schindelinfcb3d0a2006-06-25 03:51:08 +0200262extern int diff_flush_patch_id(struct diff_options *, unsigned char *);
263
Junio C Hamanoda31b352007-12-13 23:40:27 -0800264extern int diff_result_code(struct diff_options *, int);
265
Junio C Hamano0569e9b2008-05-23 22:28:56 -0700266extern void diff_no_index(struct rev_info *, int, const char **, int, const char *);
267
Stephan Beyer75f3ff22009-02-10 15:30:35 +0100268extern int index_differs_from(const char *def, int diff_flags);
269
Junio C Hamano86436c22005-04-25 18:22:47 -0700270#endif /* DIFF_H */