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.
87 * bit (N+1) is used for "do not show deletion before this".
93 static char *grab_blob(const unsigned char *sha1
, unsigned long *size
)
96 enum object_type type
;
97 if (is_null_sha1(sha1
)) {
100 return xcalloc(1, 1);
102 blob
= read_sha1_file(sha1
, &type
, size
);
103 if (type
!= OBJ_BLOB
)
104 die("object '%s' is not a blob!", sha1_to_hex(sha1
));
108 static void append_lost(struct sline
*sline
, int n
, const char *line
, int len
)
111 unsigned long this_mask
= (1UL<<n
);
112 if (line
[len
-1] == '\n')
115 /* Check to see if we can squash things */
116 if (sline
->lost_head
) {
117 struct lline
*last_one
= NULL
;
118 /* We cannot squash it with earlier one */
119 for (lline
= sline
->lost_head
;
122 if (lline
->parent_map
& this_mask
)
124 lline
= last_one
? last_one
->next
: sline
->lost_head
;
126 if (lline
->len
== len
&&
127 !memcmp(lline
->line
, line
, len
)) {
128 lline
->parent_map
|= this_mask
;
135 lline
= xmalloc(sizeof(*lline
) + len
+ 1);
138 lline
->parent_map
= this_mask
;
139 memcpy(lline
->line
, line
, len
);
140 lline
->line
[len
] = 0;
141 *sline
->lost_tail
= lline
;
142 sline
->lost_tail
= &lline
->next
;
145 struct combine_diff_state
{
152 struct sline
*lost_bucket
;
155 static void consume_line(void *state_
, char *line
, unsigned long len
)
157 struct combine_diff_state
*state
= state_
;
158 if (5 < len
&& !memcmp("@@ -", line
, 4)) {
159 if (parse_hunk_header(line
, len
,
160 &state
->ob
, &state
->on
,
161 &state
->nb
, &state
->nn
))
163 state
->lno
= state
->nb
;
165 /* @@ -1,2 +0,0 @@ to remove the
170 /* @@ -X,Y +N,0 @@ removed Y lines
171 * that would have come *after* line N
172 * in the result. Our lost buckets hang
173 * to the line after the removed lines,
175 state
->lost_bucket
= &state
->sline
[state
->nb
];
177 state
->lost_bucket
= &state
->sline
[state
->nb
-1];
178 if (!state
->sline
[state
->nb
-1].p_lno
)
179 state
->sline
[state
->nb
-1].p_lno
=
180 xcalloc(state
->num_parent
,
181 sizeof(unsigned long));
182 state
->sline
[state
->nb
-1].p_lno
[state
->n
] = state
->ob
;
185 if (!state
->lost_bucket
)
186 return; /* not in any hunk yet */
189 append_lost(state
->lost_bucket
, state
->n
, line
+1, len
-1);
192 state
->sline
[state
->lno
-1].flag
|= state
->nmask
;
198 static void combine_diff(const unsigned char *parent
, mmfile_t
*result_file
,
199 struct sline
*sline
, unsigned int cnt
, int n
,
202 unsigned int p_lno
, lno
;
203 unsigned long nmask
= (1UL << n
);
206 mmfile_t parent_file
;
208 struct combine_diff_state state
;
212 return; /* result deleted */
214 parent_file
.ptr
= grab_blob(parent
, &sz
);
215 parent_file
.size
= sz
;
216 memset(&xpp
, 0, sizeof(xpp
));
217 xpp
.flags
= XDF_NEED_MINIMAL
;
218 memset(&xecfg
, 0, sizeof(xecfg
));
219 memset(&state
, 0, sizeof(state
));
223 state
.num_parent
= num_parent
;
226 xdi_diff_outf(&parent_file
, result_file
, consume_line
, &state
,
228 free(parent_file
.ptr
);
230 /* Assign line numbers for this parent.
232 * sline[lno].p_lno[n] records the first line number
233 * (counting from 1) for parent N if the final hunk display
234 * started by showing sline[lno] (possibly showing the lost
235 * lines attached to it first).
237 for (lno
= 0, p_lno
= 1; lno
<= cnt
; lno
++) {
239 sline
[lno
].p_lno
[n
] = p_lno
;
241 /* How many lines would this sline advance the p_lno? */
242 ll
= sline
[lno
].lost_head
;
244 if (ll
->parent_map
& nmask
)
245 p_lno
++; /* '-' means parent had it */
248 if (lno
< cnt
&& !(sline
[lno
].flag
& nmask
))
249 p_lno
++; /* no '+' means parent had it */
251 sline
[lno
].p_lno
[n
] = p_lno
; /* trailer */
254 static unsigned long context
= 3;
255 static char combine_marker
= '@';
257 static int interesting(struct sline
*sline
, unsigned long all_mask
)
259 /* If some parents lost lines here, or if we have added to
260 * some parent, it is interesting.
262 return ((sline
->flag
& all_mask
) || sline
->lost_head
);
265 static unsigned long adjust_hunk_tail(struct sline
*sline
,
266 unsigned long all_mask
,
267 unsigned long hunk_begin
,
270 /* i points at the first uninteresting line. If the last line
271 * of the hunk was interesting only because it has some
272 * deletion, then it is not all that interesting for the
273 * purpose of giving trailing context lines. This is because
274 * we output '-' line and then unmodified sline[i-1] itself in
275 * that case which gives us one extra context line.
277 if ((hunk_begin
+ 1 <= i
) && !(sline
[i
-1].flag
& all_mask
))
282 static unsigned long find_next(struct sline
*sline
,
286 int look_for_uninteresting
)
288 /* We have examined up to i-1 and are about to look at i.
289 * Find next interesting or uninteresting line. Here,
290 * "interesting" does not mean interesting(), but marked by
291 * the give_context() function below (i.e. it includes context
292 * lines that are not interesting to interesting() function
293 * that are surrounded by interesting() ones.
296 if (look_for_uninteresting
297 ? !(sline
[i
].flag
& mark
)
298 : (sline
[i
].flag
& mark
))
305 static int give_context(struct sline
*sline
, unsigned long cnt
, int num_parent
)
307 unsigned long all_mask
= (1UL<<num_parent
) - 1;
308 unsigned long mark
= (1UL<<num_parent
);
309 unsigned long no_pre_delete
= (2UL<<num_parent
);
312 /* Two groups of interesting lines may have a short gap of
313 * uninteresting lines. Connect such groups to give them a
316 * We first start from what the interesting() function says,
317 * and mark them with "mark", and paint context lines with the
318 * mark. So interesting() would still say false for such context
319 * lines but they are treated as "interesting" in the end.
321 i
= find_next(sline
, mark
, 0, cnt
, 0);
326 unsigned long j
= (context
< i
) ? (i
- context
) : 0;
329 /* Paint a few lines before the first interesting line. */
331 sline
[j
++].flag
|= mark
| no_pre_delete
;
334 /* we know up to i is to be included. where does the
335 * next uninteresting one start?
337 j
= find_next(sline
, mark
, i
, cnt
, 1);
339 break; /* the rest are all interesting */
341 /* lookahead context lines */
342 k
= find_next(sline
, mark
, j
, cnt
, 0);
343 j
= adjust_hunk_tail(sline
, all_mask
, i
, j
);
345 if (k
< j
+ context
) {
346 /* k is interesting and [j,k) are not, but
347 * paint them interesting because the gap is small.
350 sline
[j
++].flag
|= mark
;
355 /* j is the first uninteresting line and there is
356 * no overlap beyond it within context lines. Paint
357 * the trailing edge a bit.
360 k
= (j
+ context
< cnt
+1) ? j
+ context
: cnt
+1;
362 sline
[j
++].flag
|= mark
;
367 static int make_hunks(struct sline
*sline
, unsigned long cnt
,
368 int num_parent
, int dense
)
370 unsigned long all_mask
= (1UL<<num_parent
) - 1;
371 unsigned long mark
= (1UL<<num_parent
);
373 int has_interesting
= 0;
375 for (i
= 0; i
<= cnt
; i
++) {
376 if (interesting(&sline
[i
], all_mask
))
377 sline
[i
].flag
|= mark
;
379 sline
[i
].flag
&= ~mark
;
382 return give_context(sline
, cnt
, num_parent
);
384 /* Look at each hunk, and if we have changes from only one
385 * parent, or the changes are the same from all but one
386 * parent, mark that uninteresting.
390 unsigned long j
, hunk_begin
, hunk_end
;
391 unsigned long same_diff
;
392 while (i
<= cnt
&& !(sline
[i
].flag
& mark
))
395 break; /* No more interesting hunks */
397 for (j
= i
+ 1; j
<= cnt
; j
++) {
398 if (!(sline
[j
].flag
& mark
)) {
399 /* Look beyond the end to see if there
400 * is an interesting line after this
401 * hunk within context span.
403 unsigned long la
; /* lookahead */
405 la
= adjust_hunk_tail(sline
, all_mask
,
407 la
= (la
+ context
< cnt
+ 1) ?
408 (la
+ context
) : cnt
+ 1;
410 if (sline
[la
].flag
& mark
) {
422 /* [i..hunk_end) are interesting. Now is it really
423 * interesting? We check if there are only two versions
424 * and the result matches one of them. That is, we look
426 * (+) line, which records lines added to which parents;
427 * this line appears in the result.
428 * (-) line, which records from what parents the line
429 * was removed; this line does not appear in the result.
430 * then check the set of parents the result has difference
431 * from, from all lines. If there are lines that has
432 * different set of parents that the result has differences
433 * from, that means we have more than two versions.
435 * Even when we have only two versions, if the result does
436 * not match any of the parents, the it should be considered
437 * interesting. In such a case, we would have all '+' line.
438 * After passing the above "two versions" test, that would
439 * appear as "the same set of parents" to be "all parents".
443 for (j
= i
; j
< hunk_end
&& !has_interesting
; j
++) {
444 unsigned long this_diff
= sline
[j
].flag
& all_mask
;
445 struct lline
*ll
= sline
[j
].lost_head
;
447 /* This has some changes. Is it the
451 same_diff
= this_diff
;
452 else if (same_diff
!= this_diff
) {
457 while (ll
&& !has_interesting
) {
458 /* Lost this line from these parents;
459 * who are they? Are they the same?
461 this_diff
= ll
->parent_map
;
463 same_diff
= this_diff
;
464 else if (same_diff
!= this_diff
) {
471 if (!has_interesting
&& same_diff
!= all_mask
) {
472 /* This hunk is not that interesting after all */
473 for (j
= hunk_begin
; j
< hunk_end
; j
++)
474 sline
[j
].flag
&= ~mark
;
479 has_interesting
= give_context(sline
, cnt
, num_parent
);
480 return has_interesting
;
483 static void show_parent_lno(struct sline
*sline
, unsigned long l0
, unsigned long l1
, int n
, unsigned long null_context
)
485 l0
= sline
[l0
].p_lno
[n
];
486 l1
= sline
[l1
].p_lno
[n
];
487 printf(" -%lu,%lu", l0
, l1
-l0
-null_context
);
490 static int hunk_comment_line(const char *bol
)
497 return (isalpha(ch
) || ch
== '_' || ch
== '$');
500 static void show_line_to_eol(const char *line
, int len
, const char *reset
)
502 int saw_cr_at_eol
= 0;
505 saw_cr_at_eol
= (len
&& line
[len
-1] == '\r');
507 printf("%.*s%s%s\n", len
- saw_cr_at_eol
, line
,
509 saw_cr_at_eol
? "\r" : "");
512 static void dump_sline(struct sline
*sline
, unsigned long cnt
, int num_parent
,
515 unsigned long mark
= (1UL<<num_parent
);
516 unsigned long no_pre_delete
= (2UL<<num_parent
);
518 unsigned long lno
= 0;
519 const char *c_frag
= diff_get_color(use_color
, DIFF_FRAGINFO
);
520 const char *c_new
= diff_get_color(use_color
, DIFF_FILE_NEW
);
521 const char *c_old
= diff_get_color(use_color
, DIFF_FILE_OLD
);
522 const char *c_plain
= diff_get_color(use_color
, DIFF_PLAIN
);
523 const char *c_reset
= diff_get_color(use_color
, DIFF_RESET
);
526 return; /* result deleted */
529 struct sline
*sl
= &sline
[lno
];
530 unsigned long hunk_end
;
531 unsigned long rlines
;
532 const char *hunk_comment
= NULL
;
533 unsigned long null_context
= 0;
535 while (lno
<= cnt
&& !(sline
[lno
].flag
& mark
)) {
536 if (hunk_comment_line(sline
[lno
].bol
))
537 hunk_comment
= sline
[lno
].bol
;
543 for (hunk_end
= lno
+ 1; hunk_end
<= cnt
; hunk_end
++)
544 if (!(sline
[hunk_end
].flag
& mark
))
547 rlines
= hunk_end
- lno
;
549 rlines
--; /* pointing at the last delete hunk */
553 * Even when running with --unified=0, all
554 * lines in the hunk needs to be processed in
555 * the loop below in order to show the
556 * deletion recorded in lost_head. However,
557 * we do not want to show the resulting line
558 * with all blank context markers in such a
562 for (j
= lno
; j
< hunk_end
; j
++)
563 if (!(sline
[j
].flag
& (mark
-1)))
565 rlines
-= null_context
;
568 fputs(c_frag
, stdout
);
569 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
570 for (i
= 0; i
< num_parent
; i
++)
571 show_parent_lno(sline
, lno
, hunk_end
, i
, null_context
);
572 printf(" +%lu,%lu ", lno
+1, rlines
);
573 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
577 for (i
= 0; i
< 40; i
++) {
578 int ch
= hunk_comment
[i
] & 0xff;
579 if (!ch
|| ch
== '\n')
586 for (i
= 0; i
< comment_end
; i
++)
587 putchar(hunk_comment
[i
]);
590 printf("%s\n", c_reset
);
591 while (lno
< hunk_end
) {
594 unsigned long p_mask
;
596 ll
= (sl
->flag
& no_pre_delete
) ? NULL
: sl
->lost_head
;
598 fputs(c_old
, stdout
);
599 for (j
= 0; j
< num_parent
; j
++) {
600 if (ll
->parent_map
& (1UL<<j
))
605 show_line_to_eol(ll
->line
, -1, c_reset
);
611 if (!(sl
->flag
& (mark
-1))) {
613 * This sline was here to hang the
614 * lost lines in front of it.
618 fputs(c_plain
, stdout
);
621 fputs(c_new
, stdout
);
622 for (j
= 0; j
< num_parent
; j
++) {
623 if (p_mask
& sl
->flag
)
629 show_line_to_eol(sl
->bol
, sl
->len
, c_reset
);
634 static void reuse_combine_diff(struct sline
*sline
, unsigned long cnt
,
637 /* We have already examined parent j and we know parent i
638 * and parent j are the same, so reuse the combined result
639 * of parent j for parent i.
641 unsigned long lno
, imask
, jmask
;
645 for (lno
= 0; lno
<= cnt
; lno
++) {
646 struct lline
*ll
= sline
->lost_head
;
647 sline
->p_lno
[i
] = sline
->p_lno
[j
];
649 if (ll
->parent_map
& jmask
)
650 ll
->parent_map
|= imask
;
653 if (sline
->flag
& jmask
)
654 sline
->flag
|= imask
;
657 /* the overall size of the file (sline[cnt]) */
658 sline
->p_lno
[i
] = sline
->p_lno
[j
];
661 static void dump_quoted_path(const char *head
,
664 const char *c_meta
, const char *c_reset
)
666 static struct strbuf buf
= STRBUF_INIT
;
669 strbuf_addstr(&buf
, c_meta
);
670 strbuf_addstr(&buf
, head
);
671 quote_two_c_style(&buf
, prefix
, path
, 0);
672 strbuf_addstr(&buf
, c_reset
);
676 static void show_patch_diff(struct combine_diff_path
*elem
, int num_parent
,
677 int dense
, struct rev_info
*rev
)
679 struct diff_options
*opt
= &rev
->diffopt
;
680 unsigned long result_size
, cnt
, lno
;
682 struct sline
*sline
; /* survived lines */
683 int mode_differs
= 0;
685 int working_tree_file
= is_null_sha1(elem
->sha1
);
686 int abbrev
= DIFF_OPT_TST(opt
, FULL_INDEX
) ? 40 : DEFAULT_ABBREV
;
687 const char *a_prefix
, *b_prefix
;
688 mmfile_t result_file
;
690 context
= opt
->context
;
691 a_prefix
= opt
->a_prefix
? opt
->a_prefix
: "a/";
692 b_prefix
= opt
->b_prefix
? opt
->b_prefix
: "b/";
694 /* Read the result of merge first */
695 if (!working_tree_file
)
696 result
= grab_blob(elem
->sha1
, &result_size
);
698 /* Used by diff-tree to read from the working tree */
702 if (lstat(elem
->path
, &st
) < 0)
705 if (S_ISLNK(st
.st_mode
)) {
706 struct strbuf buf
= STRBUF_INIT
;
708 if (strbuf_readlink(&buf
, elem
->path
, st
.st_size
) < 0) {
709 error("readlink(%s): %s", elem
->path
,
713 result_size
= buf
.len
;
714 result
= strbuf_detach(&buf
, NULL
);
715 elem
->mode
= canon_mode(st
.st_mode
);
717 else if (0 <= (fd
= open(elem
->path
, O_RDONLY
)) &&
719 size_t len
= xsize_t(st
.st_size
);
723 elem
->mode
= canon_mode(st
.st_mode
);
724 /* if symlinks don't work, assume symlink if all parents
727 is_file
= has_symlinks
;
728 for (i
= 0; !is_file
&& i
< num_parent
; i
++)
729 is_file
= !S_ISLNK(elem
->parent
[i
].mode
);
731 elem
->mode
= canon_mode(S_IFLNK
);
734 result
= xmalloc(len
+ 1);
736 done
= read_in_full(fd
, result
, len
);
738 die("read error '%s'", elem
->path
);
740 die("early EOF '%s'", elem
->path
);
744 /* If not a fake symlink, apply filters, e.g. autocrlf */
746 struct strbuf buf
= STRBUF_INIT
;
748 if (convert_to_git(elem
->path
, result
, len
, &buf
, safe_crlf
)) {
750 result
= strbuf_detach(&buf
, &len
);
759 result
= xcalloc(1, 1);
766 for (cnt
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
770 if (result_size
&& result
[result_size
-1] != '\n')
771 cnt
++; /* incomplete line */
773 sline
= xcalloc(cnt
+2, sizeof(*sline
));
774 sline
[0].bol
= result
;
775 for (lno
= 0; lno
<= cnt
+ 1; lno
++) {
776 sline
[lno
].lost_tail
= &sline
[lno
].lost_head
;
779 for (lno
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
781 sline
[lno
].len
= cp
- sline
[lno
].bol
;
784 sline
[lno
].bol
= cp
+ 1;
787 if (result_size
&& result
[result_size
-1] != '\n')
788 sline
[cnt
-1].len
= result_size
- (sline
[cnt
-1].bol
- result
);
790 result_file
.ptr
= result
;
791 result_file
.size
= result_size
;
793 /* Even p_lno[cnt+1] is valid -- that is for the end line number
794 * for deletion hunk at the end.
796 sline
[0].p_lno
= xcalloc((cnt
+2) * num_parent
, sizeof(unsigned long));
797 for (lno
= 0; lno
<= cnt
; lno
++)
798 sline
[lno
+1].p_lno
= sline
[lno
].p_lno
+ num_parent
;
800 for (i
= 0; i
< num_parent
; i
++) {
802 for (j
= 0; j
< i
; j
++) {
803 if (!hashcmp(elem
->parent
[i
].sha1
,
804 elem
->parent
[j
].sha1
)) {
805 reuse_combine_diff(sline
, cnt
, i
, j
);
810 combine_diff(elem
->parent
[i
].sha1
, &result_file
, sline
,
812 if (elem
->parent
[i
].mode
!= elem
->mode
)
816 show_hunks
= make_hunks(sline
, cnt
, num_parent
, dense
);
818 if (show_hunks
|| mode_differs
|| working_tree_file
) {
820 int use_color
= DIFF_OPT_TST(opt
, COLOR_DIFF
);
821 const char *c_meta
= diff_get_color(use_color
, DIFF_METAINFO
);
822 const char *c_reset
= diff_get_color(use_color
, DIFF_RESET
);
826 if (rev
->loginfo
&& !rev
->no_commit_id
)
828 dump_quoted_path(dense
? "diff --cc " : "diff --combined ",
829 "", elem
->path
, c_meta
, c_reset
);
830 printf("%sindex ", c_meta
);
831 for (i
= 0; i
< num_parent
; i
++) {
832 abb
= find_unique_abbrev(elem
->parent
[i
].sha1
,
834 printf("%s%s", i
? "," : "", abb
);
836 abb
= find_unique_abbrev(elem
->sha1
, abbrev
);
837 printf("..%s%s\n", abb
, c_reset
);
840 deleted
= !elem
->mode
;
842 /* We say it was added if nobody had it */
844 for (i
= 0; added
&& i
< num_parent
; i
++)
845 if (elem
->parent
[i
].status
!=
849 printf("%snew file mode %06o",
853 printf("%sdeleted file ", c_meta
);
855 for (i
= 0; i
< num_parent
; i
++) {
856 printf("%s%06o", i
? "," : "",
857 elem
->parent
[i
].mode
);
860 printf("..%06o", elem
->mode
);
862 printf("%s\n", c_reset
);
865 dump_quoted_path("--- ", "", "/dev/null",
868 dump_quoted_path("--- ", a_prefix
, elem
->path
,
871 dump_quoted_path("+++ ", "", "/dev/null",
874 dump_quoted_path("+++ ", b_prefix
, elem
->path
,
876 dump_sline(sline
, cnt
, num_parent
,
877 DIFF_OPT_TST(opt
, COLOR_DIFF
));
881 for (lno
= 0; lno
< cnt
; lno
++) {
882 if (sline
[lno
].lost_head
) {
883 struct lline
*ll
= sline
[lno
].lost_head
;
885 struct lline
*tmp
= ll
;
891 free(sline
[0].p_lno
);
895 #define COLONS "::::::::::::::::::::::::::::::::"
897 static void show_raw_diff(struct combine_diff_path
*p
, int num_parent
, struct rev_info
*rev
)
899 struct diff_options
*opt
= &rev
->diffopt
;
902 int line_termination
, inter_name_termination
;
904 line_termination
= opt
->line_termination
;
905 inter_name_termination
= '\t';
906 if (!line_termination
)
907 inter_name_termination
= 0;
909 if (rev
->loginfo
&& !rev
->no_commit_id
)
912 if (opt
->output_format
& DIFF_FORMAT_RAW
) {
913 offset
= strlen(COLONS
) - num_parent
;
916 prefix
= COLONS
+ offset
;
919 for (i
= 0; i
< num_parent
; i
++) {
920 printf("%s%06o", prefix
, p
->parent
[i
].mode
);
923 printf("%s%06o", prefix
, p
->mode
);
926 for (i
= 0; i
< num_parent
; i
++)
927 printf(" %s", diff_unique_abbrev(p
->parent
[i
].sha1
,
929 printf(" %s ", diff_unique_abbrev(p
->sha1
, opt
->abbrev
));
932 if (opt
->output_format
& (DIFF_FORMAT_RAW
| DIFF_FORMAT_NAME_STATUS
)) {
933 for (i
= 0; i
< num_parent
; i
++)
934 putchar(p
->parent
[i
].status
);
935 putchar(inter_name_termination
);
938 write_name_quoted(p
->path
, stdout
, line_termination
);
941 void show_combined_diff(struct combine_diff_path
*p
,
944 struct rev_info
*rev
)
946 struct diff_options
*opt
= &rev
->diffopt
;
949 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
951 DIFF_FORMAT_NAME_STATUS
))
952 show_raw_diff(p
, num_parent
, rev
);
953 else if (opt
->output_format
& DIFF_FORMAT_PATCH
)
954 show_patch_diff(p
, num_parent
, dense
, rev
);
957 void diff_tree_combined(const unsigned char *sha1
,
958 const unsigned char parent
[][20],
961 struct rev_info
*rev
)
963 struct diff_options
*opt
= &rev
->diffopt
;
964 struct diff_options diffopts
;
965 struct combine_diff_path
*p
, *paths
= NULL
;
966 int i
, num_paths
, needsep
, show_log_first
;
969 diffopts
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
970 DIFF_OPT_SET(&diffopts
, RECURSIVE
);
971 DIFF_OPT_CLR(&diffopts
, ALLOW_EXTERNAL
);
973 show_log_first
= !!rev
->loginfo
&& !rev
->no_commit_id
;
975 /* find set of paths that everybody touches */
976 for (i
= 0; i
< num_parent
; i
++) {
977 /* show stat against the first parent even
978 * when doing combined diff.
980 int stat_opt
= (opt
->output_format
&
981 (DIFF_FORMAT_NUMSTAT
|DIFF_FORMAT_DIFFSTAT
));
982 if (i
== 0 && stat_opt
)
983 diffopts
.output_format
= stat_opt
;
985 diffopts
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
986 diff_tree_sha1(parent
[i
], sha1
, "", &diffopts
);
987 diffcore_std(&diffopts
);
988 paths
= intersect_paths(paths
, i
, num_parent
);
990 if (show_log_first
&& i
== 0) {
992 if (rev
->verbose_header
&& opt
->output_format
)
993 putchar(opt
->line_termination
);
995 diff_flush(&diffopts
);
998 /* find out surviving paths */
999 for (num_paths
= 0, p
= paths
; p
; p
= p
->next
) {
1004 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
1006 DIFF_FORMAT_NAME_STATUS
)) {
1007 for (p
= paths
; p
; p
= p
->next
) {
1009 show_raw_diff(p
, num_parent
, rev
);
1013 else if (opt
->output_format
&
1014 (DIFF_FORMAT_NUMSTAT
|DIFF_FORMAT_DIFFSTAT
))
1016 if (opt
->output_format
& DIFF_FORMAT_PATCH
) {
1018 putchar(opt
->line_termination
);
1019 for (p
= paths
; p
; p
= p
->next
) {
1021 show_patch_diff(p
, num_parent
, dense
,
1027 /* Clean things up */
1029 struct combine_diff_path
*tmp
= paths
;
1030 paths
= paths
->next
;
1035 void diff_tree_combined_merge(const unsigned char *sha1
,
1036 int dense
, struct rev_info
*rev
)
1039 const unsigned char (*parent
)[20];
1040 struct commit
*commit
= lookup_commit(sha1
);
1041 struct commit_list
*parents
;
1044 for (parents
= commit
->parents
, num_parent
= 0;
1046 parents
= parents
->next
, num_parent
++)
1049 parent
= xmalloc(num_parent
* sizeof(*parent
));
1050 for (parents
= commit
->parents
, num_parent
= 0;
1052 parents
= parents
->next
, num_parent
++)
1053 hashcpy((unsigned char*)(parent
+ num_parent
),
1054 parents
->item
->object
.sha1
);
1055 diff_tree_combined(sha1
, parent
, num_parent
, dense
, rev
);