1 module deimos.git2.diff;
2 
3 import deimos.git2.common;
4 import deimos.git2.types;
5 import deimos.git2.oid;
6 import deimos.git2.strarray;
7 import deimos.git2.tree;
8 import deimos.git2.refs;
9 
10 extern(C):
11 
12 enum git_diff_option_t {
13 	GIT_DIFF_NORMAL = 0,
14 	GIT_DIFF_REVERSE = (1u << 0),
15 	GIT_DIFF_INCLUDE_IGNORED = (1u << 1),
16 	GIT_DIFF_RECURSE_IGNORED_DIRS = (1u << 2),
17 	GIT_DIFF_INCLUDE_UNTRACKED = (1u << 3),
18 	GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1u << 4),
19 	GIT_DIFF_INCLUDE_UNMODIFIED = (1u << 5),
20 	GIT_DIFF_INCLUDE_TYPECHANGE = (1u << 6),
21 	GIT_DIFF_INCLUDE_TYPECHANGE_TREES = (1u << 7),
22 	GIT_DIFF_IGNORE_FILEMODE = (1u << 8),
23 	GIT_DIFF_IGNORE_SUBMODULES = (1u << 9),
24 	GIT_DIFF_IGNORE_CASE = (1u << 10),
25 	GIT_DIFF_DISABLE_PATHSPEC_MATCH = (1u << 12),
26 	GIT_DIFF_SKIP_BINARY_CHECK = (1u << 13),
27 	GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS = (1u << 14),
28 	GIT_DIFF_FORCE_TEXT = (1u << 20),
29 	GIT_DIFF_FORCE_BINARY = (1u << 21),
30 	GIT_DIFF_IGNORE_WHITESPACE = (1u << 22),
31 	GIT_DIFF_IGNORE_WHITESPACE_CHANGE = (1u << 23),
32 	GIT_DIFF_IGNORE_WHITESPACE_EOL = (1u << 24),
33 	GIT_DIFF_SHOW_UNTRACKED_CONTENT = (1u << 25),
34 	GIT_DIFF_SHOW_UNMODIFIED = (1u << 26),
35 	GIT_DIFF_PATIENCE = (1u << 28),
36 	GIT_DIFF_MINIMAL = (1 << 29),
37 }
38 
39 struct git_diff {
40     @disable this();
41     @disable this(this);
42 }
43 
44 enum git_diff_flag_t {
45 	GIT_DIFF_FLAG_BINARY     = (1u << 0),
46 	GIT_DIFF_FLAG_NOT_BINARY = (1u << 1),
47 	GIT_DIFF_FLAG_VALID_OID  = (1u << 2),
48 }
49 
50 enum git_delta_t {
51 	GIT_DELTA_UNMODIFIED = 0,
52 	GIT_DELTA_ADDED = 1,
53 	GIT_DELTA_DELETED = 2,
54 	GIT_DELTA_MODIFIED = 3,
55 	GIT_DELTA_RENAMED = 4,
56 	GIT_DELTA_COPIED = 5,
57 	GIT_DELTA_IGNORED = 6,
58 	GIT_DELTA_UNTRACKED = 7,
59 	GIT_DELTA_TYPECHANGE = 8,
60 }
61 
62 struct git_diff_file {
63 	git_oid     oid;
64 	const(char)*path;
65 	git_off_t   size;
66 	uint32_t    flags;
67 	uint16_t    mode;
68 }
69 
70 struct git_diff_delta {
71 	git_delta_t   status;
72 	uint32_t      flags;
73 	uint16_t      similarity;
74 	uint16_t      nfiles;
75 	git_diff_file old_file;
76 	git_diff_file new_file;
77 }
78 
79 alias git_diff_notify_cb = int function(
80 	const(git_diff)* diff_so_far,
81 	const(git_diff_delta)* delta_to_add,
82 	const(char)* matched_pathspec,
83 	void *payload);
84 
85 struct git_diff_options {
86 	uint version_ = GIT_DIFF_OPTIONS_VERSION;
87 	uint32_t flags;
88 	git_submodule_ignore_t ignore_submodules;
89 	git_strarray       pathspec;
90 	git_diff_notify_cb notify_cb;
91 	void              *notify_payload;
92 	uint16_t    context_lines = 3;
93 	uint16_t    interhunk_lines;
94 	uint16_t    oid_abbrev;
95 	git_off_t   max_size;
96 	const(char)* old_prefix;
97 	const(char)* new_prefix;
98 }
99 
100 enum GIT_DIFF_OPTIONS_VERSION = 1;
101 
102 enum git_diff_options GIT_DIFF_OPTIONS_INIT =
103 	{GIT_DIFF_OPTIONS_VERSION, 0, git_submodule_ignore_t.GIT_SUBMODULE_IGNORE_DEFAULT, {null,0}, null, null, 3};
104 
105 alias git_diff_file_cb = int function(
106 	const(git_diff_delta)* delta,
107 	float progress,
108 	void *payload);
109 
110 struct git_diff_hunk {
111 	int    old_start;
112 	int    old_lines;
113 	int    new_start;
114 	int    new_lines;
115 	size_t header_len;
116 	char[128] header;
117 }
118 
119 alias git_diff_hunk_cb = int function(
120 	const(git_diff_delta)* delta,
121 	const(git_diff_hunk)* hunk,
122 	void *payload);
123 
124 enum git_diff_line_t {
125 	GIT_DIFF_LINE_CONTEXT   = ' ',
126 	GIT_DIFF_LINE_ADDITION  = '+',
127 	GIT_DIFF_LINE_DELETION  = '-',
128 	GIT_DIFF_LINE_CONTEXT_EOFNL = '=',
129 	GIT_DIFF_LINE_ADD_EOFNL = '>',
130 	GIT_DIFF_LINE_DEL_EOFNL = '<',
131 	GIT_DIFF_LINE_FILE_HDR  = 'F',
132 	GIT_DIFF_LINE_HUNK_HDR  = 'H',
133 	GIT_DIFF_LINE_BINARY    = 'B'
134 }
135 
136 struct git_diff_line {
137 	char   origin;
138 	int    old_lineno;
139 	int    new_lineno;
140 	int    num_lines;
141 	size_t content_len;
142 	git_off_t content_offset;
143 	const(char)* content;
144 }
145 
146 alias git_diff_line_cb = int function(
147 	const(git_diff_delta)* delta,
148 	const(git_diff_hunk)* hunk,
149 	const(git_diff_line)* line,
150 	void *payload);
151 
152 enum git_diff_find_t {
153 	GIT_DIFF_FIND_RENAMES = (1u << 0),
154 	GIT_DIFF_FIND_RENAMES_FROM_REWRITES = (1u << 1),
155 	GIT_DIFF_FIND_COPIES = (1u << 2),
156 	GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED = (1u << 3),
157 	GIT_DIFF_FIND_REWRITES = (1u << 4),
158 	GIT_DIFF_BREAK_REWRITES = (1u << 5),
159 	GIT_DIFF_FIND_AND_BREAK_REWRITES =
160 		(GIT_DIFF_FIND_REWRITES | GIT_DIFF_BREAK_REWRITES),
161 	GIT_DIFF_FIND_FOR_UNTRACKED = (1u << 6),
162 	GIT_DIFF_FIND_ALL = (0x0ff),
163 	GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE = 0,
164 	GIT_DIFF_FIND_IGNORE_WHITESPACE = (1u << 12),
165 	GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE = (1u << 13),
166 	GIT_DIFF_FIND_EXACT_MATCH_ONLY = (1u << 14),
167 	GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY  = (1u << 15),
168 }
169 
170 struct git_diff_similarity_metric {
171 	int function(
172 		void **out_, const(git_diff_file)* file,
173 		const(char)* fullpath, void *payload) file_signature;
174 	int function(
175 		void **out_, const(git_diff_file)* file,
176 		const(char)* buf, size_t buflen, void *payload) buffer_signature;
177 	void function(void *sig, void *payload) free_signature;
178 	int function(int *score, void *siga, void *sigb, void *payload) similarity;
179 	void *payload;
180 }
181 
182 struct git_diff_find_options {
183 	uint version_ = GIT_DIFF_FIND_OPTIONS_VERSION;
184 	uint32_t flags;
185 	uint16_t rename_threshold;
186 	uint16_t rename_from_rewrite_threshold;
187 	uint16_t copy_threshold;
188 	uint16_t break_rewrite_threshold;
189 	size_t rename_limit;
190 	git_diff_similarity_metric *metric;
191 }
192 
193 enum GIT_DIFF_FIND_OPTIONS_VERSION = 1;
194 enum git_diff_find_options GIT_DIFF_FIND_OPTIONS_INIT = {GIT_DIFF_FIND_OPTIONS_VERSION};
195 
196 void git_diff_free(git_diff *diff);
197 int git_diff_tree_to_tree(
198 	git_diff **diff,
199 	git_repository *repo,
200 	git_tree *old_tree,
201 	git_tree *new_tree,
202 	const(git_diff_options)* opts);
203 int git_diff_tree_to_index(
204 	git_diff **diff,
205 	git_repository *repo,
206 	git_tree *old_tree,
207 	git_index *index,
208 	const(git_diff_options)* opts);
209 int git_diff_index_to_workdir(
210 	git_diff **diff,
211 	git_repository *repo,
212 	git_index *index,
213 	const(git_diff_options)* opts);
214 int git_diff_tree_to_workdir(
215 	git_diff **diff,
216 	git_repository *repo,
217 	git_tree *old_tree,
218 	const(git_diff_options)* opts);
219 int git_diff_tree_to_workdir_with_index(
220 	git_diff **diff,
221 	git_repository *repo,
222 	git_tree *old_tree,
223 	const(git_diff_options)* opts);
224 int git_diff_merge(
225 	git_diff *onto,
226 	const(git_diff)* from);
227 int git_diff_find_similar(
228 	git_diff *diff,
229 	const(git_diff_find_options)* options);
230 int git_diff_options_init(
231 	git_diff_options *options,
232 	uint version_);
233 size_t git_diff_num_deltas(const(git_diff)* diff);
234 size_t git_diff_num_deltas_of_type(
235 	const(git_diff)* diff, git_delta_t type);
236 const(git_diff_delta)* git_diff_get_delta(
237 	const(git_diff)* diff, size_t idx);
238 int git_diff_is_sorted_icase(const(git_diff)* diff);
239 int git_diff_foreach(
240 	git_diff *diff,
241 	git_diff_file_cb file_cb,
242 	git_diff_hunk_cb hunk_cb,
243 	git_diff_line_cb line_cb,
244 	void *payload);
245 char git_diff_status_char(git_delta_t status);
246 
247 enum git_diff_format_t {
248 	GIT_DIFF_FORMAT_PATCH        = 1u,
249 	GIT_DIFF_FORMAT_PATCH_HEADER = 2u,
250 	GIT_DIFF_FORMAT_RAW          = 3u,
251 	GIT_DIFF_FORMAT_NAME_ONLY    = 4u,
252 	GIT_DIFF_FORMAT_NAME_STATUS  = 5u,
253 }
254 
255 int git_diff_print(
256 	git_diff *diff,
257 	git_diff_format_t format,
258 	git_diff_line_cb print_cb,
259 	void *payload);
260 int git_diff_blobs(
261 	const(git_blob)* old_blob,
262 	const(char)* old_as_path,
263 	const(git_blob)* new_blob,
264 	const(char)* new_as_path,
265 	const(git_diff_options)* options,
266 	git_diff_file_cb file_cb,
267 	git_diff_hunk_cb hunk_cb,
268 	git_diff_line_cb line_cb,
269 	void *payload);
270 int git_diff_blob_to_buffer(
271 	const(git_blob)* old_blob,
272 	const(char)* old_as_path,
273 	const(char)* buffer,
274 	size_t buffer_len,
275 	const(char)* buffer_as_path,
276 	const(git_diff_options)* options,
277 	git_diff_file_cb file_cb,
278 	git_diff_hunk_cb hunk_cb,
279 	git_diff_line_cb line_cb,
280 	void *payload);