7 #include "xdiff-interface.h"
10 static struct combine_diff_path
*intersect_paths(struct combine_diff_path
*curr
, int n
, int num_parent
)
12 struct diff_queue_struct
*q
= &diff_queued_diff
;
13 struct combine_diff_path
*p
;
17 struct combine_diff_path
*list
= NULL
, **tail
= &list
;
18 for (i
= 0; i
< q
->nr
; i
++) {
21 if (diff_unmodified_pair(q
->queue
[i
]))
23 path
= q
->queue
[i
]->two
->path
;
25 p
= xmalloc(combine_diff_path_size(num_parent
, len
));
26 p
->path
= (char*) &(p
->parent
[num_parent
]);
27 memcpy(p
->path
, path
, len
);
32 sizeof(p
->parent
[0]) * num_parent
);
34 hashcpy(p
->sha1
, q
->queue
[i
]->two
->sha1
);
35 p
->mode
= q
->queue
[i
]->two
->mode
;
36 hashcpy(p
->parent
[n
].sha1
, q
->queue
[i
]->one
->sha1
);
37 p
->parent
[n
].mode
= q
->queue
[i
]->one
->mode
;
38 p
->parent
[n
].status
= q
->queue
[i
]->status
;
45 for (p
= curr
; p
; p
= p
->next
) {
49 for (i
= 0; i
< q
->nr
; i
++) {
53 if (diff_unmodified_pair(q
->queue
[i
]))
55 path
= q
->queue
[i
]->two
->path
;
57 if (len
== p
->len
&& !memcmp(path
, p
->path
, len
)) {
59 hashcpy(p
->parent
[n
].sha1
, q
->queue
[i
]->one
->sha1
);
60 p
->parent
[n
].mode
= q
->queue
[i
]->one
->mode
;
61 p
->parent
[n
].status
= q
->queue
[i
]->status
;
71 /* Lines lost from parent */
75 unsigned long parent_map
;
76 char line
[FLEX_ARRAY
];
79 /* Lines surviving in the merge result */
81 struct lline
*lost_head
, **lost_tail
;
84 /* bit 0 up to (N-1) are on if the parent has this line (i.e.
85 * we did not change it).
86 * bit N is used for "interesting" lines, including context.
92 static char *grab_blob(const unsigned char *sha1
, unsigned long *size
)
96 if (is_null_sha1(sha1
)) {
101 blob
= read_sha1_file(sha1
, type
, size
);
102 if (strcmp(type
, blob_type
))
103 die("object '%s' is not a blob!", sha1_to_hex(sha1
));
107 static void append_lost(struct sline
*sline
, int n
, const char *line
, int len
)
110 unsigned long this_mask
= (1UL<<n
);
111 if (line
[len
-1] == '\n')
114 /* Check to see if we can squash things */
115 if (sline
->lost_head
) {
116 struct lline
*last_one
= NULL
;
117 /* We cannot squash it with earlier one */
118 for (lline
= sline
->lost_head
;
121 if (lline
->parent_map
& this_mask
)
123 lline
= last_one
? last_one
->next
: sline
->lost_head
;
125 if (lline
->len
== len
&&
126 !memcmp(lline
->line
, line
, len
)) {
127 lline
->parent_map
|= this_mask
;
134 lline
= xmalloc(sizeof(*lline
) + len
+ 1);
137 lline
->parent_map
= this_mask
;
138 memcpy(lline
->line
, line
, len
);
139 lline
->line
[len
] = 0;
140 *sline
->lost_tail
= lline
;
141 sline
->lost_tail
= &lline
->next
;
144 struct combine_diff_state
{
145 struct xdiff_emit_state xm
;
153 struct sline
*lost_bucket
;
156 static void consume_line(void *state_
, char *line
, unsigned long len
)
158 struct combine_diff_state
*state
= state_
;
159 if (5 < len
&& !memcmp("@@ -", line
, 4)) {
160 if (parse_hunk_header(line
, len
,
161 &state
->ob
, &state
->on
,
162 &state
->nb
, &state
->nn
))
164 state
->lno
= state
->nb
;
166 /* @@ -1,2 +0,0 @@ to remove the
171 /* @@ -X,Y +N,0 @@ removed Y lines
172 * that would have come *after* line N
173 * in the result. Our lost buckets hang
174 * to the line after the removed lines,
176 state
->lost_bucket
= &state
->sline
[state
->nb
];
178 state
->lost_bucket
= &state
->sline
[state
->nb
-1];
179 if (!state
->sline
[state
->nb
-1].p_lno
)
180 state
->sline
[state
->nb
-1].p_lno
=
181 xcalloc(state
->num_parent
,
182 sizeof(unsigned long));
183 state
->sline
[state
->nb
-1].p_lno
[state
->n
] = state
->ob
;
186 if (!state
->lost_bucket
)
187 return; /* not in any hunk yet */
190 append_lost(state
->lost_bucket
, state
->n
, line
+1, len
-1);
193 state
->sline
[state
->lno
-1].flag
|= state
->nmask
;
199 static void combine_diff(const unsigned char *parent
, mmfile_t
*result_file
,
200 struct sline
*sline
, unsigned int cnt
, int n
,
203 unsigned int p_lno
, lno
;
204 unsigned long nmask
= (1UL << n
);
207 mmfile_t parent_file
;
209 struct combine_diff_state state
;
213 return; /* result deleted */
215 parent_file
.ptr
= grab_blob(parent
, &sz
);
216 parent_file
.size
= sz
;
217 xpp
.flags
= XDF_NEED_MINIMAL
;
220 ecb
.outf
= xdiff_outf
;
222 memset(&state
, 0, sizeof(state
));
223 state
.xm
.consume
= consume_line
;
227 state
.num_parent
= num_parent
;
230 xdl_diff(&parent_file
, result_file
, &xpp
, &xecfg
, &ecb
);
231 free(parent_file
.ptr
);
233 /* Assign line numbers for this parent.
235 * sline[lno].p_lno[n] records the first line number
236 * (counting from 1) for parent N if the final hunk display
237 * started by showing sline[lno] (possibly showing the lost
238 * lines attached to it first).
240 for (lno
= 0, p_lno
= 1; lno
<= cnt
; lno
++) {
242 sline
[lno
].p_lno
[n
] = p_lno
;
244 /* How many lines would this sline advance the p_lno? */
245 ll
= sline
[lno
].lost_head
;
247 if (ll
->parent_map
& nmask
)
248 p_lno
++; /* '-' means parent had it */
251 if (lno
< cnt
&& !(sline
[lno
].flag
& nmask
))
252 p_lno
++; /* no '+' means parent had it */
254 sline
[lno
].p_lno
[n
] = p_lno
; /* trailer */
257 static unsigned long context
= 3;
258 static char combine_marker
= '@';
260 static int interesting(struct sline
*sline
, unsigned long all_mask
)
262 /* If some parents lost lines here, or if we have added to
263 * some parent, it is interesting.
265 return ((sline
->flag
& all_mask
) || sline
->lost_head
);
268 static unsigned long adjust_hunk_tail(struct sline
*sline
,
269 unsigned long all_mask
,
270 unsigned long hunk_begin
,
273 /* i points at the first uninteresting line. If the last line
274 * of the hunk was interesting only because it has some
275 * deletion, then it is not all that interesting for the
276 * purpose of giving trailing context lines. This is because
277 * we output '-' line and then unmodified sline[i-1] itself in
278 * that case which gives us one extra context line.
280 if ((hunk_begin
+ 1 <= i
) && !(sline
[i
-1].flag
& all_mask
))
285 static unsigned long find_next(struct sline
*sline
,
289 int look_for_uninteresting
)
291 /* We have examined up to i-1 and are about to look at i.
292 * Find next interesting or uninteresting line. Here,
293 * "interesting" does not mean interesting(), but marked by
294 * the give_context() function below (i.e. it includes context
295 * lines that are not interesting to interesting() function
296 * that are surrounded by interesting() ones.
299 if (look_for_uninteresting
300 ? !(sline
[i
].flag
& mark
)
301 : (sline
[i
].flag
& mark
))
308 static int give_context(struct sline
*sline
, unsigned long cnt
, int num_parent
)
310 unsigned long all_mask
= (1UL<<num_parent
) - 1;
311 unsigned long mark
= (1UL<<num_parent
);
314 /* Two groups of interesting lines may have a short gap of
315 * uninteresting lines. Connect such groups to give them a
318 * We first start from what the interesting() function says,
319 * and mark them with "mark", and paint context lines with the
320 * mark. So interesting() would still say false for such context
321 * lines but they are treated as "interesting" in the end.
323 i
= find_next(sline
, mark
, 0, cnt
, 0);
328 unsigned long j
= (context
< i
) ? (i
- context
) : 0;
331 /* Paint a few lines before the first interesting line. */
333 sline
[j
++].flag
|= mark
;
336 /* we know up to i is to be included. where does the
337 * next uninteresting one start?
339 j
= find_next(sline
, mark
, i
, cnt
, 1);
341 break; /* the rest are all interesting */
343 /* lookahead context lines */
344 k
= find_next(sline
, mark
, j
, cnt
, 0);
345 j
= adjust_hunk_tail(sline
, all_mask
, i
, j
);
347 if (k
< j
+ context
) {
348 /* k is interesting and [j,k) are not, but
349 * paint them interesting because the gap is small.
352 sline
[j
++].flag
|= mark
;
357 /* j is the first uninteresting line and there is
358 * no overlap beyond it within context lines. Paint
359 * the trailing edge a bit.
362 k
= (j
+ context
< cnt
+1) ? j
+ context
: cnt
+1;
364 sline
[j
++].flag
|= mark
;
369 static int make_hunks(struct sline
*sline
, unsigned long cnt
,
370 int num_parent
, int dense
)
372 unsigned long all_mask
= (1UL<<num_parent
) - 1;
373 unsigned long mark
= (1UL<<num_parent
);
375 int has_interesting
= 0;
377 for (i
= 0; i
<= cnt
; i
++) {
378 if (interesting(&sline
[i
], all_mask
))
379 sline
[i
].flag
|= mark
;
381 sline
[i
].flag
&= ~mark
;
384 return give_context(sline
, cnt
, num_parent
);
386 /* Look at each hunk, and if we have changes from only one
387 * parent, or the changes are the same from all but one
388 * parent, mark that uninteresting.
392 unsigned long j
, hunk_begin
, hunk_end
;
393 unsigned long same_diff
;
394 while (i
<= cnt
&& !(sline
[i
].flag
& mark
))
397 break; /* No more interesting hunks */
399 for (j
= i
+ 1; j
<= cnt
; j
++) {
400 if (!(sline
[j
].flag
& mark
)) {
401 /* Look beyond the end to see if there
402 * is an interesting line after this
403 * hunk within context span.
405 unsigned long la
; /* lookahead */
407 la
= adjust_hunk_tail(sline
, all_mask
,
409 la
= (la
+ context
< cnt
+ 1) ?
410 (la
+ context
) : cnt
+ 1;
412 if (sline
[la
].flag
& mark
) {
424 /* [i..hunk_end) are interesting. Now is it really
425 * interesting? We check if there are only two versions
426 * and the result matches one of them. That is, we look
428 * (+) line, which records lines added to which parents;
429 * this line appears in the result.
430 * (-) line, which records from what parents the line
431 * was removed; this line does not appear in the result.
432 * then check the set of parents the result has difference
433 * from, from all lines. If there are lines that has
434 * different set of parents that the result has differences
435 * from, that means we have more than two versions.
437 * Even when we have only two versions, if the result does
438 * not match any of the parents, the it should be considered
439 * interesting. In such a case, we would have all '+' line.
440 * After passing the above "two versions" test, that would
441 * appear as "the same set of parents" to be "all parents".
445 for (j
= i
; j
< hunk_end
&& !has_interesting
; j
++) {
446 unsigned long this_diff
= sline
[j
].flag
& all_mask
;
447 struct lline
*ll
= sline
[j
].lost_head
;
449 /* This has some changes. Is it the
453 same_diff
= this_diff
;
454 else if (same_diff
!= this_diff
) {
459 while (ll
&& !has_interesting
) {
460 /* Lost this line from these parents;
461 * who are they? Are they the same?
463 this_diff
= ll
->parent_map
;
465 same_diff
= this_diff
;
466 else if (same_diff
!= this_diff
) {
473 if (!has_interesting
&& same_diff
!= all_mask
) {
474 /* This hunk is not that interesting after all */
475 for (j
= hunk_begin
; j
< hunk_end
; j
++)
476 sline
[j
].flag
&= ~mark
;
481 has_interesting
= give_context(sline
, cnt
, num_parent
);
482 return has_interesting
;
485 static void show_parent_lno(struct sline
*sline
, unsigned long l0
, unsigned long l1
, int n
)
487 l0
= sline
[l0
].p_lno
[n
];
488 l1
= sline
[l1
].p_lno
[n
];
489 printf(" -%lu,%lu", l0
, l1
-l0
);
492 static int hunk_comment_line(const char *bol
)
494 int ch
= *bol
& 0xff;
495 return (isalpha(ch
) || ch
== '_' || ch
== '$');
498 static void dump_sline(struct sline
*sline
, unsigned long cnt
, int num_parent
,
501 unsigned long mark
= (1UL<<num_parent
);
503 unsigned long lno
= 0;
504 const char *c_frag
= diff_get_color(use_color
, DIFF_FRAGINFO
);
505 const char *c_new
= diff_get_color(use_color
, DIFF_FILE_NEW
);
506 const char *c_old
= diff_get_color(use_color
, DIFF_FILE_OLD
);
507 const char *c_plain
= diff_get_color(use_color
, DIFF_PLAIN
);
508 const char *c_reset
= diff_get_color(use_color
, DIFF_RESET
);
511 return; /* result deleted */
514 struct sline
*sl
= &sline
[lno
];
515 unsigned long hunk_end
;
516 unsigned long rlines
;
517 const char *hunk_comment
= NULL
;
519 while (lno
<= cnt
&& !(sline
[lno
].flag
& mark
)) {
520 if (hunk_comment_line(sline
[lno
].bol
))
521 hunk_comment
= sline
[lno
].bol
;
527 for (hunk_end
= lno
+ 1; hunk_end
<= cnt
; hunk_end
++)
528 if (!(sline
[hunk_end
].flag
& mark
))
531 rlines
= hunk_end
- lno
;
533 rlines
--; /* pointing at the last delete hunk */
534 fputs(c_frag
, stdout
);
535 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
536 for (i
= 0; i
< num_parent
; i
++)
537 show_parent_lno(sline
, lno
, hunk_end
, i
);
538 printf(" +%lu,%lu ", lno
+1, rlines
);
539 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
543 for (i
= 0; i
< 40; i
++) {
544 int ch
= hunk_comment
[i
] & 0xff;
545 if (!ch
|| ch
== '\n')
552 for (i
= 0; i
< comment_end
; i
++)
553 putchar(hunk_comment
[i
]);
556 printf("%s\n", c_reset
);
557 while (lno
< hunk_end
) {
560 unsigned long p_mask
;
564 fputs(c_old
, stdout
);
565 for (j
= 0; j
< num_parent
; j
++) {
566 if (ll
->parent_map
& (1UL<<j
))
571 printf("%s%s\n", ll
->line
, c_reset
);
577 if (!(sl
->flag
& (mark
-1)))
578 fputs(c_plain
, stdout
);
580 fputs(c_new
, stdout
);
581 for (j
= 0; j
< num_parent
; j
++) {
582 if (p_mask
& sl
->flag
)
588 printf("%.*s%s\n", sl
->len
, sl
->bol
, c_reset
);
593 static void reuse_combine_diff(struct sline
*sline
, unsigned long cnt
,
596 /* We have already examined parent j and we know parent i
597 * and parent j are the same, so reuse the combined result
598 * of parent j for parent i.
600 unsigned long lno
, imask
, jmask
;
604 for (lno
= 0; lno
<= cnt
; lno
++) {
605 struct lline
*ll
= sline
->lost_head
;
606 sline
->p_lno
[i
] = sline
->p_lno
[j
];
608 if (ll
->parent_map
& jmask
)
609 ll
->parent_map
|= imask
;
612 if (sline
->flag
& jmask
)
613 sline
->flag
|= imask
;
616 /* the overall size of the file (sline[cnt]) */
617 sline
->p_lno
[i
] = sline
->p_lno
[j
];
620 static void dump_quoted_path(const char *prefix
, const char *path
,
621 const char *c_meta
, const char *c_reset
)
623 printf("%s%s", c_meta
, prefix
);
624 if (quote_c_style(path
, NULL
, NULL
, 0))
625 quote_c_style(path
, NULL
, stdout
, 0);
628 printf("%s\n", c_reset
);
631 static void show_patch_diff(struct combine_diff_path
*elem
, int num_parent
,
632 int dense
, struct rev_info
*rev
)
634 struct diff_options
*opt
= &rev
->diffopt
;
635 unsigned long result_size
, cnt
, lno
;
637 struct sline
*sline
; /* survived lines */
638 int mode_differs
= 0;
640 int working_tree_file
= is_null_sha1(elem
->sha1
);
641 int abbrev
= opt
->full_index
? 40 : DEFAULT_ABBREV
;
642 mmfile_t result_file
;
644 context
= opt
->context
;
645 /* Read the result of merge first */
646 if (!working_tree_file
)
647 result
= grab_blob(elem
->sha1
, &result_size
);
649 /* Used by diff-tree to read from the working tree */
652 if (0 <= (fd
= open(elem
->path
, O_RDONLY
)) &&
654 int len
= st
.st_size
;
657 elem
->mode
= canon_mode(st
.st_mode
);
659 result
= xmalloc(len
+ 1);
661 int done
= xread(fd
, result
+sz
, len
-sz
);
665 die("read error '%s'", elem
->path
);
674 result
= xcalloc(1, 1);
680 for (cnt
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
684 if (result_size
&& result
[result_size
-1] != '\n')
685 cnt
++; /* incomplete line */
687 sline
= xcalloc(cnt
+2, sizeof(*sline
));
688 sline
[0].bol
= result
;
689 for (lno
= 0; lno
<= cnt
+ 1; lno
++) {
690 sline
[lno
].lost_tail
= &sline
[lno
].lost_head
;
693 for (lno
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
695 sline
[lno
].len
= cp
- sline
[lno
].bol
;
698 sline
[lno
].bol
= cp
+ 1;
701 if (result_size
&& result
[result_size
-1] != '\n')
702 sline
[cnt
-1].len
= result_size
- (sline
[cnt
-1].bol
- result
);
704 result_file
.ptr
= result
;
705 result_file
.size
= result_size
;
707 /* Even p_lno[cnt+1] is valid -- that is for the end line number
708 * for deletion hunk at the end.
710 sline
[0].p_lno
= xcalloc((cnt
+2) * num_parent
, sizeof(unsigned long));
711 for (lno
= 0; lno
<= cnt
; lno
++)
712 sline
[lno
+1].p_lno
= sline
[lno
].p_lno
+ num_parent
;
714 for (i
= 0; i
< num_parent
; i
++) {
716 for (j
= 0; j
< i
; j
++) {
717 if (!hashcmp(elem
->parent
[i
].sha1
,
718 elem
->parent
[j
].sha1
)) {
719 reuse_combine_diff(sline
, cnt
, i
, j
);
724 combine_diff(elem
->parent
[i
].sha1
, &result_file
, sline
,
726 if (elem
->parent
[i
].mode
!= elem
->mode
)
730 show_hunks
= make_hunks(sline
, cnt
, num_parent
, dense
);
732 if (show_hunks
|| mode_differs
|| working_tree_file
) {
734 int use_color
= opt
->color_diff
;
735 const char *c_meta
= diff_get_color(use_color
, DIFF_METAINFO
);
736 const char *c_reset
= diff_get_color(use_color
, DIFF_RESET
);
741 show_log(rev
, opt
->msg_sep
);
742 dump_quoted_path(dense
? "diff --cc " : "diff --combined ",
743 elem
->path
, c_meta
, c_reset
);
744 printf("%sindex ", c_meta
);
745 for (i
= 0; i
< num_parent
; i
++) {
746 abb
= find_unique_abbrev(elem
->parent
[i
].sha1
,
748 printf("%s%s", i
? "," : "", abb
);
750 abb
= find_unique_abbrev(elem
->sha1
, abbrev
);
751 printf("..%s%s\n", abb
, c_reset
);
754 deleted
= !elem
->mode
;
756 /* We say it was added if nobody had it */
758 for (i
= 0; added
&& i
< num_parent
; i
++)
759 if (elem
->parent
[i
].status
!=
763 printf("%snew file mode %06o",
767 printf("%sdeleted file ", c_meta
);
769 for (i
= 0; i
< num_parent
; i
++) {
770 printf("%s%06o", i
? "," : "",
771 elem
->parent
[i
].mode
);
774 printf("..%06o", elem
->mode
);
776 printf("%s\n", c_reset
);
779 dump_quoted_path("--- /dev/", "null", c_meta
, c_reset
);
781 dump_quoted_path("--- a/", elem
->path
, c_meta
, c_reset
);
783 dump_quoted_path("+++ /dev/", "null", c_meta
, c_reset
);
785 dump_quoted_path("+++ b/", elem
->path
, c_meta
, c_reset
);
786 dump_sline(sline
, cnt
, num_parent
, opt
->color_diff
);
790 for (lno
= 0; lno
< cnt
; lno
++) {
791 if (sline
[lno
].lost_head
) {
792 struct lline
*ll
= sline
[lno
].lost_head
;
794 struct lline
*tmp
= ll
;
800 free(sline
[0].p_lno
);
804 #define COLONS "::::::::::::::::::::::::::::::::"
806 static void show_raw_diff(struct combine_diff_path
*p
, int num_parent
, struct rev_info
*rev
)
808 struct diff_options
*opt
= &rev
->diffopt
;
811 int line_termination
, inter_name_termination
;
813 line_termination
= opt
->line_termination
;
814 inter_name_termination
= '\t';
815 if (!line_termination
)
816 inter_name_termination
= 0;
819 show_log(rev
, opt
->msg_sep
);
821 if (opt
->output_format
& DIFF_FORMAT_RAW
) {
822 offset
= strlen(COLONS
) - num_parent
;
825 prefix
= COLONS
+ offset
;
828 for (i
= 0; i
< num_parent
; i
++) {
829 printf("%s%06o", prefix
, p
->parent
[i
].mode
);
832 printf("%s%06o", prefix
, p
->mode
);
835 for (i
= 0; i
< num_parent
; i
++)
836 printf(" %s", diff_unique_abbrev(p
->parent
[i
].sha1
,
838 printf(" %s ", diff_unique_abbrev(p
->sha1
, opt
->abbrev
));
841 if (opt
->output_format
& (DIFF_FORMAT_RAW
| DIFF_FORMAT_NAME_STATUS
)) {
842 for (i
= 0; i
< num_parent
; i
++)
843 putchar(p
->parent
[i
].status
);
844 putchar(inter_name_termination
);
847 if (line_termination
) {
848 if (quote_c_style(p
->path
, NULL
, NULL
, 0))
849 quote_c_style(p
->path
, NULL
, stdout
, 0);
851 printf("%s", p
->path
);
852 putchar(line_termination
);
855 printf("%s%c", p
->path
, line_termination
);
859 void show_combined_diff(struct combine_diff_path
*p
,
862 struct rev_info
*rev
)
864 struct diff_options
*opt
= &rev
->diffopt
;
867 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
869 DIFF_FORMAT_NAME_STATUS
))
870 show_raw_diff(p
, num_parent
, rev
);
871 else if (opt
->output_format
& DIFF_FORMAT_PATCH
)
872 show_patch_diff(p
, num_parent
, dense
, rev
);
875 void diff_tree_combined(const unsigned char *sha1
,
876 const unsigned char parent
[][20],
879 struct rev_info
*rev
)
881 struct diff_options
*opt
= &rev
->diffopt
;
882 struct diff_options diffopts
;
883 struct combine_diff_path
*p
, *paths
= NULL
;
884 int i
, num_paths
, needsep
, show_log_first
;
887 diffopts
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
888 diffopts
.recursive
= 1;
890 show_log_first
= !!rev
->loginfo
;
892 /* find set of paths that everybody touches */
893 for (i
= 0; i
< num_parent
; i
++) {
894 /* show stat against the first parent even
895 * when doing combined diff.
897 int stat_opt
= (opt
->output_format
&
898 (DIFF_FORMAT_NUMSTAT
|DIFF_FORMAT_DIFFSTAT
));
899 if (i
== 0 && stat_opt
)
900 diffopts
.output_format
= stat_opt
;
902 diffopts
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
903 diff_tree_sha1(parent
[i
], sha1
, "", &diffopts
);
904 diffcore_std(&diffopts
);
905 paths
= intersect_paths(paths
, i
, num_parent
);
907 if (show_log_first
&& i
== 0) {
908 show_log(rev
, opt
->msg_sep
);
909 if (rev
->verbose_header
&& opt
->output_format
)
910 putchar(opt
->line_termination
);
912 diff_flush(&diffopts
);
915 /* find out surviving paths */
916 for (num_paths
= 0, p
= paths
; p
; p
= p
->next
) {
921 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
923 DIFF_FORMAT_NAME_STATUS
)) {
924 for (p
= paths
; p
; p
= p
->next
) {
926 show_raw_diff(p
, num_parent
, rev
);
930 else if (opt
->output_format
&
931 (DIFF_FORMAT_NUMSTAT
|DIFF_FORMAT_DIFFSTAT
))
933 if (opt
->output_format
& DIFF_FORMAT_PATCH
) {
935 putchar(opt
->line_termination
);
936 for (p
= paths
; p
; p
= p
->next
) {
938 show_patch_diff(p
, num_parent
, dense
,
944 /* Clean things up */
946 struct combine_diff_path
*tmp
= paths
;
952 void diff_tree_combined_merge(const unsigned char *sha1
,
953 int dense
, struct rev_info
*rev
)
956 const unsigned char (*parent
)[20];
957 struct commit
*commit
= lookup_commit(sha1
);
958 struct commit_list
*parents
;
961 for (parents
= commit
->parents
, num_parent
= 0;
963 parents
= parents
->next
, num_parent
++)
966 parent
= xmalloc(num_parent
* sizeof(*parent
));
967 for (parents
= commit
->parents
, num_parent
= 0;
969 parents
= parents
->next
, num_parent
++)
970 hashcpy((unsigned char*)(parent
+ num_parent
),
971 parents
->item
->object
.sha1
);
972 diff_tree_combined(sha1
, parent
, num_parent
, dense
, rev
);