gitweb: Return or exit after done serving request
[git/gsoc2010-gitweb.git] / diff.h
blob48abe7a96a96df98ef91d5f5d7ba9f57cace777f
1 /*
2 * Copyright (C) 2005 Junio C Hamano
3 */
4 #ifndef DIFF_H
5 #define DIFF_H
7 #include "tree-walk.h"
9 struct rev_info;
10 struct diff_options;
11 struct diff_queue_struct;
12 struct strbuf;
14 typedef void (*change_fn_t)(struct diff_options *options,
15 unsigned old_mode, unsigned new_mode,
16 const unsigned char *old_sha1,
17 const unsigned char *new_sha1,
18 const char *fullpath,
19 unsigned old_dirty_submodule, unsigned new_dirty_submodule);
21 typedef void (*add_remove_fn_t)(struct diff_options *options,
22 int addremove, unsigned mode,
23 const unsigned char *sha1,
24 const char *fullpath, unsigned dirty_submodule);
26 typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
27 struct diff_options *options, void *data);
29 typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
31 #define DIFF_FORMAT_RAW 0x0001
32 #define DIFF_FORMAT_DIFFSTAT 0x0002
33 #define DIFF_FORMAT_NUMSTAT 0x0004
34 #define DIFF_FORMAT_SUMMARY 0x0008
35 #define DIFF_FORMAT_PATCH 0x0010
36 #define DIFF_FORMAT_SHORTSTAT 0x0020
37 #define DIFF_FORMAT_DIRSTAT 0x0040
39 /* These override all above */
40 #define DIFF_FORMAT_NAME 0x0100
41 #define DIFF_FORMAT_NAME_STATUS 0x0200
42 #define DIFF_FORMAT_CHECKDIFF 0x0400
44 /* Same as output_format = 0 but we know that -s flag was given
45 * and we should not give default value to output_format.
47 #define DIFF_FORMAT_NO_OUTPUT 0x0800
49 #define DIFF_FORMAT_CALLBACK 0x1000
51 #define DIFF_OPT_RECURSIVE (1 << 0)
52 #define DIFF_OPT_TREE_IN_RECURSIVE (1 << 1)
53 #define DIFF_OPT_BINARY (1 << 2)
54 #define DIFF_OPT_TEXT (1 << 3)
55 #define DIFF_OPT_FULL_INDEX (1 << 4)
56 #define DIFF_OPT_SILENT_ON_REMOVE (1 << 5)
57 #define DIFF_OPT_FIND_COPIES_HARDER (1 << 6)
58 #define DIFF_OPT_FOLLOW_RENAMES (1 << 7)
59 #define DIFF_OPT_COLOR_DIFF (1 << 8)
60 /* (1 << 9) unused */
61 #define DIFF_OPT_HAS_CHANGES (1 << 10)
62 #define DIFF_OPT_QUICK (1 << 11)
63 #define DIFF_OPT_NO_INDEX (1 << 12)
64 #define DIFF_OPT_ALLOW_EXTERNAL (1 << 13)
65 #define DIFF_OPT_EXIT_WITH_STATUS (1 << 14)
66 #define DIFF_OPT_REVERSE_DIFF (1 << 15)
67 #define DIFF_OPT_CHECK_FAILED (1 << 16)
68 #define DIFF_OPT_RELATIVE_NAME (1 << 17)
69 #define DIFF_OPT_IGNORE_SUBMODULES (1 << 18)
70 #define DIFF_OPT_DIRSTAT_CUMULATIVE (1 << 19)
71 #define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
72 #define DIFF_OPT_ALLOW_TEXTCONV (1 << 21)
73 #define DIFF_OPT_DIFF_FROM_CONTENTS (1 << 22)
74 #define DIFF_OPT_SUBMODULE_LOG (1 << 23)
75 #define DIFF_OPT_DIRTY_SUBMODULES (1 << 24)
76 #define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)
78 #define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
79 #define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)
80 #define DIFF_OPT_CLR(opts, flag) ((opts)->flags &= ~DIFF_OPT_##flag)
81 #define DIFF_XDL_TST(opts, flag) ((opts)->xdl_opts & XDF_##flag)
82 #define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag)
83 #define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag)
85 enum diff_words_type {
86 DIFF_WORDS_NONE = 0,
87 DIFF_WORDS_PORCELAIN,
88 DIFF_WORDS_PLAIN,
89 DIFF_WORDS_COLOR
92 struct diff_options {
93 const char *filter;
94 const char *orderfile;
95 const char *pickaxe;
96 const char *single_follow;
97 const char *a_prefix, *b_prefix;
98 unsigned flags;
99 int context;
100 int interhunkcontext;
101 int break_opt;
102 int detect_rename;
103 int skip_stat_unmatch;
104 int line_termination;
105 int output_format;
106 int pickaxe_opts;
107 int rename_score;
108 int rename_limit;
109 int warn_on_too_large_rename;
110 int dirstat_percent;
111 int setup;
112 int abbrev;
113 const char *prefix;
114 int prefix_length;
115 const char *stat_sep;
116 long xdl_opts;
118 int stat_width;
119 int stat_name_width;
120 const char *word_regex;
121 enum diff_words_type word_diff;
123 /* this is set by diffcore for DIFF_FORMAT_PATCH */
124 int found_changes;
126 FILE *file;
127 int close_file;
129 int nr_paths;
130 const char **paths;
131 int *pathlens;
132 change_fn_t change;
133 add_remove_fn_t add_remove;
134 diff_format_fn_t format_callback;
135 void *format_callback_data;
136 diff_prefix_fn_t output_prefix;
137 void *output_prefix_data;
140 enum color_diff {
141 DIFF_RESET = 0,
142 DIFF_PLAIN = 1,
143 DIFF_METAINFO = 2,
144 DIFF_FRAGINFO = 3,
145 DIFF_FILE_OLD = 4,
146 DIFF_FILE_NEW = 5,
147 DIFF_COMMIT = 6,
148 DIFF_WHITESPACE = 7,
149 DIFF_FUNCINFO = 8
151 const char *diff_get_color(int diff_use_color, enum color_diff ix);
152 #define diff_get_color_opt(o, ix) \
153 diff_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
156 extern const char mime_boundary_leader[];
158 extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
159 extern void diff_tree_release_paths(struct diff_options *);
160 extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
161 const char *base, struct diff_options *opt);
162 extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
163 const char *base, struct diff_options *opt);
164 extern int diff_root_tree_sha1(const unsigned char *new, const char *base,
165 struct diff_options *opt);
167 struct combine_diff_path {
168 struct combine_diff_path *next;
169 int len;
170 char *path;
171 unsigned int mode;
172 unsigned char sha1[20];
173 struct combine_diff_parent {
174 char status;
175 unsigned int mode;
176 unsigned char sha1[20];
177 } parent[FLEX_ARRAY];
179 #define combine_diff_path_size(n, l) \
180 (sizeof(struct combine_diff_path) + \
181 sizeof(struct combine_diff_parent) * (n) + (l) + 1)
183 extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
184 int dense, struct rev_info *);
186 extern void diff_tree_combined(const unsigned char *sha1, const unsigned char parent[][20], int num_parent, int dense, struct rev_info *rev);
188 extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *);
190 void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
192 extern void diff_addremove(struct diff_options *,
193 int addremove,
194 unsigned mode,
195 const unsigned char *sha1,
196 const char *fullpath, unsigned dirty_submodule);
198 extern void diff_change(struct diff_options *,
199 unsigned mode1, unsigned mode2,
200 const unsigned char *sha1,
201 const unsigned char *sha2,
202 const char *fullpath,
203 unsigned dirty_submodule1, unsigned dirty_submodule2);
205 extern void diff_unmerge(struct diff_options *,
206 const char *path,
207 unsigned mode,
208 const unsigned char *sha1);
210 #define DIFF_SETUP_REVERSE 1
211 #define DIFF_SETUP_USE_CACHE 2
212 #define DIFF_SETUP_USE_SIZE_CACHE 4
214 extern int git_diff_basic_config(const char *var, const char *value, void *cb);
215 extern int git_diff_ui_config(const char *var, const char *value, void *cb);
216 extern int diff_use_color_default;
217 extern void diff_setup(struct diff_options *);
218 extern int diff_opt_parse(struct diff_options *, const char **, int);
219 extern int diff_setup_done(struct diff_options *);
221 #define DIFF_DETECT_RENAME 1
222 #define DIFF_DETECT_COPY 2
224 #define DIFF_PICKAXE_ALL 1
225 #define DIFF_PICKAXE_REGEX 2
227 extern void diffcore_std(struct diff_options *);
228 extern void diffcore_fix_diff_index(struct diff_options *);
230 #define COMMON_DIFF_OPTIONS_HELP \
231 "\ncommon diff options:\n" \
232 " -z output diff-raw with lines terminated with NUL.\n" \
233 " -p output patch format.\n" \
234 " -u synonym for -p.\n" \
235 " --patch-with-raw\n" \
236 " output both a patch and the diff-raw format.\n" \
237 " --stat show diffstat instead of patch.\n" \
238 " --numstat show numeric diffstat instead of patch.\n" \
239 " --patch-with-stat\n" \
240 " output a patch and prepend its diffstat.\n" \
241 " --name-only show only names of changed files.\n" \
242 " --name-status show names and status of changed files.\n" \
243 " --full-index show full object name on index lines.\n" \
244 " --abbrev=<n> abbreviate object names in diff-tree header and diff-raw.\n" \
245 " -R swap input file pairs.\n" \
246 " -B detect complete rewrites.\n" \
247 " -M detect renames.\n" \
248 " -C detect copies.\n" \
249 " --find-copies-harder\n" \
250 " try unchanged files as candidate for copy detection.\n" \
251 " -l<n> limit rename attempts up to <n> paths.\n" \
252 " -O<file> reorder diffs according to the <file>.\n" \
253 " -S<string> find filepair whose only one side contains the string.\n" \
254 " --pickaxe-all\n" \
255 " show all files diff when -S is used and hit is found.\n" \
256 " -a --text treat all files as text.\n"
258 extern int diff_queue_is_empty(void);
259 extern void diff_flush(struct diff_options*);
261 /* diff-raw status letters */
262 #define DIFF_STATUS_ADDED 'A'
263 #define DIFF_STATUS_COPIED 'C'
264 #define DIFF_STATUS_DELETED 'D'
265 #define DIFF_STATUS_MODIFIED 'M'
266 #define DIFF_STATUS_RENAMED 'R'
267 #define DIFF_STATUS_TYPE_CHANGED 'T'
268 #define DIFF_STATUS_UNKNOWN 'X'
269 #define DIFF_STATUS_UNMERGED 'U'
271 /* these are not diff-raw status letters proper, but used by
272 * diffcore-filter insn to specify additional restrictions.
274 #define DIFF_STATUS_FILTER_AON '*'
275 #define DIFF_STATUS_FILTER_BROKEN 'B'
277 extern const char *diff_unique_abbrev(const unsigned char *, int);
279 /* do not report anything on removed paths */
280 #define DIFF_SILENT_ON_REMOVED 01
281 /* report racily-clean paths as modified */
282 #define DIFF_RACY_IS_MODIFIED 02
283 extern int run_diff_files(struct rev_info *revs, unsigned int option);
284 extern int run_diff_index(struct rev_info *revs, int cached);
286 extern int do_diff_cache(const unsigned char *, struct diff_options *);
287 extern int diff_flush_patch_id(struct diff_options *, unsigned char *);
289 extern int diff_result_code(struct diff_options *, int);
291 extern void diff_no_index(struct rev_info *, int, const char **, int, const char *);
293 extern int index_differs_from(const char *def, int diff_flags);
295 #endif /* DIFF_H */