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
)
95 enum object_type type
;
96 if (is_null_sha1(sha1
)) {
101 blob
= read_sha1_file(sha1
, &type
, size
);
102 if (type
!= OBJ_BLOB
)
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
;
218 memset(&xecfg
, 0, sizeof(xecfg
));
219 ecb
.outf
= xdiff_outf
;
221 memset(&state
, 0, sizeof(state
));
222 state
.xm
.consume
= consume_line
;
226 state
.num_parent
= num_parent
;
229 xdi_diff(&parent_file
, result_file
, &xpp
, &xecfg
, &ecb
);
230 free(parent_file
.ptr
);
232 /* Assign line numbers for this parent.
234 * sline[lno].p_lno[n] records the first line number
235 * (counting from 1) for parent N if the final hunk display
236 * started by showing sline[lno] (possibly showing the lost
237 * lines attached to it first).
239 for (lno
= 0, p_lno
= 1; lno
<= cnt
; lno
++) {
241 sline
[lno
].p_lno
[n
] = p_lno
;
243 /* How many lines would this sline advance the p_lno? */
244 ll
= sline
[lno
].lost_head
;
246 if (ll
->parent_map
& nmask
)
247 p_lno
++; /* '-' means parent had it */
250 if (lno
< cnt
&& !(sline
[lno
].flag
& nmask
))
251 p_lno
++; /* no '+' means parent had it */
253 sline
[lno
].p_lno
[n
] = p_lno
; /* trailer */
256 static unsigned long context
= 3;
257 static char combine_marker
= '@';
259 static int interesting(struct sline
*sline
, unsigned long all_mask
)
261 /* If some parents lost lines here, or if we have added to
262 * some parent, it is interesting.
264 return ((sline
->flag
& all_mask
) || sline
->lost_head
);
267 static unsigned long adjust_hunk_tail(struct sline
*sline
,
268 unsigned long all_mask
,
269 unsigned long hunk_begin
,
272 /* i points at the first uninteresting line. If the last line
273 * of the hunk was interesting only because it has some
274 * deletion, then it is not all that interesting for the
275 * purpose of giving trailing context lines. This is because
276 * we output '-' line and then unmodified sline[i-1] itself in
277 * that case which gives us one extra context line.
279 if ((hunk_begin
+ 1 <= i
) && !(sline
[i
-1].flag
& all_mask
))
284 static unsigned long find_next(struct sline
*sline
,
288 int look_for_uninteresting
)
290 /* We have examined up to i-1 and are about to look at i.
291 * Find next interesting or uninteresting line. Here,
292 * "interesting" does not mean interesting(), but marked by
293 * the give_context() function below (i.e. it includes context
294 * lines that are not interesting to interesting() function
295 * that are surrounded by interesting() ones.
298 if (look_for_uninteresting
299 ? !(sline
[i
].flag
& mark
)
300 : (sline
[i
].flag
& mark
))
307 static int give_context(struct sline
*sline
, unsigned long cnt
, int num_parent
)
309 unsigned long all_mask
= (1UL<<num_parent
) - 1;
310 unsigned long mark
= (1UL<<num_parent
);
313 /* Two groups of interesting lines may have a short gap of
314 * uninteresting lines. Connect such groups to give them a
317 * We first start from what the interesting() function says,
318 * and mark them with "mark", and paint context lines with the
319 * mark. So interesting() would still say false for such context
320 * lines but they are treated as "interesting" in the end.
322 i
= find_next(sline
, mark
, 0, cnt
, 0);
327 unsigned long j
= (context
< i
) ? (i
- context
) : 0;
330 /* Paint a few lines before the first interesting line. */
332 sline
[j
++].flag
|= mark
;
335 /* we know up to i is to be included. where does the
336 * next uninteresting one start?
338 j
= find_next(sline
, mark
, i
, cnt
, 1);
340 break; /* the rest are all interesting */
342 /* lookahead context lines */
343 k
= find_next(sline
, mark
, j
, cnt
, 0);
344 j
= adjust_hunk_tail(sline
, all_mask
, i
, j
);
346 if (k
< j
+ context
) {
347 /* k is interesting and [j,k) are not, but
348 * paint them interesting because the gap is small.
351 sline
[j
++].flag
|= mark
;
356 /* j is the first uninteresting line and there is
357 * no overlap beyond it within context lines. Paint
358 * the trailing edge a bit.
361 k
= (j
+ context
< cnt
+1) ? j
+ context
: cnt
+1;
363 sline
[j
++].flag
|= mark
;
368 static int make_hunks(struct sline
*sline
, unsigned long cnt
,
369 int num_parent
, int dense
)
371 unsigned long all_mask
= (1UL<<num_parent
) - 1;
372 unsigned long mark
= (1UL<<num_parent
);
374 int has_interesting
= 0;
376 for (i
= 0; i
<= cnt
; i
++) {
377 if (interesting(&sline
[i
], all_mask
))
378 sline
[i
].flag
|= mark
;
380 sline
[i
].flag
&= ~mark
;
383 return give_context(sline
, cnt
, num_parent
);
385 /* Look at each hunk, and if we have changes from only one
386 * parent, or the changes are the same from all but one
387 * parent, mark that uninteresting.
391 unsigned long j
, hunk_begin
, hunk_end
;
392 unsigned long same_diff
;
393 while (i
<= cnt
&& !(sline
[i
].flag
& mark
))
396 break; /* No more interesting hunks */
398 for (j
= i
+ 1; j
<= cnt
; j
++) {
399 if (!(sline
[j
].flag
& mark
)) {
400 /* Look beyond the end to see if there
401 * is an interesting line after this
402 * hunk within context span.
404 unsigned long la
; /* lookahead */
406 la
= adjust_hunk_tail(sline
, all_mask
,
408 la
= (la
+ context
< cnt
+ 1) ?
409 (la
+ context
) : cnt
+ 1;
411 if (sline
[la
].flag
& mark
) {
423 /* [i..hunk_end) are interesting. Now is it really
424 * interesting? We check if there are only two versions
425 * and the result matches one of them. That is, we look
427 * (+) line, which records lines added to which parents;
428 * this line appears in the result.
429 * (-) line, which records from what parents the line
430 * was removed; this line does not appear in the result.
431 * then check the set of parents the result has difference
432 * from, from all lines. If there are lines that has
433 * different set of parents that the result has differences
434 * from, that means we have more than two versions.
436 * Even when we have only two versions, if the result does
437 * not match any of the parents, the it should be considered
438 * interesting. In such a case, we would have all '+' line.
439 * After passing the above "two versions" test, that would
440 * appear as "the same set of parents" to be "all parents".
444 for (j
= i
; j
< hunk_end
&& !has_interesting
; j
++) {
445 unsigned long this_diff
= sline
[j
].flag
& all_mask
;
446 struct lline
*ll
= sline
[j
].lost_head
;
448 /* This has some changes. Is it the
452 same_diff
= this_diff
;
453 else if (same_diff
!= this_diff
) {
458 while (ll
&& !has_interesting
) {
459 /* Lost this line from these parents;
460 * who are they? Are they the same?
462 this_diff
= ll
->parent_map
;
464 same_diff
= this_diff
;
465 else if (same_diff
!= this_diff
) {
472 if (!has_interesting
&& same_diff
!= all_mask
) {
473 /* This hunk is not that interesting after all */
474 for (j
= hunk_begin
; j
< hunk_end
; j
++)
475 sline
[j
].flag
&= ~mark
;
480 has_interesting
= give_context(sline
, cnt
, num_parent
);
481 return has_interesting
;
484 static void show_parent_lno(struct sline
*sline
, unsigned long l0
, unsigned long l1
, int n
, unsigned long null_context
)
486 l0
= sline
[l0
].p_lno
[n
];
487 l1
= sline
[l1
].p_lno
[n
];
488 printf(" -%lu,%lu", l0
, l1
-l0
-null_context
);
491 static int hunk_comment_line(const char *bol
)
498 return (isalpha(ch
) || ch
== '_' || ch
== '$');
501 static void dump_sline(struct sline
*sline
, unsigned long cnt
, int num_parent
,
504 unsigned long mark
= (1UL<<num_parent
);
506 unsigned long lno
= 0;
507 const char *c_frag
= diff_get_color(use_color
, DIFF_FRAGINFO
);
508 const char *c_new
= diff_get_color(use_color
, DIFF_FILE_NEW
);
509 const char *c_old
= diff_get_color(use_color
, DIFF_FILE_OLD
);
510 const char *c_plain
= diff_get_color(use_color
, DIFF_PLAIN
);
511 const char *c_reset
= diff_get_color(use_color
, DIFF_RESET
);
514 return; /* result deleted */
517 struct sline
*sl
= &sline
[lno
];
518 unsigned long hunk_end
;
519 unsigned long rlines
;
520 const char *hunk_comment
= NULL
;
521 unsigned long null_context
= 0;
523 while (lno
<= cnt
&& !(sline
[lno
].flag
& mark
)) {
524 if (hunk_comment_line(sline
[lno
].bol
))
525 hunk_comment
= sline
[lno
].bol
;
531 for (hunk_end
= lno
+ 1; hunk_end
<= cnt
; hunk_end
++)
532 if (!(sline
[hunk_end
].flag
& mark
))
535 rlines
= hunk_end
- lno
;
537 rlines
--; /* pointing at the last delete hunk */
541 * Even when running with --unified=0, all
542 * lines in the hunk needs to be processed in
543 * the loop below in order to show the
544 * deletion recorded in lost_head. However,
545 * we do not want to show the resulting line
546 * with all blank context markers in such a
550 for (j
= lno
; j
< hunk_end
; j
++)
551 if (!(sline
[j
].flag
& (mark
-1)))
553 rlines
-= null_context
;
556 fputs(c_frag
, stdout
);
557 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
558 for (i
= 0; i
< num_parent
; i
++)
559 show_parent_lno(sline
, lno
, hunk_end
, i
, null_context
);
560 printf(" +%lu,%lu ", lno
+1, rlines
);
561 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
565 for (i
= 0; i
< 40; i
++) {
566 int ch
= hunk_comment
[i
] & 0xff;
567 if (!ch
|| ch
== '\n')
574 for (i
= 0; i
< comment_end
; i
++)
575 putchar(hunk_comment
[i
]);
578 printf("%s\n", c_reset
);
579 while (lno
< hunk_end
) {
582 unsigned long p_mask
;
586 fputs(c_old
, stdout
);
587 for (j
= 0; j
< num_parent
; j
++) {
588 if (ll
->parent_map
& (1UL<<j
))
593 printf("%s%s\n", ll
->line
, c_reset
);
599 if (!(sl
->flag
& (mark
-1))) {
601 * This sline was here to hang the
602 * lost lines in front of it.
606 fputs(c_plain
, stdout
);
609 fputs(c_new
, stdout
);
610 for (j
= 0; j
< num_parent
; j
++) {
611 if (p_mask
& sl
->flag
)
617 printf("%.*s%s\n", sl
->len
, sl
->bol
, c_reset
);
622 static void reuse_combine_diff(struct sline
*sline
, unsigned long cnt
,
625 /* We have already examined parent j and we know parent i
626 * and parent j are the same, so reuse the combined result
627 * of parent j for parent i.
629 unsigned long lno
, imask
, jmask
;
633 for (lno
= 0; lno
<= cnt
; lno
++) {
634 struct lline
*ll
= sline
->lost_head
;
635 sline
->p_lno
[i
] = sline
->p_lno
[j
];
637 if (ll
->parent_map
& jmask
)
638 ll
->parent_map
|= imask
;
641 if (sline
->flag
& jmask
)
642 sline
->flag
|= imask
;
645 /* the overall size of the file (sline[cnt]) */
646 sline
->p_lno
[i
] = sline
->p_lno
[j
];
649 static void dump_quoted_path(const char *head
,
652 const char *c_meta
, const char *c_reset
)
654 static struct strbuf buf
= STRBUF_INIT
;
657 strbuf_addstr(&buf
, c_meta
);
658 strbuf_addstr(&buf
, head
);
659 quote_two_c_style(&buf
, prefix
, path
, 0);
660 strbuf_addstr(&buf
, c_reset
);
664 static void show_patch_diff(struct combine_diff_path
*elem
, int num_parent
,
665 int dense
, struct rev_info
*rev
)
667 struct diff_options
*opt
= &rev
->diffopt
;
668 unsigned long result_size
, cnt
, lno
;
670 struct sline
*sline
; /* survived lines */
671 int mode_differs
= 0;
673 int working_tree_file
= is_null_sha1(elem
->sha1
);
674 int abbrev
= DIFF_OPT_TST(opt
, FULL_INDEX
) ? 40 : DEFAULT_ABBREV
;
675 mmfile_t result_file
;
677 context
= opt
->context
;
678 /* Read the result of merge first */
679 if (!working_tree_file
)
680 result
= grab_blob(elem
->sha1
, &result_size
);
682 /* Used by diff-tree to read from the working tree */
686 if (lstat(elem
->path
, &st
) < 0)
689 if (S_ISLNK(st
.st_mode
)) {
690 size_t len
= xsize_t(st
.st_size
);
692 result
= xmalloc(len
+ 1);
693 if (result_size
!= readlink(elem
->path
, result
, len
)) {
694 error("readlink(%s): %s", elem
->path
,
699 elem
->mode
= canon_mode(st
.st_mode
);
701 else if (0 <= (fd
= open(elem
->path
, O_RDONLY
)) &&
703 size_t len
= xsize_t(st
.st_size
);
707 elem
->mode
= canon_mode(st
.st_mode
);
708 /* if symlinks don't work, assume symlink if all parents
711 is_file
= has_symlinks
;
712 for (i
= 0; !is_file
&& i
< num_parent
; i
++)
713 is_file
= !S_ISLNK(elem
->parent
[i
].mode
);
715 elem
->mode
= canon_mode(S_IFLNK
);
718 result
= xmalloc(len
+ 1);
720 done
= read_in_full(fd
, result
, len
);
722 die("read error '%s'", elem
->path
);
724 die("early EOF '%s'", elem
->path
);
732 result
= xcalloc(1, 1);
739 for (cnt
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
743 if (result_size
&& result
[result_size
-1] != '\n')
744 cnt
++; /* incomplete line */
746 sline
= xcalloc(cnt
+2, sizeof(*sline
));
747 sline
[0].bol
= result
;
748 for (lno
= 0; lno
<= cnt
+ 1; lno
++) {
749 sline
[lno
].lost_tail
= &sline
[lno
].lost_head
;
752 for (lno
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
754 sline
[lno
].len
= cp
- sline
[lno
].bol
;
757 sline
[lno
].bol
= cp
+ 1;
760 if (result_size
&& result
[result_size
-1] != '\n')
761 sline
[cnt
-1].len
= result_size
- (sline
[cnt
-1].bol
- result
);
763 result_file
.ptr
= result
;
764 result_file
.size
= result_size
;
766 /* Even p_lno[cnt+1] is valid -- that is for the end line number
767 * for deletion hunk at the end.
769 sline
[0].p_lno
= xcalloc((cnt
+2) * num_parent
, sizeof(unsigned long));
770 for (lno
= 0; lno
<= cnt
; lno
++)
771 sline
[lno
+1].p_lno
= sline
[lno
].p_lno
+ num_parent
;
773 for (i
= 0; i
< num_parent
; i
++) {
775 for (j
= 0; j
< i
; j
++) {
776 if (!hashcmp(elem
->parent
[i
].sha1
,
777 elem
->parent
[j
].sha1
)) {
778 reuse_combine_diff(sline
, cnt
, i
, j
);
783 combine_diff(elem
->parent
[i
].sha1
, &result_file
, sline
,
785 if (elem
->parent
[i
].mode
!= elem
->mode
)
789 show_hunks
= make_hunks(sline
, cnt
, num_parent
, dense
);
791 if (show_hunks
|| mode_differs
|| working_tree_file
) {
793 int use_color
= DIFF_OPT_TST(opt
, COLOR_DIFF
);
794 const char *c_meta
= diff_get_color(use_color
, DIFF_METAINFO
);
795 const char *c_reset
= diff_get_color(use_color
, DIFF_RESET
);
799 if (rev
->loginfo
&& !rev
->no_commit_id
)
801 dump_quoted_path(dense
? "diff --cc " : "diff --combined ",
802 "", elem
->path
, c_meta
, c_reset
);
803 printf("%sindex ", c_meta
);
804 for (i
= 0; i
< num_parent
; i
++) {
805 abb
= find_unique_abbrev(elem
->parent
[i
].sha1
,
807 printf("%s%s", i
? "," : "", abb
);
809 abb
= find_unique_abbrev(elem
->sha1
, abbrev
);
810 printf("..%s%s\n", abb
, c_reset
);
813 deleted
= !elem
->mode
;
815 /* We say it was added if nobody had it */
817 for (i
= 0; added
&& i
< num_parent
; i
++)
818 if (elem
->parent
[i
].status
!=
822 printf("%snew file mode %06o",
826 printf("%sdeleted file ", c_meta
);
828 for (i
= 0; i
< num_parent
; i
++) {
829 printf("%s%06o", i
? "," : "",
830 elem
->parent
[i
].mode
);
833 printf("..%06o", elem
->mode
);
835 printf("%s\n", c_reset
);
838 dump_quoted_path("--- ", "", "/dev/null",
841 dump_quoted_path("--- ", opt
->a_prefix
, elem
->path
,
844 dump_quoted_path("+++ ", "", "/dev/null",
847 dump_quoted_path("+++ ", opt
->b_prefix
, elem
->path
,
849 dump_sline(sline
, cnt
, num_parent
,
850 DIFF_OPT_TST(opt
, COLOR_DIFF
));
854 for (lno
= 0; lno
< cnt
; lno
++) {
855 if (sline
[lno
].lost_head
) {
856 struct lline
*ll
= sline
[lno
].lost_head
;
858 struct lline
*tmp
= ll
;
864 free(sline
[0].p_lno
);
868 #define COLONS "::::::::::::::::::::::::::::::::"
870 static void show_raw_diff(struct combine_diff_path
*p
, int num_parent
, struct rev_info
*rev
)
872 struct diff_options
*opt
= &rev
->diffopt
;
875 int line_termination
, inter_name_termination
;
877 line_termination
= opt
->line_termination
;
878 inter_name_termination
= '\t';
879 if (!line_termination
)
880 inter_name_termination
= 0;
882 if (rev
->loginfo
&& !rev
->no_commit_id
)
885 if (opt
->output_format
& DIFF_FORMAT_RAW
) {
886 offset
= strlen(COLONS
) - num_parent
;
889 prefix
= COLONS
+ offset
;
892 for (i
= 0; i
< num_parent
; i
++) {
893 printf("%s%06o", prefix
, p
->parent
[i
].mode
);
896 printf("%s%06o", prefix
, p
->mode
);
899 for (i
= 0; i
< num_parent
; i
++)
900 printf(" %s", diff_unique_abbrev(p
->parent
[i
].sha1
,
902 printf(" %s ", diff_unique_abbrev(p
->sha1
, opt
->abbrev
));
905 if (opt
->output_format
& (DIFF_FORMAT_RAW
| DIFF_FORMAT_NAME_STATUS
)) {
906 for (i
= 0; i
< num_parent
; i
++)
907 putchar(p
->parent
[i
].status
);
908 putchar(inter_name_termination
);
911 write_name_quoted(p
->path
, stdout
, line_termination
);
914 void show_combined_diff(struct combine_diff_path
*p
,
917 struct rev_info
*rev
)
919 struct diff_options
*opt
= &rev
->diffopt
;
922 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
924 DIFF_FORMAT_NAME_STATUS
))
925 show_raw_diff(p
, num_parent
, rev
);
926 else if (opt
->output_format
& DIFF_FORMAT_PATCH
)
927 show_patch_diff(p
, num_parent
, dense
, rev
);
930 void diff_tree_combined(const unsigned char *sha1
,
931 const unsigned char parent
[][20],
934 struct rev_info
*rev
)
936 struct diff_options
*opt
= &rev
->diffopt
;
937 struct diff_options diffopts
;
938 struct combine_diff_path
*p
, *paths
= NULL
;
939 int i
, num_paths
, needsep
, show_log_first
;
942 diffopts
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
943 DIFF_OPT_SET(&diffopts
, RECURSIVE
);
944 DIFF_OPT_CLR(&diffopts
, ALLOW_EXTERNAL
);
946 show_log_first
= !!rev
->loginfo
&& !rev
->no_commit_id
;
948 /* find set of paths that everybody touches */
949 for (i
= 0; i
< num_parent
; i
++) {
950 /* show stat against the first parent even
951 * when doing combined diff.
953 int stat_opt
= (opt
->output_format
&
954 (DIFF_FORMAT_NUMSTAT
|DIFF_FORMAT_DIFFSTAT
));
955 if (i
== 0 && stat_opt
)
956 diffopts
.output_format
= stat_opt
;
958 diffopts
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
959 diff_tree_sha1(parent
[i
], sha1
, "", &diffopts
);
960 diffcore_std(&diffopts
);
961 paths
= intersect_paths(paths
, i
, num_parent
);
963 if (show_log_first
&& i
== 0) {
965 if (rev
->verbose_header
&& opt
->output_format
)
966 putchar(opt
->line_termination
);
968 diff_flush(&diffopts
);
971 /* find out surviving paths */
972 for (num_paths
= 0, p
= paths
; p
; p
= p
->next
) {
977 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
979 DIFF_FORMAT_NAME_STATUS
)) {
980 for (p
= paths
; p
; p
= p
->next
) {
982 show_raw_diff(p
, num_parent
, rev
);
986 else if (opt
->output_format
&
987 (DIFF_FORMAT_NUMSTAT
|DIFF_FORMAT_DIFFSTAT
))
989 if (opt
->output_format
& DIFF_FORMAT_PATCH
) {
991 putchar(opt
->line_termination
);
992 for (p
= paths
; p
; p
= p
->next
) {
994 show_patch_diff(p
, num_parent
, dense
,
1000 /* Clean things up */
1002 struct combine_diff_path
*tmp
= paths
;
1003 paths
= paths
->next
;
1008 void diff_tree_combined_merge(const unsigned char *sha1
,
1009 int dense
, struct rev_info
*rev
)
1012 const unsigned char (*parent
)[20];
1013 struct commit
*commit
= lookup_commit(sha1
);
1014 struct commit_list
*parents
;
1017 for (parents
= commit
->parents
, num_parent
= 0;
1019 parents
= parents
->next
, num_parent
++)
1022 parent
= xmalloc(num_parent
* sizeof(*parent
));
1023 for (parents
= commit
->parents
, num_parent
= 0;
1025 parents
= parents
->next
, num_parent
++)
1026 hashcpy((unsigned char*)(parent
+ num_parent
),
1027 parents
->item
->object
.sha1
);
1028 diff_tree_combined(sha1
, parent
, num_parent
, dense
, rev
);