🌐 AI搜索 & 代理 主页
blob: 2ef3341fb0852fc8958fa5c5eacab69ee68c0ad9 [file] [log] [blame]
Junio C Hamanobe3cfa82005-04-26 16:25:051/*
2 * Copyright (C) 2005 Junio C Hamano
3 */
Junio C Hamano86436c22005-04-26 01:22:474#ifndef DIFF_H
5#define DIFF_H
6
Junio C Hamano1b0c7172006-03-30 06:55:437#include "tree-walk.h"
Linus Torvalds50f9a852006-01-31 22:10:568
Linus Torvalds91539832006-04-17 18:59:329struct rev_info;
Linus Torvaldsac1b3d12005-10-21 04:05:0510struct diff_options;
Jeff King04245582006-09-07 06:35:4211struct diff_queue_struct;
Linus Torvaldsac1b3d12005-10-21 04:05:0512
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,
Jens Lehmanne3d42c42010-01-18 20:26:1817 const char *fullpath,
18 unsigned old_dirty_submodule, unsigned new_dirty_submodule);
Linus Torvaldsac1b3d12005-10-21 04:05:0519
20typedef void (*add_remove_fn_t)(struct diff_options *options,
21 int addremove, unsigned mode,
22 const unsigned char *sha1,
Jens Lehmanne3d42c42010-01-18 20:26:1823 const char *fullpath, unsigned dirty_submodule);
Linus Torvaldsac1b3d12005-10-21 04:05:0524
Jeff King04245582006-09-07 06:35:4225typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
26 struct diff_options *options, void *data);
27
Timo Hirvonenc6744342006-06-24 17:21:5328#define DIFF_FORMAT_RAW 0x0001
29#define DIFF_FORMAT_DIFFSTAT 0x0002
Junio C Hamano74e2abe2006-10-12 10:01:0030#define DIFF_FORMAT_NUMSTAT 0x0004
31#define DIFF_FORMAT_SUMMARY 0x0008
32#define DIFF_FORMAT_PATCH 0x0010
Nicolas Pitreebd124c2006-12-15 04:15:4433#define DIFF_FORMAT_SHORTSTAT 0x0020
Linus Torvalds7df7c012008-02-12 21:26:3134#define DIFF_FORMAT_DIRSTAT 0x0040
Timo Hirvonenc6744342006-06-24 17:21:5335
36/* These override all above */
Junio C Hamano74e2abe2006-10-12 10:01:0037#define DIFF_FORMAT_NAME 0x0100
38#define DIFF_FORMAT_NAME_STATUS 0x0200
39#define DIFF_FORMAT_CHECKDIFF 0x0400
Timo Hirvonenc6744342006-06-24 17:21:5340
41/* Same as output_format = 0 but we know that -s flag was given
42 * and we should not give default value to output_format.
43 */
Junio C Hamano74e2abe2006-10-12 10:01:0044#define DIFF_FORMAT_NO_OUTPUT 0x0800
Timo Hirvonenc6744342006-06-24 17:21:5345
Junio C Hamano74e2abe2006-10-12 10:01:0046#define DIFF_FORMAT_CALLBACK 0x1000
Jeff King04245582006-09-07 06:35:4247
Pierre Habouzit8f67f8a2007-11-10 19:05:1448#define DIFF_OPT_RECURSIVE (1 << 0)
49#define DIFF_OPT_TREE_IN_RECURSIVE (1 << 1)
50#define DIFF_OPT_BINARY (1 << 2)
51#define DIFF_OPT_TEXT (1 << 3)
52#define DIFF_OPT_FULL_INDEX (1 << 4)
53#define DIFF_OPT_SILENT_ON_REMOVE (1 << 5)
54#define DIFF_OPT_FIND_COPIES_HARDER (1 << 6)
55#define DIFF_OPT_FOLLOW_RENAMES (1 << 7)
56#define DIFF_OPT_COLOR_DIFF (1 << 8)
57#define DIFF_OPT_COLOR_DIFF_WORDS (1 << 9)
58#define DIFF_OPT_HAS_CHANGES (1 << 10)
Junio C Hamano90b19942009-05-23 08:15:3559#define DIFF_OPT_QUICK (1 << 11)
Pierre Habouzit8f67f8a2007-11-10 19:05:1460#define DIFF_OPT_NO_INDEX (1 << 12)
61#define DIFF_OPT_ALLOW_EXTERNAL (1 << 13)
62#define DIFF_OPT_EXIT_WITH_STATUS (1 << 14)
63#define DIFF_OPT_REVERSE_DIFF (1 << 15)
Wincent Colaiuta62c64892007-12-13 20:24:5264#define DIFF_OPT_CHECK_FAILED (1 << 16)
Junio C Hamanocd676a52008-02-12 22:26:0265#define DIFF_OPT_RELATIVE_NAME (1 << 17)
Johannes Schindelin50fd9bd2008-05-14 17:03:3166#define DIFF_OPT_IGNORE_SUBMODULES (1 << 18)
Junio C Hamanof88d2252008-09-03 00:28:5967#define DIFF_OPT_DIRSTAT_CUMULATIVE (1 << 19)
Heikki Orsilafd337772008-09-05 19:27:3568#define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
Jeff Kingc7534ef2008-10-26 04:45:5569#define DIFF_OPT_ALLOW_TEXTCONV (1 << 21)
Junio C Hamanof2451942009-05-22 19:45:2970#define DIFF_OPT_DIFF_FROM_CONTENTS (1 << 22)
Johannes Schindelin752c0c22009-10-19 12:38:3271#define DIFF_OPT_SUBMODULE_LOG (1 << 23)
72
Pierre Habouzit8f67f8a2007-11-10 19:05:1473#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
74#define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)
75#define DIFF_OPT_CLR(opts, flag) ((opts)->flags &= ~DIFF_OPT_##flag)
Keith Cascio628d5c22009-02-17 03:26:4976#define DIFF_XDL_TST(opts, flag) ((opts)->xdl_opts & XDF_##flag)
77#define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag)
78#define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag)
Pierre Habouzit8f67f8a2007-11-10 19:05:1479
Junio C Hamano6b5ee132005-09-21 07:00:4780struct diff_options {
Junio C Hamano6b5ee132005-09-21 07:00:4781 const char *filter;
82 const char *orderfile;
83 const char *pickaxe;
Junio C Hamano2f3f8b22006-11-02 08:02:1184 const char *single_follow;
Johannes Schindelineab9a402007-12-18 19:32:1485 const char *a_prefix, *b_prefix;
Pierre Habouzit8f67f8a2007-11-10 19:05:1486 unsigned flags;
Linus Torvaldsee1e5412006-05-13 20:23:4887 int context;
René Scharfe6d0e6742008-12-28 18:45:3288 int interhunkcontext;
Junio C Hamano6b5ee132005-09-21 07:00:4789 int break_opt;
90 int detect_rename;
Junio C Hamanofb132272007-08-03 20:33:3191 int skip_stat_unmatch;
Junio C Hamano6b5ee132005-09-21 07:00:4792 int line_termination;
93 int output_format;
94 int pickaxe_opts;
95 int rename_score;
Junio C Hamano8082d8d2005-09-21 07:18:2796 int rename_limit;
Jeff Kingb8960bb2008-04-30 17:25:5397 int warn_on_too_large_rename;
Linus Torvalds7df7c012008-02-12 21:26:3198 int dirstat_percent;
Junio C Hamano6b5ee132005-09-21 07:00:4799 int setup;
Junio C Hamano47dd0d52005-12-14 01:21:41100 int abbrev;
Junio C Hamanocd676a52008-02-12 22:26:02101 const char *prefix;
102 int prefix_length;
Johannes Schindelin698ce6f2006-05-20 13:40:29103 const char *stat_sep;
Johannes Schindelin0d21efa2006-06-14 15:40:23104 long xdl_opts;
Linus Torvaldsac1b3d12005-10-21 04:05:05105
Junio C Hamanoa2540022006-09-27 01:53:02106 int stat_width;
107 int stat_name_width;
Johannes Schindelin2b6a5412009-01-17 16:29:45108 const char *word_regex;
Junio C Hamanoa2540022006-09-27 01:53:02109
Johannes Schindelin34a5e1a2007-02-25 22:34:54110 /* this is set by diffcore for DIFF_FORMAT_PATCH */
111 int found_changes;
112
Daniel Barkalowc0c77732008-03-10 02:43:39113 FILE *file;
114 int close_file;
115
Junio C Hamanoa8baa7b2006-04-10 23:39:11116 int nr_paths;
117 const char **paths;
118 int *pathlens;
Linus Torvaldsac1b3d12005-10-21 04:05:05119 change_fn_t change;
120 add_remove_fn_t add_remove;
Jeff King04245582006-09-07 06:35:42121 diff_format_fn_t format_callback;
122 void *format_callback_data;
Junio C Hamano6b5ee132005-09-21 07:00:47123};
124
Jeff Kingce436972006-07-23 09:24:18125enum color_diff {
126 DIFF_RESET = 0,
127 DIFF_PLAIN = 1,
128 DIFF_METAINFO = 2,
129 DIFF_FRAGINFO = 3,
130 DIFF_FILE_OLD = 4,
131 DIFF_FILE_NEW = 5,
132 DIFF_COMMIT = 6,
Junio C Hamano448c3ef2006-09-23 05:48:39133 DIFF_WHITESPACE = 7,
Bert Wesarg89cb73a2009-11-27 06:55:18134 DIFF_FUNCINFO = 8,
Jeff Kingce436972006-07-23 09:24:18135};
136const char *diff_get_color(int diff_use_color, enum color_diff ix);
Pierre Habouzit8f67f8a2007-11-10 19:05:14137#define diff_get_color_opt(o, ix) \
138 diff_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
139
Jeff Kingce436972006-07-23 09:24:18140
Johannes Schindelin698ce6f2006-05-20 13:40:29141extern const char mime_boundary_leader[];
142
Junio C Hamanoa8baa7b2006-04-10 23:39:11143extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
144extern void diff_tree_release_paths(struct diff_options *);
Linus Torvaldsac1b3d12005-10-21 04:05:05145extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
146 const char *base, struct diff_options *opt);
147extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
148 const char *base, struct diff_options *opt);
Rene Scharfe2b603562006-10-26 16:52:39149extern int diff_root_tree_sha1(const unsigned char *new, const char *base,
150 struct diff_options *opt);
Linus Torvaldsac1b3d12005-10-21 04:05:05151
Junio C Hamanoea726d02006-01-28 08:03:38152struct combine_diff_path {
153 struct combine_diff_path *next;
154 int len;
155 char *path;
Junio C Hamano2454c962006-02-06 20:53:07156 unsigned int mode;
Junio C Hamanoea726d02006-01-28 08:03:38157 unsigned char sha1[20];
Junio C Hamano2454c962006-02-06 20:53:07158 struct combine_diff_parent {
Junio C Hamanod416df82006-02-10 10:30:52159 char status;
Junio C Hamano2454c962006-02-06 20:53:07160 unsigned int mode;
161 unsigned char sha1[20];
162 } parent[FLEX_ARRAY];
Junio C Hamanoea726d02006-01-28 08:03:38163};
Junio C Hamano2454c962006-02-06 20:53:07164#define combine_diff_path_size(n, l) \
165 (sizeof(struct combine_diff_path) + \
166 sizeof(struct combine_diff_parent) * (n) + (l) + 1)
Junio C Hamanoea726d02006-01-28 08:03:38167
Linus Torvalds91539832006-04-17 18:59:32168extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
169 int dense, struct rev_info *);
Junio C Hamanoea726d02006-01-28 08:03:38170
Junio C Hamano0fe7c1d2006-04-29 08:24:49171extern void diff_tree_combined(const unsigned char *sha1, const unsigned char parent[][20], int num_parent, int dense, struct rev_info *rev);
172
Linus Torvalds91539832006-04-17 18:59:32173extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *);
Junio C Hamanoaf3feef2006-01-24 09:22:04174
Junio C Hamanoa5a818e2008-08-19 03:08:09175void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
176
Junio C Hamano6b5ee132005-09-21 07:00:47177extern void diff_addremove(struct diff_options *,
178 int addremove,
Junio C Hamano77eb2722005-04-27 16:21:00179 unsigned mode,
180 const unsigned char *sha1,
Jens Lehmanne3d42c42010-01-18 20:26:18181 const char *fullpath, unsigned dirty_submodule);
Junio C Hamano77eb2722005-04-27 16:21:00182
Junio C Hamano6b5ee132005-09-21 07:00:47183extern void diff_change(struct diff_options *,
184 unsigned mode1, unsigned mode2,
185 const unsigned char *sha1,
186 const unsigned char *sha2,
Jens Lehmanne3d42c42010-01-18 20:26:18187 const char *fullpath,
188 unsigned dirty_submodule1, unsigned dirty_submodule2);
Junio C Hamano77eb2722005-04-27 16:21:00189
Junio C Hamano6b5ee132005-09-21 07:00:47190extern void diff_unmerge(struct diff_options *,
Junio C Hamanoe9c84092007-01-05 09:25:18191 const char *path,
192 unsigned mode,
193 const unsigned char *sha1);
Junio C Hamano77eb2722005-04-27 16:21:00194
Junio C Hamano19feebc2005-05-27 22:54:37195#define DIFF_SETUP_REVERSE 1
Junio C Hamanof0c6b2a2005-05-27 22:56:38196#define DIFF_SETUP_USE_CACHE 2
197#define DIFF_SETUP_USE_SIZE_CACHE 4
Junio C Hamanoce240672005-06-03 08:36:43198
Johannes Schindelinef90d6d2008-05-14 17:46:53199extern int git_diff_basic_config(const char *var, const char *value, void *cb);
200extern int git_diff_ui_config(const char *var, const char *value, void *cb);
Matthias Kestenholz6b2f2d92008-02-18 07:26:03201extern int diff_use_color_default;
Junio C Hamano6b5ee132005-09-21 07:00:47202extern void diff_setup(struct diff_options *);
203extern int diff_opt_parse(struct diff_options *, const char **, int);
204extern int diff_setup_done(struct diff_options *);
Junio C Hamano86436c22005-04-26 01:22:47205
Junio C Hamano6b14d7f2005-05-22 17:04:37206#define DIFF_DETECT_RENAME 1
207#define DIFF_DETECT_COPY 2
208
Junio C Hamano367cec12005-05-27 22:55:28209#define DIFF_PICKAXE_ALL 1
Petr Baudisd01d8c62006-03-29 00:16:33210#define DIFF_PICKAXE_REGEX 2
Junio C Hamanof345b0a2005-05-30 07:08:37211
Junio C Hamano6b5ee132005-09-21 07:00:47212extern void diffcore_std(struct diff_options *);
Junio C Hamano730f7282009-09-20 07:03:39213extern void diffcore_fix_diff_index(struct diff_options *);
Junio C Hamanof2ce9fd2005-06-12 03:57:13214
Junio C Hamanodda2d792005-07-13 19:52:35215#define COMMON_DIFF_OPTIONS_HELP \
216"\ncommon diff options:\n" \
Junio C Hamano8082d8d2005-09-21 07:18:27217" -z output diff-raw with lines terminated with NUL.\n" \
218" -p output patch format.\n" \
219" -u synonym for -p.\n" \
Petr Baudis5c91da22006-04-11 11:22:17220" --patch-with-raw\n" \
221" output both a patch and the diff-raw format.\n" \
Johannes Schindelind75f7952006-04-13 22:15:30222" --stat show diffstat instead of patch.\n" \
Junio C Hamano74e2abe2006-10-12 10:01:00223" --numstat show numeric diffstat instead of patch.\n" \
Johannes Schindelin29353272006-04-15 11:41:18224" --patch-with-stat\n" \
225" output a patch and prepend its diffstat.\n" \
Junio C Hamano8082d8d2005-09-21 07:18:27226" --name-only show only names of changed files.\n" \
Junio C Hamano946f5f72005-09-21 07:20:06227" --name-status show names and status of changed files.\n" \
Junio C Hamano47dd0d52005-12-14 01:21:41228" --full-index show full object name on index lines.\n" \
Junio C Hamano913419f2005-12-18 10:03:15229" --abbrev=<n> abbreviate object names in diff-tree header and diff-raw.\n" \
Junio C Hamano8082d8d2005-09-21 07:18:27230" -R swap input file pairs.\n" \
231" -B detect complete rewrites.\n" \
232" -M detect renames.\n" \
233" -C detect copies.\n" \
Junio C Hamanodda2d792005-07-13 19:52:35234" --find-copies-harder\n" \
Junio C Hamano8082d8d2005-09-21 07:18:27235" try unchanged files as candidate for copy detection.\n" \
236" -l<n> limit rename attempts up to <n> paths.\n" \
237" -O<file> reorder diffs according to the <file>.\n" \
238" -S<string> find filepair whose only one side contains the string.\n" \
Junio C Hamanodda2d792005-07-13 19:52:35239" --pickaxe-all\n" \
Stephan Federca499202006-07-07 13:57:08240" show all files diff when -S is used and hit is found.\n" \
241" -a --text treat all files as text.\n"
Junio C Hamanodda2d792005-07-13 19:52:35242
Junio C Hamano38c6f782005-05-22 02:40:36243extern int diff_queue_is_empty(void);
Junio C Hamano6b5ee132005-09-21 07:00:47244extern void diff_flush(struct diff_options*);
Junio C Hamano86436c22005-04-26 01:22:47245
Junio C Hamanoe7baa4f2005-07-25 20:05:44246/* diff-raw status letters */
Junio C Hamanoca8c9152005-07-25 21:31:19247#define DIFF_STATUS_ADDED 'A'
Junio C Hamanoe7baa4f2005-07-25 20:05:44248#define DIFF_STATUS_COPIED 'C'
249#define DIFF_STATUS_DELETED 'D'
250#define DIFF_STATUS_MODIFIED 'M'
251#define DIFF_STATUS_RENAMED 'R'
252#define DIFF_STATUS_TYPE_CHANGED 'T'
253#define DIFF_STATUS_UNKNOWN 'X'
254#define DIFF_STATUS_UNMERGED 'U'
255
256/* these are not diff-raw status letters proper, but used by
257 * diffcore-filter insn to specify additional restrictions.
258 */
Junio C Hamano0b343792005-10-05 00:44:17259#define DIFF_STATUS_FILTER_AON '*'
Junio C Hamanoe7baa4f2005-07-25 20:05:44260#define DIFF_STATUS_FILTER_BROKEN 'B'
261
Junio C Hamano47dd0d52005-12-14 01:21:41262extern const char *diff_unique_abbrev(const unsigned char *, int);
263
Junio C Hamano4bd5b7d2007-11-10 08:15:03264/* do not report anything on removed paths */
265#define DIFF_SILENT_ON_REMOVED 01
Junio C Hamanofb63d7f2007-11-10 02:22:52266/* report racily-clean paths as modified */
267#define DIFF_RACY_IS_MODIFIED 02
Junio C Hamano4bd5b7d2007-11-10 08:15:03268extern int run_diff_files(struct rev_info *revs, unsigned int option);
Junio C Hamano5c21ac02006-04-22 10:58:04269extern int run_diff_index(struct rev_info *revs, int cached);
Junio C Hamanoe09ad6e2006-04-22 09:43:00270
Junio C Hamano1cfe7732007-01-30 09:11:08271extern int do_diff_cache(const unsigned char *, struct diff_options *);
Johannes Schindelinfcb3d0a2006-06-25 01:51:08272extern int diff_flush_patch_id(struct diff_options *, unsigned char *);
273
Junio C Hamanoda31b352007-12-14 07:40:27274extern int diff_result_code(struct diff_options *, int);
275
Junio C Hamano0569e9b2008-05-24 05:28:56276extern void diff_no_index(struct rev_info *, int, const char **, int, const char *);
277
Stephan Beyer75f3ff22009-02-10 14:30:35278extern int index_differs_from(const char *def, int diff_flags);
279
Junio C Hamano86436c22005-04-26 01:22:47280#endif /* DIFF_H */