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