]>
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" |
91539833 | 8 | #include "log-tree.h" |
7dae8b21 | 9 | #include "refs.h" |
af3feefa | 10 | |
ea726d02 | 11 | static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr, int n, int num_parent) |
af3feefa JH |
12 | { |
13 | struct diff_queue_struct *q = &diff_queued_diff; | |
ea726d02 | 14 | struct combine_diff_path *p; |
af3feefa JH |
15 | int i; |
16 | ||
17 | if (!n) { | |
ea726d02 | 18 | struct combine_diff_path *list = NULL, **tail = &list; |
af3feefa JH |
19 | for (i = 0; i < q->nr; i++) { |
20 | int len; | |
21 | const char *path; | |
a976b0a5 | 22 | if (diff_unmodified_pair(q->queue[i])) |
af3feefa JH |
23 | continue; |
24 | path = q->queue[i]->two->path; | |
25 | len = strlen(path); | |
2454c962 | 26 | p = xmalloc(combine_diff_path_size(num_parent, len)); |
4b25d091 | 27 | p->path = (char *) &(p->parent[num_parent]); |
af3feefa JH |
28 | memcpy(p->path, path, len); |
29 | p->path[len] = 0; | |
30 | p->len = len; | |
31 | p->next = NULL; | |
2454c962 JH |
32 | memset(p->parent, 0, |
33 | sizeof(p->parent[0]) * num_parent); | |
34 | ||
e702496e | 35 | hashcpy(p->sha1, q->queue[i]->two->sha1); |
2454c962 | 36 | p->mode = q->queue[i]->two->mode; |
e702496e | 37 | hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1); |
2454c962 | 38 | p->parent[n].mode = q->queue[i]->one->mode; |
d416df88 | 39 | p->parent[n].status = q->queue[i]->status; |
5290a0f8 JH |
40 | *tail = p; |
41 | tail = &p->next; | |
af3feefa JH |
42 | } |
43 | return list; | |
44 | } | |
45 | ||
46 | for (p = curr; p; p = p->next) { | |
47 | int found = 0; | |
48 | if (!p->len) | |
49 | continue; | |
50 | for (i = 0; i < q->nr; i++) { | |
51 | const char *path; | |
52 | int len; | |
53 | ||
a976b0a5 | 54 | if (diff_unmodified_pair(q->queue[i])) |
af3feefa JH |
55 | continue; |
56 | path = q->queue[i]->two->path; | |
57 | len = strlen(path); | |
58 | if (len == p->len && !memcmp(path, p->path, len)) { | |
59 | found = 1; | |
e702496e | 60 | hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1); |
2454c962 | 61 | p->parent[n].mode = q->queue[i]->one->mode; |
d416df88 | 62 | p->parent[n].status = q->queue[i]->status; |
af3feefa JH |
63 | break; |
64 | } | |
65 | } | |
66 | if (!found) | |
67 | p->len = 0; | |
68 | } | |
69 | return curr; | |
70 | } | |
71 | ||
b469d8b6 | 72 | /* Lines lost from parent */ |
af3feefa JH |
73 | struct lline { |
74 | struct lline *next; | |
75 | int len; | |
76 | unsigned long parent_map; | |
77 | char line[FLEX_ARRAY]; | |
78 | }; | |
79 | ||
b469d8b6 | 80 | /* Lines surviving in the merge result */ |
af3feefa JH |
81 | struct sline { |
82 | struct lline *lost_head, **lost_tail; | |
55d5d5ba | 83 | struct lline *next_lost; |
af3feefa JH |
84 | char *bol; |
85 | int len; | |
46dc9412 JH |
86 | /* bit 0 up to (N-1) are on if the parent has this line (i.e. |
87 | * we did not change it). | |
b469d8b6 | 88 | * bit N is used for "interesting" lines, including context. |
c86fbe53 | 89 | * bit (N+1) is used for "do not show deletion before this". |
b469d8b6 | 90 | */ |
af3feefa | 91 | unsigned long flag; |
f16706cc | 92 | unsigned long *p_lno; |
af3feefa JH |
93 | }; |
94 | ||
7dae8b21 | 95 | static char *grab_blob(const unsigned char *sha1, unsigned int mode, unsigned long *size) |
af3feefa JH |
96 | { |
97 | char *blob; | |
21666f1a | 98 | enum object_type type; |
7dae8b21 JH |
99 | |
100 | if (S_ISGITLINK(mode)) { | |
101 | blob = xmalloc(100); | |
102 | *size = snprintf(blob, 100, | |
103 | "Subproject commit %s\n", sha1_to_hex(sha1)); | |
104 | } else if (is_null_sha1(sha1)) { | |
af3feefa JH |
105 | /* deleted blob */ |
106 | *size = 0; | |
107 | return xcalloc(1, 1); | |
7dae8b21 JH |
108 | } else { |
109 | blob = read_sha1_file(sha1, &type, size); | |
110 | if (type != OBJ_BLOB) | |
111 | die("object '%s' is not a blob!", sha1_to_hex(sha1)); | |
af3feefa | 112 | } |
af3feefa JH |
113 | return blob; |
114 | } | |
115 | ||
f23fc773 | 116 | static void append_lost(struct sline *sline, int n, const char *line, int len) |
af3feefa JH |
117 | { |
118 | struct lline *lline; | |
af3feefa JH |
119 | unsigned long this_mask = (1UL<<n); |
120 | if (line[len-1] == '\n') | |
121 | len--; | |
122 | ||
123 | /* Check to see if we can squash things */ | |
124 | if (sline->lost_head) { | |
55d5d5ba | 125 | lline = sline->next_lost; |
af3feefa JH |
126 | while (lline) { |
127 | if (lline->len == len && | |
128 | !memcmp(lline->line, line, len)) { | |
129 | lline->parent_map |= this_mask; | |
55d5d5ba | 130 | sline->next_lost = lline->next; |
af3feefa JH |
131 | return; |
132 | } | |
133 | lline = lline->next; | |
134 | } | |
135 | } | |
136 | ||
137 | lline = xmalloc(sizeof(*lline) + len + 1); | |
138 | lline->len = len; | |
139 | lline->next = NULL; | |
140 | lline->parent_map = this_mask; | |
141 | memcpy(lline->line, line, len); | |
142 | lline->line[len] = 0; | |
5290a0f8 | 143 | *sline->lost_tail = lline; |
af3feefa | 144 | sline->lost_tail = &lline->next; |
55d5d5ba | 145 | sline->next_lost = NULL; |
af3feefa JH |
146 | } |
147 | ||
f23fc773 | 148 | struct combine_diff_state { |
a0fd3146 JH |
149 | unsigned int lno; |
150 | int ob, on, nb, nn; | |
f23fc773 JH |
151 | unsigned long nmask; |
152 | int num_parent; | |
153 | int n; | |
154 | struct sline *sline; | |
155 | struct sline *lost_bucket; | |
156 | }; | |
157 | ||
d9ea73e0 | 158 | static void consume_line(void *state_, char *line, unsigned long len) |
f23fc773 | 159 | { |
d9ea73e0 | 160 | struct combine_diff_state *state = state_; |
f23fc773 JH |
161 | if (5 < len && !memcmp("@@ -", line, 4)) { |
162 | if (parse_hunk_header(line, len, | |
163 | &state->ob, &state->on, | |
164 | &state->nb, &state->nn)) | |
165 | return; | |
166 | state->lno = state->nb; | |
b810cbbd | 167 | if (state->nn == 0) { |
f23fc773 JH |
168 | /* @@ -X,Y +N,0 @@ removed Y lines |
169 | * that would have come *after* line N | |
170 | * in the result. Our lost buckets hang | |
171 | * to the line after the removed lines, | |
b810cbbd JH |
172 | * |
173 | * Note that this is correct even when N == 0, | |
174 | * in which case the hunk removes the first | |
175 | * line in the file. | |
f23fc773 JH |
176 | */ |
177 | state->lost_bucket = &state->sline[state->nb]; | |
b810cbbd JH |
178 | if (!state->nb) |
179 | state->nb = 1; | |
180 | } else { | |
f23fc773 | 181 | state->lost_bucket = &state->sline[state->nb-1]; |
b810cbbd | 182 | } |
f23fc773 JH |
183 | if (!state->sline[state->nb-1].p_lno) |
184 | state->sline[state->nb-1].p_lno = | |
185 | xcalloc(state->num_parent, | |
186 | sizeof(unsigned long)); | |
187 | state->sline[state->nb-1].p_lno[state->n] = state->ob; | |
55d5d5ba | 188 | state->lost_bucket->next_lost = state->lost_bucket->lost_head; |
f23fc773 JH |
189 | return; |
190 | } | |
191 | if (!state->lost_bucket) | |
192 | return; /* not in any hunk yet */ | |
193 | switch (line[0]) { | |
194 | case '-': | |
195 | append_lost(state->lost_bucket, state->n, line+1, len-1); | |
196 | break; | |
197 | case '+': | |
198 | state->sline[state->lno-1].flag |= state->nmask; | |
199 | state->lno++; | |
200 | break; | |
201 | } | |
202 | } | |
203 | ||
7dae8b21 JH |
204 | static void combine_diff(const unsigned char *parent, unsigned int mode, |
205 | mmfile_t *result_file, | |
2386c297 JH |
206 | struct sline *sline, unsigned int cnt, int n, |
207 | int num_parent) | |
af3feefa | 208 | { |
f23fc773 | 209 | unsigned int p_lno, lno; |
f16706cc | 210 | unsigned long nmask = (1UL << n); |
f23fc773 JH |
211 | xpparam_t xpp; |
212 | xdemitconf_t xecfg; | |
213 | mmfile_t parent_file; | |
214 | xdemitcb_t ecb; | |
215 | struct combine_diff_state state; | |
216 | unsigned long sz; | |
af3feefa | 217 | |
4462731e JH |
218 | if (!cnt) |
219 | return; /* result deleted */ | |
220 | ||
7dae8b21 | 221 | parent_file.ptr = grab_blob(parent, mode, &sz); |
f23fc773 | 222 | parent_file.size = sz; |
9ccd0a88 | 223 | memset(&xpp, 0, sizeof(xpp)); |
f23fc773 | 224 | xpp.flags = XDF_NEED_MINIMAL; |
30b25010 | 225 | memset(&xecfg, 0, sizeof(xecfg)); |
f23fc773 JH |
226 | memset(&state, 0, sizeof(state)); |
227 | state.nmask = nmask; | |
228 | state.sline = sline; | |
229 | state.lno = 1; | |
230 | state.num_parent = num_parent; | |
231 | state.n = n; | |
232 | ||
8a3f524b JH |
233 | xdi_diff_outf(&parent_file, result_file, consume_line, &state, |
234 | &xpp, &xecfg, &ecb); | |
f23fc773 | 235 | free(parent_file.ptr); |
f16706cc JH |
236 | |
237 | /* Assign line numbers for this parent. | |
238 | * | |
239 | * sline[lno].p_lno[n] records the first line number | |
240 | * (counting from 1) for parent N if the final hunk display | |
241 | * started by showing sline[lno] (possibly showing the lost | |
242 | * lines attached to it first). | |
243 | */ | |
8a470ebf | 244 | for (lno = 0, p_lno = 1; lno <= cnt; lno++) { |
f16706cc JH |
245 | struct lline *ll; |
246 | sline[lno].p_lno[n] = p_lno; | |
247 | ||
248 | /* How many lines would this sline advance the p_lno? */ | |
249 | ll = sline[lno].lost_head; | |
250 | while (ll) { | |
251 | if (ll->parent_map & nmask) | |
252 | p_lno++; /* '-' means parent had it */ | |
253 | ll = ll->next; | |
254 | } | |
8a470ebf | 255 | if (lno < cnt && !(sline[lno].flag & nmask)) |
f16706cc JH |
256 | p_lno++; /* no '+' means parent had it */ |
257 | } | |
258 | sline[lno].p_lno[n] = p_lno; /* trailer */ | |
af3feefa JH |
259 | } |
260 | ||
261 | static unsigned long context = 3; | |
262 | static char combine_marker = '@'; | |
263 | ||
264 | static int interesting(struct sline *sline, unsigned long all_mask) | |
265 | { | |
46dc9412 JH |
266 | /* If some parents lost lines here, or if we have added to |
267 | * some parent, it is interesting. | |
268 | */ | |
269 | return ((sline->flag & all_mask) || sline->lost_head); | |
af3feefa JH |
270 | } |
271 | ||
3ec1909f JH |
272 | static unsigned long adjust_hunk_tail(struct sline *sline, |
273 | unsigned long all_mask, | |
274 | unsigned long hunk_begin, | |
275 | unsigned long i) | |
276 | { | |
46dc9412 JH |
277 | /* i points at the first uninteresting line. If the last line |
278 | * of the hunk was interesting only because it has some | |
279 | * deletion, then it is not all that interesting for the | |
280 | * purpose of giving trailing context lines. This is because | |
281 | * we output '-' line and then unmodified sline[i-1] itself in | |
282 | * that case which gives us one extra context line. | |
3ec1909f | 283 | */ |
46dc9412 | 284 | if ((hunk_begin + 1 <= i) && !(sline[i-1].flag & all_mask)) |
3ec1909f JH |
285 | i--; |
286 | return i; | |
287 | } | |
288 | ||
46dc9412 JH |
289 | static unsigned long find_next(struct sline *sline, |
290 | unsigned long mark, | |
291 | unsigned long i, | |
292 | unsigned long cnt, | |
2386c297 | 293 | int look_for_uninteresting) |
3ec1909f | 294 | { |
46dc9412 JH |
295 | /* We have examined up to i-1 and are about to look at i. |
296 | * Find next interesting or uninteresting line. Here, | |
297 | * "interesting" does not mean interesting(), but marked by | |
298 | * the give_context() function below (i.e. it includes context | |
299 | * lines that are not interesting to interesting() function | |
300 | * that are surrounded by interesting() ones. | |
301 | */ | |
74065951 | 302 | while (i <= cnt) |
2386c297 | 303 | if (look_for_uninteresting |
46dc9412 JH |
304 | ? !(sline[i].flag & mark) |
305 | : (sline[i].flag & mark)) | |
3ec1909f JH |
306 | return i; |
307 | else | |
308 | i++; | |
74065951 | 309 | return i; |
3ec1909f JH |
310 | } |
311 | ||
312 | static int give_context(struct sline *sline, unsigned long cnt, int num_parent) | |
af3feefa JH |
313 | { |
314 | unsigned long all_mask = (1UL<<num_parent) - 1; | |
315 | unsigned long mark = (1UL<<num_parent); | |
c86fbe53 | 316 | unsigned long no_pre_delete = (2UL<<num_parent); |
af3feefa JH |
317 | unsigned long i; |
318 | ||
46dc9412 | 319 | /* Two groups of interesting lines may have a short gap of |
82e5a82f | 320 | * uninteresting lines. Connect such groups to give them a |
46dc9412 JH |
321 | * bit of context. |
322 | * | |
323 | * We first start from what the interesting() function says, | |
324 | * and mark them with "mark", and paint context lines with the | |
325 | * mark. So interesting() would still say false for such context | |
326 | * lines but they are treated as "interesting" in the end. | |
327 | */ | |
328 | i = find_next(sline, mark, 0, cnt, 0); | |
74065951 | 329 | if (cnt < i) |
3ec1909f JH |
330 | return 0; |
331 | ||
74065951 | 332 | while (i <= cnt) { |
3ec1909f JH |
333 | unsigned long j = (context < i) ? (i - context) : 0; |
334 | unsigned long k; | |
46dc9412 JH |
335 | |
336 | /* Paint a few lines before the first interesting line. */ | |
3ec1909f | 337 | while (j < i) |
c86fbe53 | 338 | sline[j++].flag |= mark | no_pre_delete; |
3ec1909f JH |
339 | |
340 | again: | |
46dc9412 JH |
341 | /* we know up to i is to be included. where does the |
342 | * next uninteresting one start? | |
343 | */ | |
344 | j = find_next(sline, mark, i, cnt, 1); | |
74065951 | 345 | if (cnt < j) |
3ec1909f JH |
346 | break; /* the rest are all interesting */ |
347 | ||
348 | /* lookahead context lines */ | |
46dc9412 | 349 | k = find_next(sline, mark, j, cnt, 0); |
3ec1909f JH |
350 | j = adjust_hunk_tail(sline, all_mask, i, j); |
351 | ||
352 | if (k < j + context) { | |
353 | /* k is interesting and [j,k) are not, but | |
354 | * paint them interesting because the gap is small. | |
355 | */ | |
356 | while (j < k) | |
af3feefa | 357 | sline[j++].flag |= mark; |
3ec1909f JH |
358 | i = k; |
359 | goto again; | |
af3feefa | 360 | } |
3ec1909f JH |
361 | |
362 | /* j is the first uninteresting line and there is | |
46dc9412 JH |
363 | * no overlap beyond it within context lines. Paint |
364 | * the trailing edge a bit. | |
3ec1909f JH |
365 | */ |
366 | i = k; | |
74065951 | 367 | k = (j + context < cnt+1) ? j + context : cnt+1; |
3ec1909f JH |
368 | while (j < k) |
369 | sline[j++].flag |= mark; | |
370 | } | |
371 | return 1; | |
372 | } | |
373 | ||
374 | static int make_hunks(struct sline *sline, unsigned long cnt, | |
375 | int num_parent, int dense) | |
376 | { | |
377 | unsigned long all_mask = (1UL<<num_parent) - 1; | |
378 | unsigned long mark = (1UL<<num_parent); | |
379 | unsigned long i; | |
380 | int has_interesting = 0; | |
381 | ||
74065951 | 382 | for (i = 0; i <= cnt; i++) { |
3ec1909f JH |
383 | if (interesting(&sline[i], all_mask)) |
384 | sline[i].flag |= mark; | |
385 | else | |
386 | sline[i].flag &= ~mark; | |
af3feefa | 387 | } |
d8f4790e | 388 | if (!dense) |
3ec1909f | 389 | return give_context(sline, cnt, num_parent); |
d8f4790e | 390 | |
263eee29 JH |
391 | /* Look at each hunk, and if we have changes from only one |
392 | * parent, or the changes are the same from all but one | |
393 | * parent, mark that uninteresting. | |
d8f4790e JH |
394 | */ |
395 | i = 0; | |
74065951 | 396 | while (i <= cnt) { |
3ec1909f | 397 | unsigned long j, hunk_begin, hunk_end; |
bf1c32bd | 398 | unsigned long same_diff; |
74065951 | 399 | while (i <= cnt && !(sline[i].flag & mark)) |
d8f4790e | 400 | i++; |
74065951 | 401 | if (cnt < i) |
d8f4790e | 402 | break; /* No more interesting hunks */ |
3ec1909f | 403 | hunk_begin = i; |
74065951 | 404 | for (j = i + 1; j <= cnt; j++) { |
3ec1909f JH |
405 | if (!(sline[j].flag & mark)) { |
406 | /* Look beyond the end to see if there | |
407 | * is an interesting line after this | |
408 | * hunk within context span. | |
409 | */ | |
410 | unsigned long la; /* lookahead */ | |
411 | int contin = 0; | |
412 | la = adjust_hunk_tail(sline, all_mask, | |
413 | hunk_begin, j); | |
74065951 JH |
414 | la = (la + context < cnt + 1) ? |
415 | (la + context) : cnt + 1; | |
3ec1909f JH |
416 | while (j <= --la) { |
417 | if (sline[la].flag & mark) { | |
418 | contin = 1; | |
419 | break; | |
420 | } | |
421 | } | |
422 | if (!contin) | |
423 | break; | |
424 | j = la; | |
425 | } | |
426 | } | |
427 | hunk_end = j; | |
428 | ||
bf1c32bd | 429 | /* [i..hunk_end) are interesting. Now is it really |
fd4b1d21 JH |
430 | * interesting? We check if there are only two versions |
431 | * and the result matches one of them. That is, we look | |
432 | * at: | |
433 | * (+) line, which records lines added to which parents; | |
434 | * this line appears in the result. | |
435 | * (-) line, which records from what parents the line | |
436 | * was removed; this line does not appear in the result. | |
437 | * then check the set of parents the result has difference | |
438 | * from, from all lines. If there are lines that has | |
439 | * different set of parents that the result has differences | |
440 | * from, that means we have more than two versions. | |
441 | * | |
442 | * Even when we have only two versions, if the result does | |
443 | * not match any of the parents, the it should be considered | |
444 | * interesting. In such a case, we would have all '+' line. | |
445 | * After passing the above "two versions" test, that would | |
446 | * appear as "the same set of parents" to be "all parents". | |
d8f4790e | 447 | */ |
bf1c32bd JH |
448 | same_diff = 0; |
449 | has_interesting = 0; | |
450 | for (j = i; j < hunk_end && !has_interesting; j++) { | |
46dc9412 | 451 | unsigned long this_diff = sline[j].flag & all_mask; |
bf1c32bd JH |
452 | struct lline *ll = sline[j].lost_head; |
453 | if (this_diff) { | |
454 | /* This has some changes. Is it the | |
455 | * same as others? | |
456 | */ | |
457 | if (!same_diff) | |
458 | same_diff = this_diff; | |
459 | else if (same_diff != this_diff) { | |
460 | has_interesting = 1; | |
461 | break; | |
462 | } | |
463 | } | |
464 | while (ll && !has_interesting) { | |
465 | /* Lost this line from these parents; | |
466 | * who are they? Are they the same? | |
467 | */ | |
468 | this_diff = ll->parent_map; | |
469 | if (!same_diff) | |
470 | same_diff = this_diff; | |
471 | else if (same_diff != this_diff) { | |
472 | has_interesting = 1; | |
473 | } | |
474 | ll = ll->next; | |
475 | } | |
d8f4790e | 476 | } |
bf1c32bd | 477 | |
fd4b1d21 | 478 | if (!has_interesting && same_diff != all_mask) { |
d8f4790e | 479 | /* This hunk is not that interesting after all */ |
3ec1909f | 480 | for (j = hunk_begin; j < hunk_end; j++) |
d8f4790e JH |
481 | sline[j].flag &= ~mark; |
482 | } | |
483 | i = hunk_end; | |
484 | } | |
3ec1909f JH |
485 | |
486 | has_interesting = give_context(sline, cnt, num_parent); | |
8828cdcb | 487 | return has_interesting; |
af3feefa JH |
488 | } |
489 | ||
3b0f5e88 | 490 | static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, int n, unsigned long null_context) |
f16706cc JH |
491 | { |
492 | l0 = sline[l0].p_lno[n]; | |
493 | l1 = sline[l1].p_lno[n]; | |
3b0f5e88 | 494 | printf(" -%lu,%lu", l0, l1-l0-null_context); |
f16706cc JH |
495 | } |
496 | ||
d5f6a01a JH |
497 | static int hunk_comment_line(const char *bol) |
498 | { | |
7a8ac59f JH |
499 | int ch; |
500 | ||
501 | if (!bol) | |
502 | return 0; | |
503 | ch = *bol & 0xff; | |
d5f6a01a JH |
504 | return (isalpha(ch) || ch == '_' || ch == '$'); |
505 | } | |
506 | ||
39280970 JH |
507 | static void show_line_to_eol(const char *line, int len, const char *reset) |
508 | { | |
509 | int saw_cr_at_eol = 0; | |
510 | if (len < 0) | |
511 | len = strlen(line); | |
512 | saw_cr_at_eol = (len && line[len-1] == '\r'); | |
513 | ||
514 | printf("%.*s%s%s\n", len - saw_cr_at_eol, line, | |
515 | reset, | |
516 | saw_cr_at_eol ? "\r" : ""); | |
517 | } | |
518 | ||
567a03d1 JH |
519 | static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent, |
520 | int use_color) | |
af3feefa JH |
521 | { |
522 | unsigned long mark = (1UL<<num_parent); | |
c86fbe53 | 523 | unsigned long no_pre_delete = (2UL<<num_parent); |
af3feefa | 524 | int i; |
f16706cc | 525 | unsigned long lno = 0; |
567a03d1 JH |
526 | const char *c_frag = diff_get_color(use_color, DIFF_FRAGINFO); |
527 | const char *c_new = diff_get_color(use_color, DIFF_FILE_NEW); | |
528 | const char *c_old = diff_get_color(use_color, DIFF_FILE_OLD); | |
529 | const char *c_plain = diff_get_color(use_color, DIFF_PLAIN); | |
530 | const char *c_reset = diff_get_color(use_color, DIFF_RESET); | |
af3feefa | 531 | |
4462731e JH |
532 | if (!cnt) |
533 | return; /* result deleted */ | |
534 | ||
af3feefa | 535 | while (1) { |
8bc7574b JH |
536 | unsigned long hunk_end; |
537 | unsigned long rlines; | |
d5f6a01a | 538 | const char *hunk_comment = NULL; |
3b0f5e88 | 539 | unsigned long null_context = 0; |
d5f6a01a JH |
540 | |
541 | while (lno <= cnt && !(sline[lno].flag & mark)) { | |
542 | if (hunk_comment_line(sline[lno].bol)) | |
543 | hunk_comment = sline[lno].bol; | |
af3feefa | 544 | lno++; |
d5f6a01a | 545 | } |
8a470ebf | 546 | if (cnt < lno) |
af3feefa | 547 | break; |
8a470ebf | 548 | else { |
74065951 | 549 | for (hunk_end = lno + 1; hunk_end <= cnt; hunk_end++) |
8a470ebf JH |
550 | if (!(sline[hunk_end].flag & mark)) |
551 | break; | |
552 | } | |
74065951 JH |
553 | rlines = hunk_end - lno; |
554 | if (cnt < hunk_end) | |
555 | rlines--; /* pointing at the last delete hunk */ | |
3b0f5e88 JH |
556 | |
557 | if (!context) { | |
558 | /* | |
559 | * Even when running with --unified=0, all | |
560 | * lines in the hunk needs to be processed in | |
561 | * the loop below in order to show the | |
562 | * deletion recorded in lost_head. However, | |
563 | * we do not want to show the resulting line | |
564 | * with all blank context markers in such a | |
565 | * case. Compensate. | |
566 | */ | |
567 | unsigned long j; | |
568 | for (j = lno; j < hunk_end; j++) | |
569 | if (!(sline[j].flag & (mark-1))) | |
570 | null_context++; | |
571 | rlines -= null_context; | |
572 | } | |
573 | ||
567a03d1 | 574 | fputs(c_frag, stdout); |
af3feefa | 575 | for (i = 0; i <= num_parent; i++) putchar(combine_marker); |
f16706cc | 576 | for (i = 0; i < num_parent; i++) |
3b0f5e88 | 577 | show_parent_lno(sline, lno, hunk_end, i, null_context); |
74065951 | 578 | printf(" +%lu,%lu ", lno+1, rlines); |
af3feefa | 579 | for (i = 0; i <= num_parent; i++) putchar(combine_marker); |
d5f6a01a JH |
580 | |
581 | if (hunk_comment) { | |
582 | int comment_end = 0; | |
583 | for (i = 0; i < 40; i++) { | |
584 | int ch = hunk_comment[i] & 0xff; | |
585 | if (!ch || ch == '\n') | |
586 | break; | |
587 | if (!isspace(ch)) | |
588 | comment_end = i; | |
589 | } | |
590 | if (comment_end) | |
591 | putchar(' '); | |
592 | for (i = 0; i < comment_end; i++) | |
593 | putchar(hunk_comment[i]); | |
594 | } | |
595 | ||
567a03d1 | 596 | printf("%s\n", c_reset); |
af3feefa JH |
597 | while (lno < hunk_end) { |
598 | struct lline *ll; | |
599 | int j; | |
46dc9412 | 600 | unsigned long p_mask; |
fd13b21f | 601 | struct sline *sl = &sline[lno++]; |
c86fbe53 | 602 | ll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head; |
af3feefa | 603 | while (ll) { |
567a03d1 | 604 | fputs(c_old, stdout); |
af3feefa JH |
605 | for (j = 0; j < num_parent; j++) { |
606 | if (ll->parent_map & (1UL<<j)) | |
607 | putchar('-'); | |
608 | else | |
609 | putchar(' '); | |
610 | } | |
39280970 | 611 | show_line_to_eol(ll->line, -1, c_reset); |
af3feefa JH |
612 | ll = ll->next; |
613 | } | |
74065951 | 614 | if (cnt < lno) |
8a470ebf | 615 | break; |
46dc9412 | 616 | p_mask = 1; |
3b0f5e88 JH |
617 | if (!(sl->flag & (mark-1))) { |
618 | /* | |
619 | * This sline was here to hang the | |
620 | * lost lines in front of it. | |
621 | */ | |
622 | if (!context) | |
623 | continue; | |
567a03d1 | 624 | fputs(c_plain, stdout); |
3b0f5e88 | 625 | } |
567a03d1 JH |
626 | else |
627 | fputs(c_new, stdout); | |
af3feefa | 628 | for (j = 0; j < num_parent; j++) { |
46dc9412 | 629 | if (p_mask & sl->flag) |
af3feefa | 630 | putchar('+'); |
46dc9412 JH |
631 | else |
632 | putchar(' '); | |
633 | p_mask <<= 1; | |
af3feefa | 634 | } |
39280970 | 635 | show_line_to_eol(sl->bol, sl->len, c_reset); |
af3feefa JH |
636 | } |
637 | } | |
638 | } | |
639 | ||
3c39e9bd JH |
640 | static void reuse_combine_diff(struct sline *sline, unsigned long cnt, |
641 | int i, int j) | |
642 | { | |
643 | /* We have already examined parent j and we know parent i | |
644 | * and parent j are the same, so reuse the combined result | |
645 | * of parent j for parent i. | |
646 | */ | |
647 | unsigned long lno, imask, jmask; | |
648 | imask = (1UL<<i); | |
649 | jmask = (1UL<<j); | |
650 | ||
8a470ebf | 651 | for (lno = 0; lno <= cnt; lno++) { |
3c39e9bd | 652 | struct lline *ll = sline->lost_head; |
f16706cc | 653 | sline->p_lno[i] = sline->p_lno[j]; |
3c39e9bd JH |
654 | while (ll) { |
655 | if (ll->parent_map & jmask) | |
656 | ll->parent_map |= imask; | |
657 | ll = ll->next; | |
658 | } | |
46dc9412 JH |
659 | if (sline->flag & jmask) |
660 | sline->flag |= imask; | |
3c39e9bd JH |
661 | sline++; |
662 | } | |
4462731e JH |
663 | /* the overall size of the file (sline[cnt]) */ |
664 | sline->p_lno[i] = sline->p_lno[j]; | |
3c39e9bd JH |
665 | } |
666 | ||
462a15bc JH |
667 | static void dump_quoted_path(const char *head, |
668 | const char *prefix, | |
669 | const char *path, | |
567a03d1 | 670 | const char *c_meta, const char *c_reset) |
eab144ac | 671 | { |
462a15bc JH |
672 | static struct strbuf buf = STRBUF_INIT; |
673 | ||
674 | strbuf_reset(&buf); | |
675 | strbuf_addstr(&buf, c_meta); | |
676 | strbuf_addstr(&buf, head); | |
d5625091 | 677 | quote_two_c_style(&buf, prefix, path, 0); |
462a15bc JH |
678 | strbuf_addstr(&buf, c_reset); |
679 | puts(buf.buf); | |
eab144ac LT |
680 | } |
681 | ||
89b0c4b5 JH |
682 | static void show_patch_diff(struct combine_diff_path *elem, int num_parent, |
683 | int dense, struct rev_info *rev) | |
af3feefa | 684 | { |
91539833 | 685 | struct diff_options *opt = &rev->diffopt; |
f23fc773 | 686 | unsigned long result_size, cnt, lno; |
310f8b5b | 687 | char *result, *cp; |
af3feefa | 688 | struct sline *sline; /* survived lines */ |
2454c962 | 689 | int mode_differs = 0; |
89b0c4b5 | 690 | int i, show_hunks; |
0bef57ee | 691 | int working_tree_file = is_null_sha1(elem->sha1); |
8f67f8ae | 692 | int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV; |
a5a818ee | 693 | const char *a_prefix, *b_prefix; |
f23fc773 | 694 | mmfile_t result_file; |
af3feefa | 695 | |
ee1e5412 | 696 | context = opt->context; |
a5a818ee JH |
697 | a_prefix = opt->a_prefix ? opt->a_prefix : "a/"; |
698 | b_prefix = opt->b_prefix ? opt->b_prefix : "b/"; | |
699 | ||
af3feefa | 700 | /* Read the result of merge first */ |
f23fc773 | 701 | if (!working_tree_file) |
7dae8b21 | 702 | result = grab_blob(elem->sha1, elem->mode, &result_size); |
ea726d02 | 703 | else { |
9843a1f6 | 704 | /* Used by diff-tree to read from the working tree */ |
ea726d02 | 705 | struct stat st; |
4fc970c4 JH |
706 | int fd = -1; |
707 | ||
708 | if (lstat(elem->path, &st) < 0) | |
709 | goto deleted_file; | |
710 | ||
711 | if (S_ISLNK(st.st_mode)) { | |
912342d9 JH |
712 | struct strbuf buf = STRBUF_INIT; |
713 | ||
714 | if (strbuf_readlink(&buf, elem->path, st.st_size) < 0) { | |
4fc970c4 JH |
715 | error("readlink(%s): %s", elem->path, |
716 | strerror(errno)); | |
717 | return; | |
718 | } | |
912342d9 JH |
719 | result_size = buf.len; |
720 | result = strbuf_detach(&buf, NULL); | |
4fc970c4 | 721 | elem->mode = canon_mode(st.st_mode); |
7dae8b21 JH |
722 | } else if (S_ISDIR(st.st_mode)) { |
723 | unsigned char sha1[20]; | |
724 | if (resolve_gitlink_ref(elem->path, "HEAD", sha1) < 0) | |
725 | result = grab_blob(elem->sha1, elem->mode, &result_size); | |
726 | else | |
727 | result = grab_blob(sha1, elem->mode, &result_size); | |
91fcbcbd | 728 | } else if (0 <= (fd = open(elem->path, O_RDONLY))) { |
dc49cd76 | 729 | size_t len = xsize_t(st.st_size); |
c697ad14 | 730 | ssize_t done; |
a249a9b5 | 731 | int is_file, i; |
ea726d02 | 732 | |
1b0c7174 | 733 | elem->mode = canon_mode(st.st_mode); |
a249a9b5 JS |
734 | /* if symlinks don't work, assume symlink if all parents |
735 | * are symlinks | |
736 | */ | |
737 | is_file = has_symlinks; | |
738 | for (i = 0; !is_file && i < num_parent; i++) | |
739 | is_file = !S_ISLNK(elem->parent[i].mode); | |
740 | if (!is_file) | |
741 | elem->mode = canon_mode(S_IFLNK); | |
742 | ||
f23fc773 | 743 | result_size = len; |
ea726d02 | 744 | result = xmalloc(len + 1); |
c697ad14 HO |
745 | |
746 | done = read_in_full(fd, result, len); | |
747 | if (done < 0) | |
0721c314 | 748 | die_errno("read error '%s'", elem->path); |
c697ad14 HO |
749 | else if (done < len) |
750 | die("early EOF '%s'", elem->path); | |
751 | ||
ea726d02 | 752 | result[len] = 0; |
5e568f9e AG |
753 | |
754 | /* If not a fake symlink, apply filters, e.g. autocrlf */ | |
755 | if (is_file) { | |
f285a2d7 | 756 | struct strbuf buf = STRBUF_INIT; |
5e568f9e | 757 | |
5e568f9e AG |
758 | if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) { |
759 | free(result); | |
760 | result = strbuf_detach(&buf, &len); | |
761 | result_size = len; | |
762 | } | |
763 | } | |
ea726d02 JH |
764 | } |
765 | else { | |
4fc970c4 | 766 | deleted_file: |
f23fc773 | 767 | result_size = 0; |
713a11fc | 768 | elem->mode = 0; |
28f75818 | 769 | result = xcalloc(1, 1); |
ea726d02 | 770 | } |
4fc970c4 | 771 | |
ea726d02 JH |
772 | if (0 <= fd) |
773 | close(fd); | |
774 | } | |
af3feefa | 775 | |
2386c297 | 776 | for (cnt = 0, cp = result; cp < result + result_size; cp++) { |
af3feefa JH |
777 | if (*cp == '\n') |
778 | cnt++; | |
779 | } | |
f23fc773 | 780 | if (result_size && result[result_size-1] != '\n') |
af3feefa JH |
781 | cnt++; /* incomplete line */ |
782 | ||
8a470ebf | 783 | sline = xcalloc(cnt+2, sizeof(*sline)); |
af3feefa | 784 | sline[0].bol = result; |
8a470ebf | 785 | for (lno = 0; lno <= cnt + 1; lno++) { |
4462731e JH |
786 | sline[lno].lost_tail = &sline[lno].lost_head; |
787 | sline[lno].flag = 0; | |
788 | } | |
2386c297 | 789 | for (lno = 0, cp = result; cp < result + result_size; cp++) { |
af3feefa JH |
790 | if (*cp == '\n') { |
791 | sline[lno].len = cp - sline[lno].bol; | |
af3feefa JH |
792 | lno++; |
793 | if (lno < cnt) | |
794 | sline[lno].bol = cp + 1; | |
795 | } | |
796 | } | |
f23fc773 JH |
797 | if (result_size && result[result_size-1] != '\n') |
798 | sline[cnt-1].len = result_size - (sline[cnt-1].bol - result); | |
799 | ||
800 | result_file.ptr = result; | |
801 | result_file.size = result_size; | |
af3feefa | 802 | |
8a470ebf JH |
803 | /* Even p_lno[cnt+1] is valid -- that is for the end line number |
804 | * for deletion hunk at the end. | |
805 | */ | |
806 | sline[0].p_lno = xcalloc((cnt+2) * num_parent, sizeof(unsigned long)); | |
807 | for (lno = 0; lno <= cnt; lno++) | |
f16706cc JH |
808 | sline[lno+1].p_lno = sline[lno].p_lno + num_parent; |
809 | ||
3c39e9bd JH |
810 | for (i = 0; i < num_parent; i++) { |
811 | int j; | |
812 | for (j = 0; j < i; j++) { | |
a89fccd2 DR |
813 | if (!hashcmp(elem->parent[i].sha1, |
814 | elem->parent[j].sha1)) { | |
3c39e9bd JH |
815 | reuse_combine_diff(sline, cnt, i, j); |
816 | break; | |
817 | } | |
818 | } | |
819 | if (i <= j) | |
7dae8b21 JH |
820 | combine_diff(elem->parent[i].sha1, |
821 | elem->parent[i].mode, | |
822 | &result_file, sline, | |
f16706cc | 823 | cnt, i, num_parent); |
2454c962 JH |
824 | if (elem->parent[i].mode != elem->mode) |
825 | mode_differs = 1; | |
3c39e9bd | 826 | } |
af3feefa | 827 | |
8828cdcb | 828 | show_hunks = make_hunks(sline, cnt, num_parent, dense); |
af3feefa | 829 | |
713a11fc | 830 | if (show_hunks || mode_differs || working_tree_file) { |
9843a1f6 | 831 | const char *abb; |
8f67f8ae | 832 | int use_color = DIFF_OPT_TST(opt, COLOR_DIFF); |
567a03d1 JH |
833 | const char *c_meta = diff_get_color(use_color, DIFF_METAINFO); |
834 | const char *c_reset = diff_get_color(use_color, DIFF_RESET); | |
d5f6a01a JH |
835 | int added = 0; |
836 | int deleted = 0; | |
9843a1f6 | 837 | |
44152787 | 838 | if (rev->loginfo && !rev->no_commit_id) |
02865655 | 839 | show_log(rev); |
567a03d1 | 840 | dump_quoted_path(dense ? "diff --cc " : "diff --combined ", |
462a15bc | 841 | "", elem->path, c_meta, c_reset); |
567a03d1 | 842 | printf("%sindex ", c_meta); |
823bcd6e | 843 | for (i = 0; i < num_parent; i++) { |
297a1aad | 844 | abb = find_unique_abbrev(elem->parent[i].sha1, |
e70c6b35 | 845 | abbrev); |
9843a1f6 | 846 | printf("%s%s", i ? "," : "", abb); |
823bcd6e | 847 | } |
e70c6b35 | 848 | abb = find_unique_abbrev(elem->sha1, abbrev); |
567a03d1 | 849 | printf("..%s%s\n", abb, c_reset); |
2454c962 JH |
850 | |
851 | if (mode_differs) { | |
d5f6a01a JH |
852 | deleted = !elem->mode; |
853 | ||
854 | /* We say it was added if nobody had it */ | |
855 | added = !deleted; | |
d416df88 JH |
856 | for (i = 0; added && i < num_parent; i++) |
857 | if (elem->parent[i].status != | |
858 | DIFF_STATUS_ADDED) | |
859 | added = 0; | |
860 | if (added) | |
567a03d1 JH |
861 | printf("%snew file mode %06o", |
862 | c_meta, elem->mode); | |
d416df88 | 863 | else { |
d5f6a01a | 864 | if (deleted) |
567a03d1 | 865 | printf("%sdeleted file ", c_meta); |
d416df88 JH |
866 | printf("mode "); |
867 | for (i = 0; i < num_parent; i++) { | |
868 | printf("%s%06o", i ? "," : "", | |
869 | elem->parent[i].mode); | |
870 | } | |
871 | if (elem->mode) | |
872 | printf("..%06o", elem->mode); | |
2454c962 | 873 | } |
567a03d1 | 874 | printf("%s\n", c_reset); |
2454c962 | 875 | } |
d5f6a01a | 876 | if (added) |
462a15bc JH |
877 | dump_quoted_path("--- ", "", "/dev/null", |
878 | c_meta, c_reset); | |
d5f6a01a | 879 | else |
a5a818ee | 880 | dump_quoted_path("--- ", a_prefix, elem->path, |
462a15bc | 881 | c_meta, c_reset); |
d5f6a01a | 882 | if (deleted) |
462a15bc JH |
883 | dump_quoted_path("+++ ", "", "/dev/null", |
884 | c_meta, c_reset); | |
d5f6a01a | 885 | else |
a5a818ee | 886 | dump_quoted_path("+++ ", b_prefix, elem->path, |
462a15bc JH |
887 | c_meta, c_reset); |
888 | dump_sline(sline, cnt, num_parent, | |
889 | DIFF_OPT_TST(opt, COLOR_DIFF)); | |
8828cdcb | 890 | } |
af3feefa JH |
891 | free(result); |
892 | ||
2386c297 JH |
893 | for (lno = 0; lno < cnt; lno++) { |
894 | if (sline[lno].lost_head) { | |
895 | struct lline *ll = sline[lno].lost_head; | |
af3feefa JH |
896 | while (ll) { |
897 | struct lline *tmp = ll; | |
898 | ll = ll->next; | |
899 | free(tmp); | |
900 | } | |
901 | } | |
902 | } | |
46dc9412 | 903 | free(sline[0].p_lno); |
af3feefa JH |
904 | free(sline); |
905 | } | |
906 | ||
ee638024 LT |
907 | #define COLONS "::::::::::::::::::::::::::::::::" |
908 | ||
91539833 | 909 | static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct rev_info *rev) |
ee638024 | 910 | { |
91539833 | 911 | struct diff_options *opt = &rev->diffopt; |
310f8b5b | 912 | int i, offset; |
ee638024 LT |
913 | const char *prefix; |
914 | int line_termination, inter_name_termination; | |
915 | ||
916 | line_termination = opt->line_termination; | |
917 | inter_name_termination = '\t'; | |
918 | if (!line_termination) | |
919 | inter_name_termination = 0; | |
920 | ||
44152787 | 921 | if (rev->loginfo && !rev->no_commit_id) |
02865655 | 922 | show_log(rev); |
ee638024 | 923 | |
c6744349 | 924 | if (opt->output_format & DIFF_FORMAT_RAW) { |
0a798076 JH |
925 | offset = strlen(COLONS) - num_parent; |
926 | if (offset < 0) | |
927 | offset = 0; | |
928 | prefix = COLONS + offset; | |
929 | ||
930 | /* Show the modes */ | |
931 | for (i = 0; i < num_parent; i++) { | |
932 | printf("%s%06o", prefix, p->parent[i].mode); | |
933 | prefix = " "; | |
934 | } | |
935 | printf("%s%06o", prefix, p->mode); | |
936 | ||
937 | /* Show sha1's */ | |
938 | for (i = 0; i < num_parent; i++) | |
939 | printf(" %s", diff_unique_abbrev(p->parent[i].sha1, | |
940 | opt->abbrev)); | |
941 | printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev)); | |
942 | } | |
943 | ||
c6744349 | 944 | if (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) { |
d416df88 JH |
945 | for (i = 0; i < num_parent; i++) |
946 | putchar(p->parent[i].status); | |
947 | putchar(inter_name_termination); | |
948 | } | |
0a798076 | 949 | |
663af342 | 950 | write_name_quoted(p->path, stdout, line_termination); |
0a798076 JH |
951 | } |
952 | ||
91539833 | 953 | void show_combined_diff(struct combine_diff_path *p, |
0a798076 JH |
954 | int num_parent, |
955 | int dense, | |
91539833 | 956 | struct rev_info *rev) |
0a798076 | 957 | { |
91539833 | 958 | struct diff_options *opt = &rev->diffopt; |
0a798076 | 959 | if (!p->len) |
91539833 | 960 | return; |
c6744349 TH |
961 | if (opt->output_format & (DIFF_FORMAT_RAW | |
962 | DIFF_FORMAT_NAME | | |
89b0c4b5 | 963 | DIFF_FORMAT_NAME_STATUS)) |
91539833 | 964 | show_raw_diff(p, num_parent, rev); |
89b0c4b5 | 965 | else if (opt->output_format & DIFF_FORMAT_PATCH) |
91539833 | 966 | show_patch_diff(p, num_parent, dense, rev); |
ee638024 LT |
967 | } |
968 | ||
0fe7c1de JH |
969 | void diff_tree_combined(const unsigned char *sha1, |
970 | const unsigned char parent[][20], | |
971 | int num_parent, | |
972 | int dense, | |
973 | struct rev_info *rev) | |
af3feefa | 974 | { |
91539833 | 975 | struct diff_options *opt = &rev->diffopt; |
af3feefa | 976 | struct diff_options diffopts; |
ea726d02 | 977 | struct combine_diff_path *p, *paths = NULL; |
3969cf7d | 978 | int i, num_paths, needsep, show_log_first; |
af3feefa | 979 | |
5b236832 | 980 | diffopts = *opt; |
3969cf7d | 981 | diffopts.output_format = DIFF_FORMAT_NO_OUTPUT; |
8f67f8ae PH |
982 | DIFF_OPT_SET(&diffopts, RECURSIVE); |
983 | DIFF_OPT_CLR(&diffopts, ALLOW_EXTERNAL); | |
af3feefa | 984 | |
44152787 | 985 | show_log_first = !!rev->loginfo && !rev->no_commit_id; |
3969cf7d | 986 | needsep = 0; |
af3feefa | 987 | /* find set of paths that everybody touches */ |
0fe7c1de | 988 | for (i = 0; i < num_parent; i++) { |
965f803c JH |
989 | /* show stat against the first parent even |
990 | * when doing combined diff. | |
991 | */ | |
74e2abe5 JH |
992 | int stat_opt = (opt->output_format & |
993 | (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT)); | |
994 | if (i == 0 && stat_opt) | |
995 | diffopts.output_format = stat_opt; | |
965f803c JH |
996 | else |
997 | diffopts.output_format = DIFF_FORMAT_NO_OUTPUT; | |
0fe7c1de | 998 | diff_tree_sha1(parent[i], sha1, "", &diffopts); |
5b236832 | 999 | diffcore_std(&diffopts); |
af3feefa | 1000 | paths = intersect_paths(paths, i, num_parent); |
eab144ac | 1001 | |
3969cf7d | 1002 | if (show_log_first && i == 0) { |
02865655 | 1003 | show_log(rev); |
3969cf7d JH |
1004 | if (rev->verbose_header && opt->output_format) |
1005 | putchar(opt->line_termination); | |
1006 | } | |
af3feefa JH |
1007 | diff_flush(&diffopts); |
1008 | } | |
1009 | ||
1010 | /* find out surviving paths */ | |
1011 | for (num_paths = 0, p = paths; p; p = p->next) { | |
1012 | if (p->len) | |
1013 | num_paths++; | |
1014 | } | |
e3c3a550 | 1015 | if (num_paths) { |
c6744349 TH |
1016 | if (opt->output_format & (DIFF_FORMAT_RAW | |
1017 | DIFF_FORMAT_NAME | | |
1018 | DIFF_FORMAT_NAME_STATUS)) { | |
86ff1d20 | 1019 | for (p = paths; p; p = p->next) { |
c6744349 TH |
1020 | if (p->len) |
1021 | show_raw_diff(p, num_parent, rev); | |
86ff1d20 | 1022 | } |
3969cf7d | 1023 | needsep = 1; |
86ff1d20 | 1024 | } |
74e2abe5 JH |
1025 | else if (opt->output_format & |
1026 | (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT)) | |
3969cf7d | 1027 | needsep = 1; |
c6744349 | 1028 | if (opt->output_format & DIFF_FORMAT_PATCH) { |
3969cf7d JH |
1029 | if (needsep) |
1030 | putchar(opt->line_termination); | |
c6744349 TH |
1031 | for (p = paths; p; p = p->next) { |
1032 | if (p->len) | |
1033 | show_patch_diff(p, num_parent, dense, | |
1034 | rev); | |
1035 | } | |
af3feefa JH |
1036 | } |
1037 | } | |
1038 | ||
1039 | /* Clean things up */ | |
1040 | while (paths) { | |
ea726d02 | 1041 | struct combine_diff_path *tmp = paths; |
af3feefa JH |
1042 | paths = paths->next; |
1043 | free(tmp); | |
1044 | } | |
af3feefa | 1045 | } |
0fe7c1de JH |
1046 | |
1047 | void diff_tree_combined_merge(const unsigned char *sha1, | |
1048 | int dense, struct rev_info *rev) | |
1049 | { | |
1050 | int num_parent; | |
1051 | const unsigned char (*parent)[20]; | |
1052 | struct commit *commit = lookup_commit(sha1); | |
1053 | struct commit_list *parents; | |
1054 | ||
1055 | /* count parents */ | |
1056 | for (parents = commit->parents, num_parent = 0; | |
1057 | parents; | |
1058 | parents = parents->next, num_parent++) | |
1059 | ; /* nothing */ | |
1060 | ||
1061 | parent = xmalloc(num_parent * sizeof(*parent)); | |
1062 | for (parents = commit->parents, num_parent = 0; | |
1063 | parents; | |
1064 | parents = parents->next, num_parent++) | |
4b25d091 | 1065 | hashcpy((unsigned char *)(parent + num_parent), |
e702496e | 1066 | parents->item->object.sha1); |
0fe7c1de JH |
1067 | diff_tree_combined(sha1, parent, num_parent, dense, rev); |
1068 | } |