Merge branch 'js/fetchconfig'
[git.git] / diff.h
1 /*
2  * Copyright (C) 2005 Junio C Hamano
3  */
4 #ifndef DIFF_H
5 #define DIFF_H
6
7 #include "tree-walk.h"
8
9 struct rev_info;
10 struct diff_options;
11
12 typedef void (*change_fn_t)(struct diff_options *options,
13                  unsigned old_mode, unsigned new_mode,
14                  const unsigned char *old_sha1,
15                  const unsigned char *new_sha1,
16                  const char *base, const char *path);
17
18 typedef void (*add_remove_fn_t)(struct diff_options *options,
19                     int addremove, unsigned mode,
20                     const unsigned char *sha1,
21                     const char *base, const char *path);
22
23 struct diff_options {
24         const char *filter;
25         const char *orderfile;
26         const char *pickaxe;
27         unsigned recursive:1,
28                  with_raw:1,
29                  with_stat:1,
30                  tree_in_recursive:1,
31                  binary:1,
32                  full_index:1,
33                  silent_on_remove:1,
34                  find_copies_harder:1,
35                  summary:1;
36         int context;
37         int break_opt;
38         int detect_rename;
39         int line_termination;
40         int output_format;
41         int pickaxe_opts;
42         int rename_score;
43         int reverse_diff;
44         int rename_limit;
45         int setup;
46         int abbrev;
47
48         int nr_paths;
49         const char **paths;
50         int *pathlens;
51         change_fn_t change;
52         add_remove_fn_t add_remove;
53 };
54
55 extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
56 extern void diff_tree_release_paths(struct diff_options *);
57 extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
58                      const char *base, struct diff_options *opt);
59 extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
60                           const char *base, struct diff_options *opt);
61
62 struct combine_diff_path {
63         struct combine_diff_path *next;
64         int len;
65         char *path;
66         unsigned int mode;
67         unsigned char sha1[20];
68         struct combine_diff_parent {
69                 char status;
70                 unsigned int mode;
71                 unsigned char sha1[20];
72         } parent[FLEX_ARRAY];
73 };
74 #define combine_diff_path_size(n, l) \
75         (sizeof(struct combine_diff_path) + \
76          sizeof(struct combine_diff_parent) * (n) + (l) + 1)
77
78 extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
79                               int dense, struct rev_info *);
80
81 extern void diff_tree_combined(const unsigned char *sha1, const unsigned char parent[][20], int num_parent, int dense, struct rev_info *rev);
82
83 extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *);
84
85 extern void diff_addremove(struct diff_options *,
86                            int addremove,
87                            unsigned mode,
88                            const unsigned char *sha1,
89                            const char *base,
90                            const char *path);
91
92 extern void diff_change(struct diff_options *,
93                         unsigned mode1, unsigned mode2,
94                         const unsigned char *sha1,
95                         const unsigned char *sha2,
96                         const char *base, const char *path);
97
98 extern void diff_unmerge(struct diff_options *,
99                          const char *path);
100
101 extern int diff_scoreopt_parse(const char *opt);
102
103 #define DIFF_SETUP_REVERSE              1
104 #define DIFF_SETUP_USE_CACHE            2
105 #define DIFF_SETUP_USE_SIZE_CACHE       4
106
107 extern int git_diff_config(const char *var, const char *value);
108 extern void diff_setup(struct diff_options *);
109 extern int diff_opt_parse(struct diff_options *, const char **, int);
110 extern int diff_setup_done(struct diff_options *);
111
112 #define DIFF_DETECT_RENAME      1
113 #define DIFF_DETECT_COPY        2
114
115 #define DIFF_PICKAXE_ALL        1
116 #define DIFF_PICKAXE_REGEX      2
117
118 extern void diffcore_std(struct diff_options *);
119
120 extern void diffcore_std_no_resolve(struct diff_options *);
121
122 #define COMMON_DIFF_OPTIONS_HELP \
123 "\ncommon diff options:\n" \
124 "  -z            output diff-raw with lines terminated with NUL.\n" \
125 "  -p            output patch format.\n" \
126 "  -u            synonym for -p.\n" \
127 "  --patch-with-raw\n" \
128 "                output both a patch and the diff-raw format.\n" \
129 "  --stat        show diffstat instead of patch.\n" \
130 "  --patch-with-stat\n" \
131 "                output a patch and prepend its diffstat.\n" \
132 "  --name-only   show only names of changed files.\n" \
133 "  --name-status show names and status of changed files.\n" \
134 "  --full-index  show full object name on index lines.\n" \
135 "  --abbrev=<n>  abbreviate object names in diff-tree header and diff-raw.\n" \
136 "  -R            swap input file pairs.\n" \
137 "  -B            detect complete rewrites.\n" \
138 "  -M            detect renames.\n" \
139 "  -C            detect copies.\n" \
140 "  --find-copies-harder\n" \
141 "                try unchanged files as candidate for copy detection.\n" \
142 "  -l<n>         limit rename attempts up to <n> paths.\n" \
143 "  -O<file>      reorder diffs according to the <file>.\n" \
144 "  -S<string>    find filepair whose only one side contains the string.\n" \
145 "  --pickaxe-all\n" \
146 "                show all files diff when -S is used and hit is found.\n"
147
148 extern int diff_queue_is_empty(void);
149
150 #define DIFF_FORMAT_RAW         1
151 #define DIFF_FORMAT_PATCH       2
152 #define DIFF_FORMAT_NO_OUTPUT   3
153 #define DIFF_FORMAT_NAME        4
154 #define DIFF_FORMAT_NAME_STATUS 5
155 #define DIFF_FORMAT_DIFFSTAT    6
156
157 extern void diff_flush(struct diff_options*);
158
159 /* diff-raw status letters */
160 #define DIFF_STATUS_ADDED               'A'
161 #define DIFF_STATUS_COPIED              'C'
162 #define DIFF_STATUS_DELETED             'D'
163 #define DIFF_STATUS_MODIFIED            'M'
164 #define DIFF_STATUS_RENAMED             'R'
165 #define DIFF_STATUS_TYPE_CHANGED        'T'
166 #define DIFF_STATUS_UNKNOWN             'X'
167 #define DIFF_STATUS_UNMERGED            'U'
168
169 /* these are not diff-raw status letters proper, but used by
170  * diffcore-filter insn to specify additional restrictions.
171  */
172 #define DIFF_STATUS_FILTER_AON          '*'
173 #define DIFF_STATUS_FILTER_BROKEN       'B'
174
175 extern const char *diff_unique_abbrev(const unsigned char *, int);
176
177 extern int run_diff_files(struct rev_info *revs, int silent_on_removed);
178
179 extern int run_diff_index(struct rev_info *revs, int cached);
180
181 #endif /* DIFF_H */