]>
Commit | Line | Data |
---|---|---|
af3feefa | 1 | #include "cache.h" |
cbd53a21 | 2 | #include "object-store.h" |
af3feefa | 3 | #include "commit.h" |
8e440259 | 4 | #include "blob.h" |
af3feefa JH |
5 | #include "diff.h" |
6 | #include "diffcore.h" | |
7 | #include "quote.h" | |
d9ea73e0 | 8 | #include "xdiff-interface.h" |
fa04ae0b | 9 | #include "xdiff/xmacros.h" |
91539833 | 10 | #include "log-tree.h" |
7dae8b21 | 11 | #include "refs.h" |
4d5f3471 | 12 | #include "userdiff.h" |
0041f09d | 13 | #include "sha1-array.h" |
53d00b39 | 14 | #include "revision.h" |
af3feefa | 15 | |
e09867f0 JK |
16 | static int compare_paths(const struct combine_diff_path *one, |
17 | const struct diff_filespec *two) | |
18 | { | |
19 | if (!S_ISDIR(one->mode) && !S_ISDIR(two->mode)) | |
20 | return strcmp(one->path, two->path); | |
21 | ||
22 | return base_name_compare(one->path, strlen(one->path), one->mode, | |
23 | two->path, strlen(two->path), two->mode); | |
24 | } | |
25 | ||
ea726d02 | 26 | static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr, int n, int num_parent) |
af3feefa JH |
27 | { |
28 | struct diff_queue_struct *q = &diff_queued_diff; | |
7b1004b0 | 29 | struct combine_diff_path *p, **tail = &curr; |
8518ff8f | 30 | int i, cmp; |
af3feefa JH |
31 | |
32 | if (!n) { | |
af3feefa JH |
33 | for (i = 0; i < q->nr; i++) { |
34 | int len; | |
35 | const char *path; | |
a976b0a5 | 36 | if (diff_unmodified_pair(q->queue[i])) |
af3feefa JH |
37 | continue; |
38 | path = q->queue[i]->two->path; | |
39 | len = strlen(path); | |
2454c962 | 40 | p = xmalloc(combine_diff_path_size(num_parent, len)); |
4b25d091 | 41 | p->path = (char *) &(p->parent[num_parent]); |
af3feefa JH |
42 | memcpy(p->path, path, len); |
43 | p->path[len] = 0; | |
af3feefa | 44 | p->next = NULL; |
2454c962 JH |
45 | memset(p->parent, 0, |
46 | sizeof(p->parent[0]) * num_parent); | |
47 | ||
a0d12c44 | 48 | oidcpy(&p->oid, &q->queue[i]->two->oid); |
2454c962 | 49 | p->mode = q->queue[i]->two->mode; |
a0d12c44 | 50 | oidcpy(&p->parent[n].oid, &q->queue[i]->one->oid); |
2454c962 | 51 | p->parent[n].mode = q->queue[i]->one->mode; |
d416df88 | 52 | p->parent[n].status = q->queue[i]->status; |
5290a0f8 JH |
53 | *tail = p; |
54 | tail = &p->next; | |
af3feefa | 55 | } |
7b1004b0 | 56 | return curr; |
af3feefa JH |
57 | } |
58 | ||
8518ff8f | 59 | /* |
7b1004b0 JH |
60 | * paths in curr (linked list) and q->queue[] (array) are |
61 | * both sorted in the tree order. | |
8518ff8f | 62 | */ |
8518ff8f | 63 | i = 0; |
7b1004b0 JH |
64 | while ((p = *tail) != NULL) { |
65 | cmp = ((i >= q->nr) | |
e09867f0 | 66 | ? -1 : compare_paths(p, q->queue[i]->two)); |
8518ff8f | 67 | |
8518ff8f | 68 | if (cmp < 0) { |
7b1004b0 JH |
69 | /* p->path not in q->queue[]; drop it */ |
70 | *tail = p->next; | |
71 | free(p); | |
af3feefa | 72 | continue; |
8518ff8f | 73 | } |
af3feefa | 74 | |
8518ff8f | 75 | if (cmp > 0) { |
7b1004b0 | 76 | /* q->queue[i] not in p->path; skip it */ |
8518ff8f KS |
77 | i++; |
78 | continue; | |
af3feefa | 79 | } |
8518ff8f | 80 | |
a0d12c44 | 81 | oidcpy(&p->parent[n].oid, &q->queue[i]->one->oid); |
8518ff8f KS |
82 | p->parent[n].mode = q->queue[i]->one->mode; |
83 | p->parent[n].status = q->queue[i]->status; | |
84 | ||
7b1004b0 | 85 | tail = &p->next; |
8518ff8f | 86 | i++; |
af3feefa JH |
87 | } |
88 | return curr; | |
89 | } | |
90 | ||
b469d8b6 | 91 | /* Lines lost from parent */ |
af3feefa | 92 | struct lline { |
99d32060 | 93 | struct lline *next, *prev; |
af3feefa JH |
94 | int len; |
95 | unsigned long parent_map; | |
96 | char line[FLEX_ARRAY]; | |
97 | }; | |
98 | ||
99d32060 AP |
99 | /* Lines lost from current parent (before coalescing) */ |
100 | struct plost { | |
101 | struct lline *lost_head, *lost_tail; | |
102 | int len; | |
103 | }; | |
104 | ||
b469d8b6 | 105 | /* Lines surviving in the merge result */ |
af3feefa | 106 | struct sline { |
99d32060 AP |
107 | /* Accumulated and coalesced lost lines */ |
108 | struct lline *lost; | |
109 | int lenlost; | |
110 | struct plost plost; | |
af3feefa JH |
111 | char *bol; |
112 | int len; | |
46dc9412 JH |
113 | /* bit 0 up to (N-1) are on if the parent has this line (i.e. |
114 | * we did not change it). | |
b469d8b6 | 115 | * bit N is used for "interesting" lines, including context. |
c86fbe53 | 116 | * bit (N+1) is used for "do not show deletion before this". |
b469d8b6 | 117 | */ |
af3feefa | 118 | unsigned long flag; |
f16706cc | 119 | unsigned long *p_lno; |
af3feefa JH |
120 | }; |
121 | ||
fa04ae0b AP |
122 | static int match_string_spaces(const char *line1, int len1, |
123 | const char *line2, int len2, | |
124 | long flags) | |
125 | { | |
126 | if (flags & XDF_WHITESPACE_FLAGS) { | |
127 | for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--); | |
128 | for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--); | |
129 | } | |
130 | ||
131 | if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE))) | |
132 | return (len1 == len2 && !memcmp(line1, line2, len1)); | |
133 | ||
134 | while (len1 > 0 && len2 > 0) { | |
135 | len1--; | |
136 | len2--; | |
137 | if (XDL_ISSPACE(line1[len1]) || XDL_ISSPACE(line2[len2])) { | |
138 | if ((flags & XDF_IGNORE_WHITESPACE_CHANGE) && | |
139 | (!XDL_ISSPACE(line1[len1]) || !XDL_ISSPACE(line2[len2]))) | |
140 | return 0; | |
141 | ||
142 | for (; len1 > 0 && XDL_ISSPACE(line1[len1]); len1--); | |
143 | for (; len2 > 0 && XDL_ISSPACE(line2[len2]); len2--); | |
144 | } | |
145 | if (line1[len1] != line2[len2]) | |
146 | return 0; | |
147 | } | |
148 | ||
149 | if (flags & XDF_IGNORE_WHITESPACE) { | |
150 | /* Consume remaining spaces */ | |
151 | for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--); | |
152 | for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--); | |
153 | } | |
154 | ||
155 | /* We matched full line1 and line2 */ | |
156 | if (!len1 && !len2) | |
157 | return 1; | |
158 | ||
159 | return 0; | |
160 | } | |
161 | ||
99d32060 AP |
162 | enum coalesce_direction { MATCH, BASE, NEW }; |
163 | ||
164 | /* Coalesce new lines into base by finding LCS */ | |
165 | static struct lline *coalesce_lines(struct lline *base, int *lenbase, | |
06fffa00 | 166 | struct lline *newline, int lennew, |
99d32060 | 167 | unsigned long parent, long flags) |
af3feefa | 168 | { |
99d32060 AP |
169 | int **lcs; |
170 | enum coalesce_direction **directions; | |
171 | struct lline *baseend, *newend = NULL; | |
172 | int i, j, origbaselen = *lenbase; | |
af3feefa | 173 | |
06fffa00 | 174 | if (newline == NULL) |
99d32060 AP |
175 | return base; |
176 | ||
177 | if (base == NULL) { | |
178 | *lenbase = lennew; | |
06fffa00 | 179 | return newline; |
99d32060 AP |
180 | } |
181 | ||
182 | /* | |
183 | * Coalesce new lines into base by finding the LCS | |
98e023de | 184 | * - Create the table to run dynamic programming |
99d32060 AP |
185 | * - Compute the LCS |
186 | * - Then reverse read the direction structure: | |
187 | * - If we have MATCH, assign parent to base flag, and consume | |
188 | * both baseend and newend | |
189 | * - Else if we have BASE, consume baseend | |
190 | * - Else if we have NEW, insert newend lline into base and | |
191 | * consume newend | |
192 | */ | |
50a6c8ef JK |
193 | lcs = xcalloc(st_add(origbaselen, 1), sizeof(int*)); |
194 | directions = xcalloc(st_add(origbaselen, 1), sizeof(enum coalesce_direction*)); | |
99d32060 | 195 | for (i = 0; i < origbaselen + 1; i++) { |
50a6c8ef JK |
196 | lcs[i] = xcalloc(st_add(lennew, 1), sizeof(int)); |
197 | directions[i] = xcalloc(st_add(lennew, 1), sizeof(enum coalesce_direction)); | |
99d32060 AP |
198 | directions[i][0] = BASE; |
199 | } | |
200 | for (j = 1; j < lennew + 1; j++) | |
201 | directions[0][j] = NEW; | |
202 | ||
203 | for (i = 1, baseend = base; i < origbaselen + 1; i++) { | |
06fffa00 | 204 | for (j = 1, newend = newline; j < lennew + 1; j++) { |
99d32060 AP |
205 | if (match_string_spaces(baseend->line, baseend->len, |
206 | newend->line, newend->len, flags)) { | |
207 | lcs[i][j] = lcs[i - 1][j - 1] + 1; | |
208 | directions[i][j] = MATCH; | |
209 | } else if (lcs[i][j - 1] >= lcs[i - 1][j]) { | |
210 | lcs[i][j] = lcs[i][j - 1]; | |
211 | directions[i][j] = NEW; | |
212 | } else { | |
213 | lcs[i][j] = lcs[i - 1][j]; | |
214 | directions[i][j] = BASE; | |
215 | } | |
216 | if (newend->next) | |
217 | newend = newend->next; | |
218 | } | |
219 | if (baseend->next) | |
220 | baseend = baseend->next; | |
221 | } | |
222 | ||
223 | for (i = 0; i < origbaselen + 1; i++) | |
224 | free(lcs[i]); | |
225 | free(lcs); | |
226 | ||
227 | /* At this point, baseend and newend point to the end of each lists */ | |
228 | i--; | |
229 | j--; | |
230 | while (i != 0 || j != 0) { | |
231 | if (directions[i][j] == MATCH) { | |
232 | baseend->parent_map |= 1<<parent; | |
233 | baseend = baseend->prev; | |
234 | newend = newend->prev; | |
235 | i--; | |
236 | j--; | |
237 | } else if (directions[i][j] == NEW) { | |
238 | struct lline *lline; | |
239 | ||
240 | lline = newend; | |
241 | /* Remove lline from new list and update newend */ | |
242 | if (lline->prev) | |
243 | lline->prev->next = lline->next; | |
244 | else | |
06fffa00 | 245 | newline = lline->next; |
99d32060 AP |
246 | if (lline->next) |
247 | lline->next->prev = lline->prev; | |
248 | ||
249 | newend = lline->prev; | |
250 | j--; | |
251 | ||
252 | /* Add lline to base list */ | |
253 | if (baseend) { | |
254 | lline->next = baseend->next; | |
255 | lline->prev = baseend; | |
256 | if (lline->prev) | |
257 | lline->prev->next = lline; | |
af3feefa | 258 | } |
99d32060 AP |
259 | else { |
260 | lline->next = base; | |
261 | base = lline; | |
262 | } | |
263 | (*lenbase)++; | |
264 | ||
265 | if (lline->next) | |
266 | lline->next->prev = lline; | |
267 | ||
268 | } else { | |
269 | baseend = baseend->prev; | |
270 | i--; | |
af3feefa JH |
271 | } |
272 | } | |
273 | ||
06fffa00 | 274 | newend = newline; |
99d32060 AP |
275 | while (newend) { |
276 | struct lline *lline = newend; | |
277 | newend = newend->next; | |
278 | free(lline); | |
279 | } | |
280 | ||
281 | for (i = 0; i < origbaselen + 1; i++) | |
282 | free(directions[i]); | |
283 | free(directions); | |
284 | ||
285 | return base; | |
286 | } | |
287 | ||
6afaf807 NTND |
288 | static char *grab_blob(struct repository *r, |
289 | const struct object_id *oid, unsigned int mode, | |
99d32060 AP |
290 | unsigned long *size, struct userdiff_driver *textconv, |
291 | const char *path) | |
292 | { | |
293 | char *blob; | |
294 | enum object_type type; | |
295 | ||
296 | if (S_ISGITLINK(mode)) { | |
0dc3b035 JK |
297 | struct strbuf buf = STRBUF_INIT; |
298 | strbuf_addf(&buf, "Subproject commit %s\n", oid_to_hex(oid)); | |
299 | *size = buf.len; | |
300 | blob = strbuf_detach(&buf, NULL); | |
1ff57c13 | 301 | } else if (is_null_oid(oid)) { |
99d32060 AP |
302 | /* deleted blob */ |
303 | *size = 0; | |
304 | return xcalloc(1, 1); | |
305 | } else if (textconv) { | |
306 | struct diff_filespec *df = alloc_filespec(path); | |
f9704c2d | 307 | fill_filespec(df, oid, 1, mode); |
6afaf807 | 308 | *size = fill_textconv(r, textconv, df, &blob); |
99d32060 AP |
309 | free_filespec(df); |
310 | } else { | |
b4f5aca4 | 311 | blob = read_object_file(oid, &type, size); |
99d32060 | 312 | if (type != OBJ_BLOB) |
1ff57c13 | 313 | die("object '%s' is not a blob!", oid_to_hex(oid)); |
99d32060 AP |
314 | } |
315 | return blob; | |
316 | } | |
317 | ||
318 | static void append_lost(struct sline *sline, int n, const char *line, int len) | |
319 | { | |
320 | struct lline *lline; | |
321 | unsigned long this_mask = (1UL<<n); | |
322 | if (line[len-1] == '\n') | |
323 | len--; | |
324 | ||
96ffc06f | 325 | FLEX_ALLOC_MEM(lline, line, line, len); |
af3feefa JH |
326 | lline->len = len; |
327 | lline->next = NULL; | |
99d32060 AP |
328 | lline->prev = sline->plost.lost_tail; |
329 | if (lline->prev) | |
330 | lline->prev->next = lline; | |
331 | else | |
332 | sline->plost.lost_head = lline; | |
333 | sline->plost.lost_tail = lline; | |
334 | sline->plost.len++; | |
af3feefa | 335 | lline->parent_map = this_mask; |
af3feefa JH |
336 | } |
337 | ||
f23fc773 | 338 | struct combine_diff_state { |
a0fd3146 JH |
339 | unsigned int lno; |
340 | int ob, on, nb, nn; | |
f23fc773 JH |
341 | unsigned long nmask; |
342 | int num_parent; | |
343 | int n; | |
344 | struct sline *sline; | |
345 | struct sline *lost_bucket; | |
346 | }; | |
347 | ||
0074c911 JK |
348 | static void consume_hunk(void *state_, |
349 | long ob, long on, | |
350 | long nb, long nn, | |
351 | const char *funcline, long funclen) | |
f23fc773 | 352 | { |
d9ea73e0 | 353 | struct combine_diff_state *state = state_; |
0074c911 JK |
354 | |
355 | state->ob = ob; | |
356 | state->on = on; | |
357 | state->nb = nb; | |
358 | state->nn = nn; | |
359 | state->lno = state->nb; | |
360 | if (state->nn == 0) { | |
361 | /* @@ -X,Y +N,0 @@ removed Y lines | |
362 | * that would have come *after* line N | |
363 | * in the result. Our lost buckets hang | |
364 | * to the line after the removed lines, | |
365 | * | |
366 | * Note that this is correct even when N == 0, | |
367 | * in which case the hunk removes the first | |
368 | * line in the file. | |
369 | */ | |
370 | state->lost_bucket = &state->sline[state->nb]; | |
371 | if (!state->nb) | |
372 | state->nb = 1; | |
373 | } else { | |
374 | state->lost_bucket = &state->sline[state->nb-1]; | |
f23fc773 | 375 | } |
0074c911 JK |
376 | if (!state->sline[state->nb-1].p_lno) |
377 | state->sline[state->nb-1].p_lno = | |
378 | xcalloc(state->num_parent, sizeof(unsigned long)); | |
379 | state->sline[state->nb-1].p_lno[state->n] = state->ob; | |
380 | } | |
381 | ||
382 | static void consume_line(void *state_, char *line, unsigned long len) | |
383 | { | |
384 | struct combine_diff_state *state = state_; | |
f23fc773 JH |
385 | if (!state->lost_bucket) |
386 | return; /* not in any hunk yet */ | |
387 | switch (line[0]) { | |
388 | case '-': | |
99d32060 | 389 | append_lost(state->lost_bucket, state->n, line+1, len-1); |
f23fc773 JH |
390 | break; |
391 | case '+': | |
392 | state->sline[state->lno-1].flag |= state->nmask; | |
393 | state->lno++; | |
394 | break; | |
395 | } | |
396 | } | |
397 | ||
6afaf807 NTND |
398 | static void combine_diff(struct repository *r, |
399 | const struct object_id *parent, unsigned int mode, | |
7dae8b21 | 400 | mmfile_t *result_file, |
2386c297 | 401 | struct sline *sline, unsigned int cnt, int n, |
0508fe53 JK |
402 | int num_parent, int result_deleted, |
403 | struct userdiff_driver *textconv, | |
fa04ae0b | 404 | const char *path, long flags) |
af3feefa | 405 | { |
f23fc773 | 406 | unsigned int p_lno, lno; |
f16706cc | 407 | unsigned long nmask = (1UL << n); |
f23fc773 JH |
408 | xpparam_t xpp; |
409 | xdemitconf_t xecfg; | |
410 | mmfile_t parent_file; | |
f23fc773 JH |
411 | struct combine_diff_state state; |
412 | unsigned long sz; | |
af3feefa | 413 | |
21798708 | 414 | if (result_deleted) |
4462731e JH |
415 | return; /* result deleted */ |
416 | ||
6afaf807 | 417 | parent_file.ptr = grab_blob(r, parent, mode, &sz, textconv, path); |
f23fc773 | 418 | parent_file.size = sz; |
9ccd0a88 | 419 | memset(&xpp, 0, sizeof(xpp)); |
fa04ae0b | 420 | xpp.flags = flags; |
30b25010 | 421 | memset(&xecfg, 0, sizeof(xecfg)); |
f23fc773 JH |
422 | memset(&state, 0, sizeof(state)); |
423 | state.nmask = nmask; | |
424 | state.sline = sline; | |
425 | state.lno = 1; | |
426 | state.num_parent = num_parent; | |
427 | state.n = n; | |
428 | ||
0074c911 JK |
429 | if (xdi_diff_outf(&parent_file, result_file, consume_hunk, |
430 | consume_line, &state, &xpp, &xecfg)) | |
3efb9880 | 431 | die("unable to generate combined diff for %s", |
11a458be | 432 | oid_to_hex(parent)); |
f23fc773 | 433 | free(parent_file.ptr); |
f16706cc JH |
434 | |
435 | /* Assign line numbers for this parent. | |
436 | * | |
437 | * sline[lno].p_lno[n] records the first line number | |
438 | * (counting from 1) for parent N if the final hunk display | |
439 | * started by showing sline[lno] (possibly showing the lost | |
440 | * lines attached to it first). | |
441 | */ | |
8a470ebf | 442 | for (lno = 0, p_lno = 1; lno <= cnt; lno++) { |
f16706cc JH |
443 | struct lline *ll; |
444 | sline[lno].p_lno[n] = p_lno; | |
445 | ||
99d32060 AP |
446 | /* Coalesce new lines */ |
447 | if (sline[lno].plost.lost_head) { | |
448 | struct sline *sl = &sline[lno]; | |
449 | sl->lost = coalesce_lines(sl->lost, &sl->lenlost, | |
450 | sl->plost.lost_head, | |
451 | sl->plost.len, n, flags); | |
452 | sl->plost.lost_head = sl->plost.lost_tail = NULL; | |
453 | sl->plost.len = 0; | |
454 | } | |
455 | ||
f16706cc | 456 | /* How many lines would this sline advance the p_lno? */ |
99d32060 | 457 | ll = sline[lno].lost; |
f16706cc JH |
458 | while (ll) { |
459 | if (ll->parent_map & nmask) | |
460 | p_lno++; /* '-' means parent had it */ | |
461 | ll = ll->next; | |
462 | } | |
8a470ebf | 463 | if (lno < cnt && !(sline[lno].flag & nmask)) |
f16706cc JH |
464 | p_lno++; /* no '+' means parent had it */ |
465 | } | |
466 | sline[lno].p_lno[n] = p_lno; /* trailer */ | |
af3feefa JH |
467 | } |
468 | ||
469 | static unsigned long context = 3; | |
470 | static char combine_marker = '@'; | |
471 | ||
472 | static int interesting(struct sline *sline, unsigned long all_mask) | |
473 | { | |
46dc9412 JH |
474 | /* If some parents lost lines here, or if we have added to |
475 | * some parent, it is interesting. | |
476 | */ | |
99d32060 | 477 | return ((sline->flag & all_mask) || sline->lost); |
af3feefa JH |
478 | } |
479 | ||
3ec1909f JH |
480 | static unsigned long adjust_hunk_tail(struct sline *sline, |
481 | unsigned long all_mask, | |
482 | unsigned long hunk_begin, | |
483 | unsigned long i) | |
484 | { | |
46dc9412 JH |
485 | /* i points at the first uninteresting line. If the last line |
486 | * of the hunk was interesting only because it has some | |
487 | * deletion, then it is not all that interesting for the | |
488 | * purpose of giving trailing context lines. This is because | |
489 | * we output '-' line and then unmodified sline[i-1] itself in | |
490 | * that case which gives us one extra context line. | |
3ec1909f | 491 | */ |
46dc9412 | 492 | if ((hunk_begin + 1 <= i) && !(sline[i-1].flag & all_mask)) |
3ec1909f JH |
493 | i--; |
494 | return i; | |
495 | } | |
496 | ||
46dc9412 JH |
497 | static unsigned long find_next(struct sline *sline, |
498 | unsigned long mark, | |
499 | unsigned long i, | |
500 | unsigned long cnt, | |
2386c297 | 501 | int look_for_uninteresting) |
3ec1909f | 502 | { |
46dc9412 JH |
503 | /* We have examined up to i-1 and are about to look at i. |
504 | * Find next interesting or uninteresting line. Here, | |
505 | * "interesting" does not mean interesting(), but marked by | |
506 | * the give_context() function below (i.e. it includes context | |
507 | * lines that are not interesting to interesting() function | |
508 | * that are surrounded by interesting() ones. | |
509 | */ | |
74065951 | 510 | while (i <= cnt) |
2386c297 | 511 | if (look_for_uninteresting |
46dc9412 JH |
512 | ? !(sline[i].flag & mark) |
513 | : (sline[i].flag & mark)) | |
3ec1909f JH |
514 | return i; |
515 | else | |
516 | i++; | |
74065951 | 517 | return i; |
3ec1909f JH |
518 | } |
519 | ||
520 | static int give_context(struct sline *sline, unsigned long cnt, int num_parent) | |
af3feefa JH |
521 | { |
522 | unsigned long all_mask = (1UL<<num_parent) - 1; | |
523 | unsigned long mark = (1UL<<num_parent); | |
c86fbe53 | 524 | unsigned long no_pre_delete = (2UL<<num_parent); |
af3feefa JH |
525 | unsigned long i; |
526 | ||
46dc9412 | 527 | /* Two groups of interesting lines may have a short gap of |
82e5a82f | 528 | * uninteresting lines. Connect such groups to give them a |
46dc9412 JH |
529 | * bit of context. |
530 | * | |
531 | * We first start from what the interesting() function says, | |
532 | * and mark them with "mark", and paint context lines with the | |
533 | * mark. So interesting() would still say false for such context | |
534 | * lines but they are treated as "interesting" in the end. | |
535 | */ | |
536 | i = find_next(sline, mark, 0, cnt, 0); | |
74065951 | 537 | if (cnt < i) |
3ec1909f JH |
538 | return 0; |
539 | ||
74065951 | 540 | while (i <= cnt) { |
3ec1909f JH |
541 | unsigned long j = (context < i) ? (i - context) : 0; |
542 | unsigned long k; | |
46dc9412 JH |
543 | |
544 | /* Paint a few lines before the first interesting line. */ | |
aac38571 MK |
545 | while (j < i) { |
546 | if (!(sline[j].flag & mark)) | |
547 | sline[j].flag |= no_pre_delete; | |
548 | sline[j++].flag |= mark; | |
549 | } | |
3ec1909f JH |
550 | |
551 | again: | |
46dc9412 JH |
552 | /* we know up to i is to be included. where does the |
553 | * next uninteresting one start? | |
554 | */ | |
555 | j = find_next(sline, mark, i, cnt, 1); | |
74065951 | 556 | if (cnt < j) |
3ec1909f JH |
557 | break; /* the rest are all interesting */ |
558 | ||
559 | /* lookahead context lines */ | |
46dc9412 | 560 | k = find_next(sline, mark, j, cnt, 0); |
3ec1909f JH |
561 | j = adjust_hunk_tail(sline, all_mask, i, j); |
562 | ||
563 | if (k < j + context) { | |
564 | /* k is interesting and [j,k) are not, but | |
565 | * paint them interesting because the gap is small. | |
566 | */ | |
567 | while (j < k) | |
af3feefa | 568 | sline[j++].flag |= mark; |
3ec1909f JH |
569 | i = k; |
570 | goto again; | |
af3feefa | 571 | } |
3ec1909f JH |
572 | |
573 | /* j is the first uninteresting line and there is | |
46dc9412 JH |
574 | * no overlap beyond it within context lines. Paint |
575 | * the trailing edge a bit. | |
3ec1909f JH |
576 | */ |
577 | i = k; | |
74065951 | 578 | k = (j + context < cnt+1) ? j + context : cnt+1; |
3ec1909f JH |
579 | while (j < k) |
580 | sline[j++].flag |= mark; | |
581 | } | |
582 | return 1; | |
583 | } | |
584 | ||
585 | static int make_hunks(struct sline *sline, unsigned long cnt, | |
586 | int num_parent, int dense) | |
587 | { | |
588 | unsigned long all_mask = (1UL<<num_parent) - 1; | |
589 | unsigned long mark = (1UL<<num_parent); | |
590 | unsigned long i; | |
591 | int has_interesting = 0; | |
592 | ||
74065951 | 593 | for (i = 0; i <= cnt; i++) { |
3ec1909f JH |
594 | if (interesting(&sline[i], all_mask)) |
595 | sline[i].flag |= mark; | |
596 | else | |
597 | sline[i].flag &= ~mark; | |
af3feefa | 598 | } |
d8f4790e | 599 | if (!dense) |
3ec1909f | 600 | return give_context(sline, cnt, num_parent); |
d8f4790e | 601 | |
263eee29 JH |
602 | /* Look at each hunk, and if we have changes from only one |
603 | * parent, or the changes are the same from all but one | |
604 | * parent, mark that uninteresting. | |
d8f4790e JH |
605 | */ |
606 | i = 0; | |
74065951 | 607 | while (i <= cnt) { |
3ec1909f | 608 | unsigned long j, hunk_begin, hunk_end; |
bf1c32bd | 609 | unsigned long same_diff; |
74065951 | 610 | while (i <= cnt && !(sline[i].flag & mark)) |
d8f4790e | 611 | i++; |
74065951 | 612 | if (cnt < i) |
d8f4790e | 613 | break; /* No more interesting hunks */ |
3ec1909f | 614 | hunk_begin = i; |
74065951 | 615 | for (j = i + 1; j <= cnt; j++) { |
3ec1909f JH |
616 | if (!(sline[j].flag & mark)) { |
617 | /* Look beyond the end to see if there | |
618 | * is an interesting line after this | |
619 | * hunk within context span. | |
620 | */ | |
621 | unsigned long la; /* lookahead */ | |
622 | int contin = 0; | |
623 | la = adjust_hunk_tail(sline, all_mask, | |
624 | hunk_begin, j); | |
74065951 JH |
625 | la = (la + context < cnt + 1) ? |
626 | (la + context) : cnt + 1; | |
e5e9b565 | 627 | while (la && j <= --la) { |
3ec1909f JH |
628 | if (sline[la].flag & mark) { |
629 | contin = 1; | |
630 | break; | |
631 | } | |
632 | } | |
633 | if (!contin) | |
634 | break; | |
635 | j = la; | |
636 | } | |
637 | } | |
638 | hunk_end = j; | |
639 | ||
bf1c32bd | 640 | /* [i..hunk_end) are interesting. Now is it really |
fd4b1d21 JH |
641 | * interesting? We check if there are only two versions |
642 | * and the result matches one of them. That is, we look | |
643 | * at: | |
644 | * (+) line, which records lines added to which parents; | |
645 | * this line appears in the result. | |
646 | * (-) line, which records from what parents the line | |
647 | * was removed; this line does not appear in the result. | |
648 | * then check the set of parents the result has difference | |
649 | * from, from all lines. If there are lines that has | |
650 | * different set of parents that the result has differences | |
651 | * from, that means we have more than two versions. | |
652 | * | |
653 | * Even when we have only two versions, if the result does | |
654 | * not match any of the parents, the it should be considered | |
655 | * interesting. In such a case, we would have all '+' line. | |
656 | * After passing the above "two versions" test, that would | |
657 | * appear as "the same set of parents" to be "all parents". | |
d8f4790e | 658 | */ |
bf1c32bd JH |
659 | same_diff = 0; |
660 | has_interesting = 0; | |
661 | for (j = i; j < hunk_end && !has_interesting; j++) { | |
46dc9412 | 662 | unsigned long this_diff = sline[j].flag & all_mask; |
99d32060 | 663 | struct lline *ll = sline[j].lost; |
bf1c32bd JH |
664 | if (this_diff) { |
665 | /* This has some changes. Is it the | |
666 | * same as others? | |
667 | */ | |
668 | if (!same_diff) | |
669 | same_diff = this_diff; | |
670 | else if (same_diff != this_diff) { | |
671 | has_interesting = 1; | |
672 | break; | |
673 | } | |
674 | } | |
675 | while (ll && !has_interesting) { | |
676 | /* Lost this line from these parents; | |
677 | * who are they? Are they the same? | |
678 | */ | |
679 | this_diff = ll->parent_map; | |
680 | if (!same_diff) | |
681 | same_diff = this_diff; | |
682 | else if (same_diff != this_diff) { | |
683 | has_interesting = 1; | |
684 | } | |
685 | ll = ll->next; | |
686 | } | |
d8f4790e | 687 | } |
bf1c32bd | 688 | |
fd4b1d21 | 689 | if (!has_interesting && same_diff != all_mask) { |
d8f4790e | 690 | /* This hunk is not that interesting after all */ |
3ec1909f | 691 | for (j = hunk_begin; j < hunk_end; j++) |
d8f4790e JH |
692 | sline[j].flag &= ~mark; |
693 | } | |
694 | i = hunk_end; | |
695 | } | |
3ec1909f JH |
696 | |
697 | has_interesting = give_context(sline, cnt, num_parent); | |
8828cdcb | 698 | return has_interesting; |
af3feefa JH |
699 | } |
700 | ||
3b0f5e88 | 701 | static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, int n, unsigned long null_context) |
f16706cc JH |
702 | { |
703 | l0 = sline[l0].p_lno[n]; | |
704 | l1 = sline[l1].p_lno[n]; | |
3b0f5e88 | 705 | printf(" -%lu,%lu", l0, l1-l0-null_context); |
f16706cc JH |
706 | } |
707 | ||
d5f6a01a JH |
708 | static int hunk_comment_line(const char *bol) |
709 | { | |
7a8ac59f JH |
710 | int ch; |
711 | ||
712 | if (!bol) | |
713 | return 0; | |
714 | ch = *bol & 0xff; | |
d5f6a01a JH |
715 | return (isalpha(ch) || ch == '_' || ch == '$'); |
716 | } | |
717 | ||
39280970 JH |
718 | static void show_line_to_eol(const char *line, int len, const char *reset) |
719 | { | |
720 | int saw_cr_at_eol = 0; | |
721 | if (len < 0) | |
722 | len = strlen(line); | |
723 | saw_cr_at_eol = (len && line[len-1] == '\r'); | |
724 | ||
725 | printf("%.*s%s%s\n", len - saw_cr_at_eol, line, | |
726 | reset, | |
727 | saw_cr_at_eol ? "\r" : ""); | |
728 | } | |
729 | ||
41ee2ad6 JK |
730 | static void dump_sline(struct sline *sline, const char *line_prefix, |
731 | unsigned long cnt, int num_parent, | |
21798708 | 732 | int use_color, int result_deleted) |
af3feefa JH |
733 | { |
734 | unsigned long mark = (1UL<<num_parent); | |
c86fbe53 | 735 | unsigned long no_pre_delete = (2UL<<num_parent); |
af3feefa | 736 | int i; |
f16706cc | 737 | unsigned long lno = 0; |
567a03d1 | 738 | const char *c_frag = diff_get_color(use_color, DIFF_FRAGINFO); |
89cb73a1 | 739 | const char *c_func = diff_get_color(use_color, DIFF_FUNCINFO); |
567a03d1 JH |
740 | const char *c_new = diff_get_color(use_color, DIFF_FILE_NEW); |
741 | const char *c_old = diff_get_color(use_color, DIFF_FILE_OLD); | |
8dbf3eb6 | 742 | const char *c_context = diff_get_color(use_color, DIFF_CONTEXT); |
567a03d1 | 743 | const char *c_reset = diff_get_color(use_color, DIFF_RESET); |
af3feefa | 744 | |
21798708 | 745 | if (result_deleted) |
4462731e JH |
746 | return; /* result deleted */ |
747 | ||
af3feefa | 748 | while (1) { |
8bc7574b JH |
749 | unsigned long hunk_end; |
750 | unsigned long rlines; | |
d5f6a01a | 751 | const char *hunk_comment = NULL; |
3b0f5e88 | 752 | unsigned long null_context = 0; |
d5f6a01a JH |
753 | |
754 | while (lno <= cnt && !(sline[lno].flag & mark)) { | |
755 | if (hunk_comment_line(sline[lno].bol)) | |
756 | hunk_comment = sline[lno].bol; | |
af3feefa | 757 | lno++; |
d5f6a01a | 758 | } |
8a470ebf | 759 | if (cnt < lno) |
af3feefa | 760 | break; |
8a470ebf | 761 | else { |
74065951 | 762 | for (hunk_end = lno + 1; hunk_end <= cnt; hunk_end++) |
8a470ebf JH |
763 | if (!(sline[hunk_end].flag & mark)) |
764 | break; | |
765 | } | |
74065951 JH |
766 | rlines = hunk_end - lno; |
767 | if (cnt < hunk_end) | |
768 | rlines--; /* pointing at the last delete hunk */ | |
3b0f5e88 JH |
769 | |
770 | if (!context) { | |
771 | /* | |
772 | * Even when running with --unified=0, all | |
773 | * lines in the hunk needs to be processed in | |
774 | * the loop below in order to show the | |
775 | * deletion recorded in lost_head. However, | |
776 | * we do not want to show the resulting line | |
777 | * with all blank context markers in such a | |
778 | * case. Compensate. | |
779 | */ | |
780 | unsigned long j; | |
781 | for (j = lno; j < hunk_end; j++) | |
782 | if (!(sline[j].flag & (mark-1))) | |
783 | null_context++; | |
784 | rlines -= null_context; | |
785 | } | |
786 | ||
41ee2ad6 | 787 | printf("%s%s", line_prefix, c_frag); |
af3feefa | 788 | for (i = 0; i <= num_parent; i++) putchar(combine_marker); |
f16706cc | 789 | for (i = 0; i < num_parent; i++) |
3b0f5e88 | 790 | show_parent_lno(sline, lno, hunk_end, i, null_context); |
74065951 | 791 | printf(" +%lu,%lu ", lno+1, rlines); |
af3feefa | 792 | for (i = 0; i <= num_parent; i++) putchar(combine_marker); |
d5f6a01a JH |
793 | |
794 | if (hunk_comment) { | |
795 | int comment_end = 0; | |
796 | for (i = 0; i < 40; i++) { | |
797 | int ch = hunk_comment[i] & 0xff; | |
798 | if (!ch || ch == '\n') | |
799 | break; | |
800 | if (!isspace(ch)) | |
801 | comment_end = i; | |
802 | } | |
803 | if (comment_end) | |
89cb73a1 | 804 | printf("%s%s %s%s", c_reset, |
8dbf3eb6 | 805 | c_context, c_reset, |
89cb73a1 | 806 | c_func); |
d5f6a01a JH |
807 | for (i = 0; i < comment_end; i++) |
808 | putchar(hunk_comment[i]); | |
809 | } | |
810 | ||
567a03d1 | 811 | printf("%s\n", c_reset); |
af3feefa JH |
812 | while (lno < hunk_end) { |
813 | struct lline *ll; | |
814 | int j; | |
46dc9412 | 815 | unsigned long p_mask; |
fd13b21f | 816 | struct sline *sl = &sline[lno++]; |
99d32060 | 817 | ll = (sl->flag & no_pre_delete) ? NULL : sl->lost; |
af3feefa | 818 | while (ll) { |
41ee2ad6 | 819 | printf("%s%s", line_prefix, c_old); |
af3feefa JH |
820 | for (j = 0; j < num_parent; j++) { |
821 | if (ll->parent_map & (1UL<<j)) | |
822 | putchar('-'); | |
823 | else | |
824 | putchar(' '); | |
825 | } | |
39280970 | 826 | show_line_to_eol(ll->line, -1, c_reset); |
af3feefa JH |
827 | ll = ll->next; |
828 | } | |
74065951 | 829 | if (cnt < lno) |
8a470ebf | 830 | break; |
46dc9412 | 831 | p_mask = 1; |
41ee2ad6 | 832 | fputs(line_prefix, stdout); |
3b0f5e88 JH |
833 | if (!(sl->flag & (mark-1))) { |
834 | /* | |
835 | * This sline was here to hang the | |
836 | * lost lines in front of it. | |
837 | */ | |
838 | if (!context) | |
839 | continue; | |
8dbf3eb6 | 840 | fputs(c_context, stdout); |
3b0f5e88 | 841 | } |
567a03d1 JH |
842 | else |
843 | fputs(c_new, stdout); | |
af3feefa | 844 | for (j = 0; j < num_parent; j++) { |
46dc9412 | 845 | if (p_mask & sl->flag) |
af3feefa | 846 | putchar('+'); |
46dc9412 JH |
847 | else |
848 | putchar(' '); | |
849 | p_mask <<= 1; | |
af3feefa | 850 | } |
39280970 | 851 | show_line_to_eol(sl->bol, sl->len, c_reset); |
af3feefa JH |
852 | } |
853 | } | |
854 | } | |
855 | ||
3c39e9bd JH |
856 | static void reuse_combine_diff(struct sline *sline, unsigned long cnt, |
857 | int i, int j) | |
858 | { | |
859 | /* We have already examined parent j and we know parent i | |
860 | * and parent j are the same, so reuse the combined result | |
861 | * of parent j for parent i. | |
862 | */ | |
863 | unsigned long lno, imask, jmask; | |
864 | imask = (1UL<<i); | |
865 | jmask = (1UL<<j); | |
866 | ||
8a470ebf | 867 | for (lno = 0; lno <= cnt; lno++) { |
99d32060 | 868 | struct lline *ll = sline->lost; |
f16706cc | 869 | sline->p_lno[i] = sline->p_lno[j]; |
3c39e9bd JH |
870 | while (ll) { |
871 | if (ll->parent_map & jmask) | |
872 | ll->parent_map |= imask; | |
873 | ll = ll->next; | |
874 | } | |
46dc9412 JH |
875 | if (sline->flag & jmask) |
876 | sline->flag |= imask; | |
3c39e9bd JH |
877 | sline++; |
878 | } | |
4462731e JH |
879 | /* the overall size of the file (sline[cnt]) */ |
880 | sline->p_lno[i] = sline->p_lno[j]; | |
3c39e9bd JH |
881 | } |
882 | ||
462a15bc JH |
883 | static void dump_quoted_path(const char *head, |
884 | const char *prefix, | |
885 | const char *path, | |
41ee2ad6 | 886 | const char *line_prefix, |
567a03d1 | 887 | const char *c_meta, const char *c_reset) |
eab144ac | 888 | { |
462a15bc JH |
889 | static struct strbuf buf = STRBUF_INIT; |
890 | ||
891 | strbuf_reset(&buf); | |
41ee2ad6 | 892 | strbuf_addstr(&buf, line_prefix); |
462a15bc JH |
893 | strbuf_addstr(&buf, c_meta); |
894 | strbuf_addstr(&buf, head); | |
d5625091 | 895 | quote_two_c_style(&buf, prefix, path, 0); |
462a15bc JH |
896 | strbuf_addstr(&buf, c_reset); |
897 | puts(buf.buf); | |
eab144ac LT |
898 | } |
899 | ||
7c978a06 JK |
900 | static void show_combined_header(struct combine_diff_path *elem, |
901 | int num_parent, | |
902 | int dense, | |
903 | struct rev_info *rev, | |
41ee2ad6 | 904 | const char *line_prefix, |
4d5f3471 JK |
905 | int mode_differs, |
906 | int show_file_header) | |
7c978a06 JK |
907 | { |
908 | struct diff_options *opt = &rev->diffopt; | |
0d1e0e78 | 909 | int abbrev = opt->flags.full_index ? GIT_SHA1_HEXSZ : DEFAULT_ABBREV; |
7c978a06 JK |
910 | const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/"; |
911 | const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/"; | |
f1c96261 JK |
912 | const char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO); |
913 | const char *c_reset = diff_get_color_opt(opt, DIFF_RESET); | |
7c978a06 JK |
914 | const char *abb; |
915 | int added = 0; | |
916 | int deleted = 0; | |
917 | int i; | |
918 | ||
919 | if (rev->loginfo && !rev->no_commit_id) | |
920 | show_log(rev); | |
921 | ||
922 | dump_quoted_path(dense ? "diff --cc " : "diff --combined ", | |
41ee2ad6 JK |
923 | "", elem->path, line_prefix, c_meta, c_reset); |
924 | printf("%s%sindex ", line_prefix, c_meta); | |
7c978a06 | 925 | for (i = 0; i < num_parent; i++) { |
aab9583f | 926 | abb = find_unique_abbrev(&elem->parent[i].oid, |
7c978a06 JK |
927 | abbrev); |
928 | printf("%s%s", i ? "," : "", abb); | |
929 | } | |
aab9583f | 930 | abb = find_unique_abbrev(&elem->oid, abbrev); |
7c978a06 JK |
931 | printf("..%s%s\n", abb, c_reset); |
932 | ||
933 | if (mode_differs) { | |
934 | deleted = !elem->mode; | |
935 | ||
936 | /* We say it was added if nobody had it */ | |
937 | added = !deleted; | |
938 | for (i = 0; added && i < num_parent; i++) | |
939 | if (elem->parent[i].status != | |
940 | DIFF_STATUS_ADDED) | |
941 | added = 0; | |
942 | if (added) | |
41ee2ad6 JK |
943 | printf("%s%snew file mode %06o", |
944 | line_prefix, c_meta, elem->mode); | |
7c978a06 JK |
945 | else { |
946 | if (deleted) | |
41ee2ad6 JK |
947 | printf("%s%sdeleted file ", |
948 | line_prefix, c_meta); | |
7c978a06 JK |
949 | printf("mode "); |
950 | for (i = 0; i < num_parent; i++) { | |
951 | printf("%s%06o", i ? "," : "", | |
952 | elem->parent[i].mode); | |
953 | } | |
954 | if (elem->mode) | |
955 | printf("..%06o", elem->mode); | |
956 | } | |
957 | printf("%s\n", c_reset); | |
958 | } | |
959 | ||
4d5f3471 JK |
960 | if (!show_file_header) |
961 | return; | |
962 | ||
7c978a06 JK |
963 | if (added) |
964 | dump_quoted_path("--- ", "", "/dev/null", | |
41ee2ad6 | 965 | line_prefix, c_meta, c_reset); |
7c978a06 JK |
966 | else |
967 | dump_quoted_path("--- ", a_prefix, elem->path, | |
41ee2ad6 | 968 | line_prefix, c_meta, c_reset); |
7c978a06 JK |
969 | if (deleted) |
970 | dump_quoted_path("+++ ", "", "/dev/null", | |
41ee2ad6 | 971 | line_prefix, c_meta, c_reset); |
7c978a06 JK |
972 | else |
973 | dump_quoted_path("+++ ", b_prefix, elem->path, | |
41ee2ad6 | 974 | line_prefix, c_meta, c_reset); |
7c978a06 JK |
975 | } |
976 | ||
89b0c4b5 | 977 | static void show_patch_diff(struct combine_diff_path *elem, int num_parent, |
99694544 JH |
978 | int dense, int working_tree_file, |
979 | struct rev_info *rev) | |
af3feefa | 980 | { |
91539833 | 981 | struct diff_options *opt = &rev->diffopt; |
f23fc773 | 982 | unsigned long result_size, cnt, lno; |
21798708 | 983 | int result_deleted = 0; |
310f8b5b | 984 | char *result, *cp; |
af3feefa | 985 | struct sline *sline; /* survived lines */ |
2454c962 | 986 | int mode_differs = 0; |
89b0c4b5 | 987 | int i, show_hunks; |
f23fc773 | 988 | mmfile_t result_file; |
4d5f3471 | 989 | struct userdiff_driver *userdiff; |
0508fe53 | 990 | struct userdiff_driver *textconv = NULL; |
4d5f3471 | 991 | int is_binary; |
41ee2ad6 | 992 | const char *line_prefix = diff_line_prefix(opt); |
af3feefa | 993 | |
ee1e5412 | 994 | context = opt->context; |
acd00ea0 | 995 | userdiff = userdiff_find_by_path(opt->repo->index, elem->path); |
4d5f3471 JK |
996 | if (!userdiff) |
997 | userdiff = userdiff_find_by_name("default"); | |
0d1e0e78 | 998 | if (opt->flags.allow_textconv) |
0508fe53 | 999 | textconv = userdiff_get_textconv(userdiff); |
a5a818ee | 1000 | |
af3feefa | 1001 | /* Read the result of merge first */ |
f23fc773 | 1002 | if (!working_tree_file) |
6afaf807 | 1003 | result = grab_blob(opt->repo, &elem->oid, elem->mode, &result_size, |
0508fe53 | 1004 | textconv, elem->path); |
ea726d02 | 1005 | else { |
9843a1f6 | 1006 | /* Used by diff-tree to read from the working tree */ |
ea726d02 | 1007 | struct stat st; |
4fc970c4 JH |
1008 | int fd = -1; |
1009 | ||
1010 | if (lstat(elem->path, &st) < 0) | |
1011 | goto deleted_file; | |
1012 | ||
1013 | if (S_ISLNK(st.st_mode)) { | |
912342d9 JH |
1014 | struct strbuf buf = STRBUF_INIT; |
1015 | ||
1016 | if (strbuf_readlink(&buf, elem->path, st.st_size) < 0) { | |
4b94ec9b | 1017 | error_errno("readlink(%s)", elem->path); |
4fc970c4 JH |
1018 | return; |
1019 | } | |
912342d9 JH |
1020 | result_size = buf.len; |
1021 | result = strbuf_detach(&buf, NULL); | |
4fc970c4 | 1022 | elem->mode = canon_mode(st.st_mode); |
7dae8b21 | 1023 | } else if (S_ISDIR(st.st_mode)) { |
1ff57c13 | 1024 | struct object_id oid; |
a98e6101 | 1025 | if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0) |
6afaf807 NTND |
1026 | result = grab_blob(opt->repo, &elem->oid, |
1027 | elem->mode, &result_size, | |
1028 | NULL, NULL); | |
7dae8b21 | 1029 | else |
6afaf807 | 1030 | result = grab_blob(opt->repo, &oid, elem->mode, |
0508fe53 JK |
1031 | &result_size, NULL, NULL); |
1032 | } else if (textconv) { | |
1033 | struct diff_filespec *df = alloc_filespec(elem->path); | |
f9704c2d | 1034 | fill_filespec(df, &null_oid, 0, st.st_mode); |
6afaf807 | 1035 | result_size = fill_textconv(opt->repo, textconv, df, &result); |
0508fe53 | 1036 | free_filespec(df); |
91fcbcbd | 1037 | } else if (0 <= (fd = open(elem->path, O_RDONLY))) { |
dc49cd76 | 1038 | size_t len = xsize_t(st.st_size); |
c697ad14 | 1039 | ssize_t done; |
a249a9b5 | 1040 | int is_file, i; |
ea726d02 | 1041 | |
1b0c7174 | 1042 | elem->mode = canon_mode(st.st_mode); |
a249a9b5 JS |
1043 | /* if symlinks don't work, assume symlink if all parents |
1044 | * are symlinks | |
1045 | */ | |
1046 | is_file = has_symlinks; | |
1047 | for (i = 0; !is_file && i < num_parent; i++) | |
1048 | is_file = !S_ISLNK(elem->parent[i].mode); | |
1049 | if (!is_file) | |
1050 | elem->mode = canon_mode(S_IFLNK); | |
1051 | ||
f23fc773 | 1052 | result_size = len; |
3733e694 | 1053 | result = xmallocz(len); |
c697ad14 HO |
1054 | |
1055 | done = read_in_full(fd, result, len); | |
1056 | if (done < 0) | |
0721c314 | 1057 | die_errno("read error '%s'", elem->path); |
c697ad14 HO |
1058 | else if (done < len) |
1059 | die("early EOF '%s'", elem->path); | |
1060 | ||
5e568f9e AG |
1061 | /* If not a fake symlink, apply filters, e.g. autocrlf */ |
1062 | if (is_file) { | |
f285a2d7 | 1063 | struct strbuf buf = STRBUF_INIT; |
5e568f9e | 1064 | |
0734f209 NTND |
1065 | if (convert_to_git(rev->diffopt.repo->index, |
1066 | elem->path, result, len, &buf, global_conv_flags_eol)) { | |
5e568f9e AG |
1067 | free(result); |
1068 | result = strbuf_detach(&buf, &len); | |
1069 | result_size = len; | |
1070 | } | |
1071 | } | |
ea726d02 JH |
1072 | } |
1073 | else { | |
4fc970c4 | 1074 | deleted_file: |
21798708 | 1075 | result_deleted = 1; |
f23fc773 | 1076 | result_size = 0; |
713a11fc | 1077 | elem->mode = 0; |
28f75818 | 1078 | result = xcalloc(1, 1); |
ea726d02 | 1079 | } |
4fc970c4 | 1080 | |
ea726d02 JH |
1081 | if (0 <= fd) |
1082 | close(fd); | |
1083 | } | |
af3feefa | 1084 | |
c95b99bb JK |
1085 | for (i = 0; i < num_parent; i++) { |
1086 | if (elem->parent[i].mode != elem->mode) { | |
1087 | mode_differs = 1; | |
1088 | break; | |
1089 | } | |
1090 | } | |
1091 | ||
0508fe53 JK |
1092 | if (textconv) |
1093 | is_binary = 0; | |
1094 | else if (userdiff->binary != -1) | |
4d5f3471 JK |
1095 | is_binary = userdiff->binary; |
1096 | else { | |
1097 | is_binary = buffer_is_binary(result, result_size); | |
1098 | for (i = 0; !is_binary && i < num_parent; i++) { | |
1099 | char *buf; | |
1100 | unsigned long size; | |
6afaf807 NTND |
1101 | buf = grab_blob(opt->repo, |
1102 | &elem->parent[i].oid, | |
4d5f3471 | 1103 | elem->parent[i].mode, |
0508fe53 | 1104 | &size, NULL, NULL); |
4d5f3471 JK |
1105 | if (buffer_is_binary(buf, size)) |
1106 | is_binary = 1; | |
1107 | free(buf); | |
1108 | } | |
1109 | } | |
1110 | if (is_binary) { | |
1111 | show_combined_header(elem, num_parent, dense, rev, | |
41ee2ad6 | 1112 | line_prefix, mode_differs, 0); |
4d5f3471 JK |
1113 | printf("Binary files differ\n"); |
1114 | free(result); | |
1115 | return; | |
1116 | } | |
1117 | ||
2386c297 | 1118 | for (cnt = 0, cp = result; cp < result + result_size; cp++) { |
af3feefa JH |
1119 | if (*cp == '\n') |
1120 | cnt++; | |
1121 | } | |
f23fc773 | 1122 | if (result_size && result[result_size-1] != '\n') |
af3feefa JH |
1123 | cnt++; /* incomplete line */ |
1124 | ||
50a6c8ef | 1125 | sline = xcalloc(st_add(cnt, 2), sizeof(*sline)); |
af3feefa | 1126 | sline[0].bol = result; |
2386c297 | 1127 | for (lno = 0, cp = result; cp < result + result_size; cp++) { |
af3feefa JH |
1128 | if (*cp == '\n') { |
1129 | sline[lno].len = cp - sline[lno].bol; | |
af3feefa JH |
1130 | lno++; |
1131 | if (lno < cnt) | |
1132 | sline[lno].bol = cp + 1; | |
1133 | } | |
1134 | } | |
f23fc773 JH |
1135 | if (result_size && result[result_size-1] != '\n') |
1136 | sline[cnt-1].len = result_size - (sline[cnt-1].bol - result); | |
1137 | ||
1138 | result_file.ptr = result; | |
1139 | result_file.size = result_size; | |
af3feefa | 1140 | |
8a470ebf JH |
1141 | /* Even p_lno[cnt+1] is valid -- that is for the end line number |
1142 | * for deletion hunk at the end. | |
1143 | */ | |
50a6c8ef | 1144 | sline[0].p_lno = xcalloc(st_mult(st_add(cnt, 2), num_parent), sizeof(unsigned long)); |
8a470ebf | 1145 | for (lno = 0; lno <= cnt; lno++) |
f16706cc JH |
1146 | sline[lno+1].p_lno = sline[lno].p_lno + num_parent; |
1147 | ||
3c39e9bd JH |
1148 | for (i = 0; i < num_parent; i++) { |
1149 | int j; | |
1150 | for (j = 0; j < i; j++) { | |
4a7e27e9 JK |
1151 | if (oideq(&elem->parent[i].oid, |
1152 | &elem->parent[j].oid)) { | |
3c39e9bd JH |
1153 | reuse_combine_diff(sline, cnt, i, j); |
1154 | break; | |
1155 | } | |
1156 | } | |
1157 | if (i <= j) | |
6afaf807 NTND |
1158 | combine_diff(opt->repo, |
1159 | &elem->parent[i].oid, | |
7dae8b21 JH |
1160 | elem->parent[i].mode, |
1161 | &result_file, sline, | |
0508fe53 | 1162 | cnt, i, num_parent, result_deleted, |
fa04ae0b | 1163 | textconv, elem->path, opt->xdl_opts); |
3c39e9bd | 1164 | } |
af3feefa | 1165 | |
8828cdcb | 1166 | show_hunks = make_hunks(sline, cnt, num_parent, dense); |
af3feefa | 1167 | |
713a11fc | 1168 | if (show_hunks || mode_differs || working_tree_file) { |
7c978a06 | 1169 | show_combined_header(elem, num_parent, dense, rev, |
41ee2ad6 JK |
1170 | line_prefix, mode_differs, 1); |
1171 | dump_sline(sline, line_prefix, cnt, num_parent, | |
f1c96261 | 1172 | opt->use_color, result_deleted); |
8828cdcb | 1173 | } |
af3feefa JH |
1174 | free(result); |
1175 | ||
2386c297 | 1176 | for (lno = 0; lno < cnt; lno++) { |
99d32060 AP |
1177 | if (sline[lno].lost) { |
1178 | struct lline *ll = sline[lno].lost; | |
af3feefa JH |
1179 | while (ll) { |
1180 | struct lline *tmp = ll; | |
1181 | ll = ll->next; | |
1182 | free(tmp); | |
1183 | } | |
1184 | } | |
1185 | } | |
46dc9412 | 1186 | free(sline[0].p_lno); |
af3feefa JH |
1187 | free(sline); |
1188 | } | |
1189 | ||
91539833 | 1190 | static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct rev_info *rev) |
ee638024 | 1191 | { |
91539833 | 1192 | struct diff_options *opt = &rev->diffopt; |
77667051 | 1193 | int line_termination, inter_name_termination, i; |
41ee2ad6 | 1194 | const char *line_prefix = diff_line_prefix(opt); |
ee638024 LT |
1195 | |
1196 | line_termination = opt->line_termination; | |
1197 | inter_name_termination = '\t'; | |
1198 | if (!line_termination) | |
1199 | inter_name_termination = 0; | |
1200 | ||
44152787 | 1201 | if (rev->loginfo && !rev->no_commit_id) |
02865655 | 1202 | show_log(rev); |
ee638024 | 1203 | |
a1d68bea | 1204 | |
c6744349 | 1205 | if (opt->output_format & DIFF_FORMAT_RAW) { |
41ee2ad6 | 1206 | printf("%s", line_prefix); |
a1d68bea | 1207 | |
77667051 JH |
1208 | /* As many colons as there are parents */ |
1209 | for (i = 0; i < num_parent; i++) | |
1210 | putchar(':'); | |
0a798076 JH |
1211 | |
1212 | /* Show the modes */ | |
77667051 JH |
1213 | for (i = 0; i < num_parent; i++) |
1214 | printf("%06o ", p->parent[i].mode); | |
1215 | printf("%06o", p->mode); | |
0a798076 JH |
1216 | |
1217 | /* Show sha1's */ | |
1218 | for (i = 0; i < num_parent; i++) | |
d6cece51 | 1219 | printf(" %s", diff_aligned_abbrev(&p->parent[i].oid, |
d5e3b01e | 1220 | opt->abbrev)); |
d6cece51 | 1221 | printf(" %s ", diff_aligned_abbrev(&p->oid, opt->abbrev)); |
0a798076 JH |
1222 | } |
1223 | ||
c6744349 | 1224 | if (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) { |
d416df88 JH |
1225 | for (i = 0; i < num_parent; i++) |
1226 | putchar(p->parent[i].status); | |
1227 | putchar(inter_name_termination); | |
1228 | } | |
0a798076 | 1229 | |
663af342 | 1230 | write_name_quoted(p->path, stdout, line_termination); |
0a798076 JH |
1231 | } |
1232 | ||
99694544 JH |
1233 | /* |
1234 | * The result (p->elem) is from the working tree and their | |
1235 | * parents are typically from multiple stages during a merge | |
1236 | * (i.e. diff-files) or the state in HEAD and in the index | |
1237 | * (i.e. diff-index). | |
1238 | */ | |
91539833 | 1239 | void show_combined_diff(struct combine_diff_path *p, |
0a798076 JH |
1240 | int num_parent, |
1241 | int dense, | |
91539833 | 1242 | struct rev_info *rev) |
0a798076 | 1243 | { |
91539833 | 1244 | struct diff_options *opt = &rev->diffopt; |
41ee2ad6 | 1245 | |
c6744349 TH |
1246 | if (opt->output_format & (DIFF_FORMAT_RAW | |
1247 | DIFF_FORMAT_NAME | | |
89b0c4b5 | 1248 | DIFF_FORMAT_NAME_STATUS)) |
91539833 | 1249 | show_raw_diff(p, num_parent, rev); |
89b0c4b5 | 1250 | else if (opt->output_format & DIFF_FORMAT_PATCH) |
99694544 | 1251 | show_patch_diff(p, num_parent, dense, 1, rev); |
ee638024 LT |
1252 | } |
1253 | ||
25e5e2bf JH |
1254 | static void free_combined_pair(struct diff_filepair *pair) |
1255 | { | |
1256 | free(pair->two); | |
1257 | free(pair); | |
1258 | } | |
1259 | ||
1260 | /* | |
1261 | * A combine_diff_path expresses N parents on the LHS against 1 merge | |
1262 | * result. Synthesize a diff_filepair that has N entries on the "one" | |
1263 | * side and 1 entry on the "two" side. | |
1264 | * | |
1265 | * In the future, we might want to add more data to combine_diff_path | |
1266 | * so that we can fill fields we are ignoring (most notably, size) here, | |
1267 | * but currently nobody uses it, so this should suffice for now. | |
1268 | */ | |
1269 | static struct diff_filepair *combined_pair(struct combine_diff_path *p, | |
1270 | int num_parent) | |
1271 | { | |
1272 | int i; | |
1273 | struct diff_filepair *pair; | |
1274 | struct diff_filespec *pool; | |
1275 | ||
1276 | pair = xmalloc(sizeof(*pair)); | |
50a6c8ef | 1277 | pool = xcalloc(st_add(num_parent, 1), sizeof(struct diff_filespec)); |
25e5e2bf JH |
1278 | pair->one = pool + 1; |
1279 | pair->two = pool; | |
1280 | ||
1281 | for (i = 0; i < num_parent; i++) { | |
1282 | pair->one[i].path = p->path; | |
1283 | pair->one[i].mode = p->parent[i].mode; | |
a0d12c44 | 1284 | oidcpy(&pair->one[i].oid, &p->parent[i].oid); |
41c9560e | 1285 | pair->one[i].oid_valid = !is_null_oid(&p->parent[i].oid); |
25e5e2bf JH |
1286 | pair->one[i].has_more_entries = 1; |
1287 | } | |
1288 | pair->one[num_parent - 1].has_more_entries = 0; | |
1289 | ||
1290 | pair->two->path = p->path; | |
1291 | pair->two->mode = p->mode; | |
a0d12c44 | 1292 | oidcpy(&pair->two->oid, &p->oid); |
41c9560e | 1293 | pair->two->oid_valid = !is_null_oid(&p->oid); |
25e5e2bf JH |
1294 | return pair; |
1295 | } | |
1296 | ||
1297 | static void handle_combined_callback(struct diff_options *opt, | |
1298 | struct combine_diff_path *paths, | |
1299 | int num_parent, | |
1300 | int num_paths) | |
1301 | { | |
1302 | struct combine_diff_path *p; | |
1303 | struct diff_queue_struct q; | |
1304 | int i; | |
1305 | ||
1306 | q.queue = xcalloc(num_paths, sizeof(struct diff_filepair *)); | |
1307 | q.alloc = num_paths; | |
1308 | q.nr = num_paths; | |
af82c788 | 1309 | for (i = 0, p = paths; p; p = p->next) |
25e5e2bf | 1310 | q.queue[i++] = combined_pair(p, num_parent); |
25e5e2bf JH |
1311 | opt->format_callback(&q, opt, opt->format_callback_data); |
1312 | for (i = 0; i < num_paths; i++) | |
1313 | free_combined_pair(q.queue[i]); | |
1314 | free(q.queue); | |
1315 | } | |
1316 | ||
8518ff8f KS |
1317 | static const char *path_path(void *obj) |
1318 | { | |
1319 | struct combine_diff_path *path = (struct combine_diff_path *)obj; | |
1320 | ||
1321 | return path->path; | |
1322 | } | |
1323 | ||
eeb3f328 KS |
1324 | |
1325 | /* find set of paths that every parent touches */ | |
09fae19a | 1326 | static struct combine_diff_path *find_paths_generic(const struct object_id *oid, |
910650d2 | 1327 | const struct oid_array *parents, struct diff_options *opt) |
eeb3f328 KS |
1328 | { |
1329 | struct combine_diff_path *paths = NULL; | |
1330 | int i, num_parent = parents->nr; | |
1331 | ||
1332 | int output_format = opt->output_format; | |
1333 | const char *orderfile = opt->orderfile; | |
1334 | ||
1335 | opt->output_format = DIFF_FORMAT_NO_OUTPUT; | |
1336 | /* tell diff_tree to emit paths in sorted (=tree) order */ | |
1337 | opt->orderfile = NULL; | |
1338 | ||
7195fbfa | 1339 | /* D(A,P1...Pn) = D(A,P1) ^ ... ^ D(A,Pn) (wrt paths) */ |
eeb3f328 KS |
1340 | for (i = 0; i < num_parent; i++) { |
1341 | /* | |
1342 | * show stat against the first parent even when doing | |
1343 | * combined diff. | |
1344 | */ | |
1345 | int stat_opt = (output_format & | |
1346 | (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT)); | |
1347 | if (i == 0 && stat_opt) | |
1348 | opt->output_format = stat_opt; | |
1349 | else | |
1350 | opt->output_format = DIFF_FORMAT_NO_OUTPUT; | |
66f414f8 | 1351 | diff_tree_oid(&parents->oid[i], oid, "", opt); |
eeb3f328 KS |
1352 | diffcore_std(opt); |
1353 | paths = intersect_paths(paths, i, num_parent); | |
1354 | ||
1355 | /* if showing diff, show it in requested order */ | |
1356 | if (opt->output_format != DIFF_FORMAT_NO_OUTPUT && | |
1357 | orderfile) { | |
1358 | diffcore_order(orderfile); | |
1359 | } | |
1360 | ||
1361 | diff_flush(opt); | |
1362 | } | |
1363 | ||
1364 | opt->output_format = output_format; | |
1365 | opt->orderfile = orderfile; | |
1366 | return paths; | |
1367 | } | |
1368 | ||
1369 | ||
7195fbfa KS |
1370 | /* |
1371 | * find set of paths that everybody touches, assuming diff is run without | |
1372 | * rename/copy detection, etc, comparing all trees simultaneously (= faster). | |
1373 | */ | |
1374 | static struct combine_diff_path *find_paths_multitree( | |
09fae19a | 1375 | const struct object_id *oid, const struct oid_array *parents, |
7195fbfa KS |
1376 | struct diff_options *opt) |
1377 | { | |
1378 | int i, nparent = parents->nr; | |
fda94b41 | 1379 | const struct object_id **parents_oid; |
7195fbfa KS |
1380 | struct combine_diff_path paths_head; |
1381 | struct strbuf base; | |
1382 | ||
fda94b41 | 1383 | ALLOC_ARRAY(parents_oid, nparent); |
7195fbfa | 1384 | for (i = 0; i < nparent; i++) |
fda94b41 | 1385 | parents_oid[i] = &parents->oid[i]; |
7195fbfa KS |
1386 | |
1387 | /* fake list head, so worker can assume it is non-NULL */ | |
1388 | paths_head.next = NULL; | |
1389 | ||
1390 | strbuf_init(&base, PATH_MAX); | |
fda94b41 | 1391 | diff_tree_paths(&paths_head, oid, parents_oid, nparent, &base, opt); |
7195fbfa KS |
1392 | |
1393 | strbuf_release(&base); | |
fda94b41 | 1394 | free(parents_oid); |
7195fbfa KS |
1395 | return paths_head.next; |
1396 | } | |
1397 | ||
1398 | ||
b9acf54d | 1399 | void diff_tree_combined(const struct object_id *oid, |
910650d2 | 1400 | const struct oid_array *parents, |
0fe7c1de JH |
1401 | int dense, |
1402 | struct rev_info *rev) | |
af3feefa | 1403 | { |
91539833 | 1404 | struct diff_options *opt = &rev->diffopt; |
af3feefa | 1405 | struct diff_options diffopts; |
eeb3f328 | 1406 | struct combine_diff_path *p, *paths; |
0041f09d | 1407 | int i, num_paths, needsep, show_log_first, num_parent = parents->nr; |
7195fbfa | 1408 | int need_generic_pathscan; |
af3feefa | 1409 | |
51af1886 KS |
1410 | /* nothing to do, if no parents */ |
1411 | if (!num_parent) | |
1412 | return; | |
1413 | ||
1414 | show_log_first = !!rev->loginfo && !rev->no_commit_id; | |
1415 | needsep = 0; | |
1416 | if (show_log_first) { | |
1417 | show_log(rev); | |
1418 | ||
e7cc0ede | 1419 | if (rev->verbose_header && opt->output_format && |
b9c7d6e4 JK |
1420 | opt->output_format != DIFF_FORMAT_NO_OUTPUT && |
1421 | !commit_format_is_empty(rev->commit_format)) | |
51af1886 KS |
1422 | printf("%s%c", diff_line_prefix(opt), |
1423 | opt->line_termination); | |
1424 | } | |
1425 | ||
5b236832 | 1426 | diffopts = *opt; |
bd1928df | 1427 | copy_pathspec(&diffopts.pathspec, &opt->pathspec); |
0d1e0e78 BW |
1428 | diffopts.flags.recursive = 1; |
1429 | diffopts.flags.allow_external = 0; | |
af3feefa | 1430 | |
eeb3f328 KS |
1431 | /* find set of paths that everybody touches |
1432 | * | |
7195fbfa KS |
1433 | * NOTE |
1434 | * | |
1435 | * Diffcore transformations are bound to diff_filespec and logic | |
1436 | * comparing two entries - i.e. they do not apply directly to combine | |
1437 | * diff. | |
1438 | * | |
1439 | * If some of such transformations is requested - we launch generic | |
1440 | * path scanning, which works significantly slower compared to | |
1441 | * simultaneous all-trees-in-one-go scan in find_paths_multitree(). | |
1442 | * | |
1443 | * TODO some of the filters could be ported to work on | |
1444 | * combine_diff_paths - i.e. all functionality that skips paths, so in | |
1445 | * theory, we could end up having only multitree path scanning. | |
1446 | * | |
1447 | * NOTE please keep this semantically in sync with diffcore_std() | |
eeb3f328 | 1448 | */ |
7195fbfa | 1449 | need_generic_pathscan = opt->skip_stat_unmatch || |
0d1e0e78 | 1450 | opt->flags.follow_renames || |
7195fbfa KS |
1451 | opt->break_opt != -1 || |
1452 | opt->detect_rename || | |
cf63051a | 1453 | (opt->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK) || |
7195fbfa KS |
1454 | opt->filter; |
1455 | ||
1456 | ||
1457 | if (need_generic_pathscan) { | |
1458 | /* | |
1459 | * NOTE generic case also handles --stat, as it computes | |
1460 | * diff(sha1,parent_i) for all i to do the job, specifically | |
1461 | * for parent0. | |
1462 | */ | |
09fae19a | 1463 | paths = find_paths_generic(oid, parents, &diffopts); |
7195fbfa KS |
1464 | } |
1465 | else { | |
1466 | int stat_opt; | |
09fae19a | 1467 | paths = find_paths_multitree(oid, parents, &diffopts); |
7195fbfa KS |
1468 | |
1469 | /* | |
1470 | * show stat against the first parent even | |
1471 | * when doing combined diff. | |
1472 | */ | |
1473 | stat_opt = (opt->output_format & | |
1474 | (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT)); | |
1475 | if (stat_opt) { | |
1476 | diffopts.output_format = stat_opt; | |
1477 | ||
66f414f8 | 1478 | diff_tree_oid(&parents->oid[0], oid, "", &diffopts); |
7195fbfa KS |
1479 | diffcore_std(&diffopts); |
1480 | if (opt->orderfile) | |
1481 | diffcore_order(opt->orderfile); | |
1482 | diff_flush(&diffopts); | |
1483 | } | |
1484 | } | |
af3feefa | 1485 | |
af82c788 KS |
1486 | /* find out number of surviving paths */ |
1487 | for (num_paths = 0, p = paths; p; p = p->next) | |
1488 | num_paths++; | |
8518ff8f KS |
1489 | |
1490 | /* order paths according to diffcore_order */ | |
1491 | if (opt->orderfile && num_paths) { | |
1492 | struct obj_order *o; | |
1493 | ||
b32fa95f | 1494 | ALLOC_ARRAY(o, num_paths); |
8518ff8f KS |
1495 | for (i = 0, p = paths; p; p = p->next, i++) |
1496 | o[i].obj = p; | |
1497 | order_objects(opt->orderfile, path_path, o, num_paths); | |
1498 | for (i = 0; i < num_paths - 1; i++) { | |
1499 | p = o[i].obj; | |
1500 | p->next = o[i+1].obj; | |
1501 | } | |
1502 | ||
1503 | p = o[num_paths-1].obj; | |
1504 | p->next = NULL; | |
1505 | paths = o[0].obj; | |
1506 | free(o); | |
1507 | } | |
1508 | ||
1509 | ||
e3c3a550 | 1510 | if (num_paths) { |
c6744349 TH |
1511 | if (opt->output_format & (DIFF_FORMAT_RAW | |
1512 | DIFF_FORMAT_NAME | | |
1513 | DIFF_FORMAT_NAME_STATUS)) { | |
af82c788 KS |
1514 | for (p = paths; p; p = p->next) |
1515 | show_raw_diff(p, num_parent, rev); | |
3969cf7d | 1516 | needsep = 1; |
86ff1d20 | 1517 | } |
74e2abe5 JH |
1518 | else if (opt->output_format & |
1519 | (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT)) | |
3969cf7d | 1520 | needsep = 1; |
25e5e2bf JH |
1521 | else if (opt->output_format & DIFF_FORMAT_CALLBACK) |
1522 | handle_combined_callback(opt, paths, num_parent, num_paths); | |
1523 | ||
c6744349 | 1524 | if (opt->output_format & DIFF_FORMAT_PATCH) { |
3969cf7d | 1525 | if (needsep) |
41ee2ad6 JK |
1526 | printf("%s%c", diff_line_prefix(opt), |
1527 | opt->line_termination); | |
af82c788 KS |
1528 | for (p = paths; p; p = p->next) |
1529 | show_patch_diff(p, num_parent, dense, | |
1530 | 0, rev); | |
af3feefa JH |
1531 | } |
1532 | } | |
1533 | ||
1534 | /* Clean things up */ | |
1535 | while (paths) { | |
ea726d02 | 1536 | struct combine_diff_path *tmp = paths; |
af3feefa JH |
1537 | paths = paths->next; |
1538 | free(tmp); | |
1539 | } | |
46ec510a | 1540 | |
ed6e8038 | 1541 | clear_pathspec(&diffopts.pathspec); |
af3feefa | 1542 | } |
0fe7c1de | 1543 | |
82889295 RS |
1544 | void diff_tree_combined_merge(const struct commit *commit, int dense, |
1545 | struct rev_info *rev) | |
0fe7c1de | 1546 | { |
53d00b39 | 1547 | struct commit_list *parent = get_saved_parents(rev, commit); |
910650d2 | 1548 | struct oid_array parents = OID_ARRAY_INIT; |
0041f09d RS |
1549 | |
1550 | while (parent) { | |
910650d2 | 1551 | oid_array_append(&parents, &parent->item->object.oid); |
0041f09d RS |
1552 | parent = parent->next; |
1553 | } | |
b9acf54d | 1554 | diff_tree_combined(&commit->object.oid, &parents, dense, rev); |
910650d2 | 1555 | oid_array_clear(&parents); |
0fe7c1de | 1556 | } |