1 #define USE_THE_REPOSITORY_VARIABLE
2 #define DISABLE_SIGN_COMPARE_WARNINGS
4 #include "git-compat-util.h"
5 #include "object-store-ll.h"
10 #include "environment.h"
12 #include "object-name.h"
14 #include "xdiff-interface.h"
15 #include "xdiff/xmacros.h"
20 #include "oid-array.h"
23 static int compare_paths(const struct combine_diff_path
*one
,
24 const struct diff_filespec
*two
)
26 if (!S_ISDIR(one
->mode
) && !S_ISDIR(two
->mode
))
27 return strcmp(one
->path
, two
->path
);
29 return base_name_compare(one
->path
, strlen(one
->path
), one
->mode
,
30 two
->path
, strlen(two
->path
), two
->mode
);
33 static int filename_changed(char status
)
35 return status
== 'R' || status
== 'C';
38 static struct combine_diff_path
*intersect_paths(
39 struct combine_diff_path
*curr
,
42 int combined_all_paths
)
44 struct diff_queue_struct
*q
= &diff_queued_diff
;
45 struct combine_diff_path
*p
, **tail
= &curr
;
49 for (i
= 0; i
< q
->nr
; i
++) {
52 if (diff_unmodified_pair(q
->queue
[i
]))
54 path
= q
->queue
[i
]->two
->path
;
56 p
= xmalloc(combine_diff_path_size(num_parent
, len
));
57 p
->path
= (char *) &(p
->parent
[num_parent
]);
58 memcpy(p
->path
, path
, len
);
62 sizeof(p
->parent
[0]) * num_parent
);
64 oidcpy(&p
->oid
, &q
->queue
[i
]->two
->oid
);
65 p
->mode
= q
->queue
[i
]->two
->mode
;
66 oidcpy(&p
->parent
[n
].oid
, &q
->queue
[i
]->one
->oid
);
67 p
->parent
[n
].mode
= q
->queue
[i
]->one
->mode
;
68 p
->parent
[n
].status
= q
->queue
[i
]->status
;
70 if (combined_all_paths
&&
71 filename_changed(p
->parent
[n
].status
)) {
72 strbuf_init(&p
->parent
[n
].path
, 0);
73 strbuf_addstr(&p
->parent
[n
].path
,
74 q
->queue
[i
]->one
->path
);
83 * paths in curr (linked list) and q->queue[] (array) are
84 * both sorted in the tree order.
87 while ((p
= *tail
) != NULL
) {
89 ? -1 : compare_paths(p
, q
->queue
[i
]->two
));
92 /* p->path not in q->queue[]; drop it */
94 for (j
= 0; j
< num_parent
; j
++)
95 if (combined_all_paths
&&
96 filename_changed(p
->parent
[j
].status
))
97 strbuf_release(&p
->parent
[j
].path
);
103 /* q->queue[i] not in p->path; skip it */
108 oidcpy(&p
->parent
[n
].oid
, &q
->queue
[i
]->one
->oid
);
109 p
->parent
[n
].mode
= q
->queue
[i
]->one
->mode
;
110 p
->parent
[n
].status
= q
->queue
[i
]->status
;
111 if (combined_all_paths
&&
112 filename_changed(p
->parent
[n
].status
))
113 strbuf_addstr(&p
->parent
[n
].path
,
114 q
->queue
[i
]->one
->path
);
122 /* Lines lost from parent */
124 struct lline
*next
, *prev
;
126 unsigned long parent_map
;
127 char line
[FLEX_ARRAY
];
130 /* Lines lost from current parent (before coalescing) */
132 struct lline
*lost_head
, *lost_tail
;
136 /* Lines surviving in the merge result */
138 /* Accumulated and coalesced lost lines */
144 /* bit 0 up to (N-1) are on if the parent has this line (i.e.
145 * we did not change it).
146 * bit N is used for "interesting" lines, including context.
147 * bit (N+1) is used for "do not show deletion before this".
150 unsigned long *p_lno
;
153 static int match_string_spaces(const char *line1
, int len1
,
154 const char *line2
, int len2
,
157 if (flags
& XDF_WHITESPACE_FLAGS
) {
158 for (; len1
> 0 && XDL_ISSPACE(line1
[len1
- 1]); len1
--);
159 for (; len2
> 0 && XDL_ISSPACE(line2
[len2
- 1]); len2
--);
162 if (!(flags
& (XDF_IGNORE_WHITESPACE
| XDF_IGNORE_WHITESPACE_CHANGE
)))
163 return (len1
== len2
&& !memcmp(line1
, line2
, len1
));
165 while (len1
> 0 && len2
> 0) {
168 if (XDL_ISSPACE(line1
[len1
]) || XDL_ISSPACE(line2
[len2
])) {
169 if ((flags
& XDF_IGNORE_WHITESPACE_CHANGE
) &&
170 (!XDL_ISSPACE(line1
[len1
]) || !XDL_ISSPACE(line2
[len2
])))
173 for (; len1
> 0 && XDL_ISSPACE(line1
[len1
]); len1
--);
174 for (; len2
> 0 && XDL_ISSPACE(line2
[len2
]); len2
--);
176 if (line1
[len1
] != line2
[len2
])
180 if (flags
& XDF_IGNORE_WHITESPACE
) {
181 /* Consume remaining spaces */
182 for (; len1
> 0 && XDL_ISSPACE(line1
[len1
- 1]); len1
--);
183 for (; len2
> 0 && XDL_ISSPACE(line2
[len2
- 1]); len2
--);
186 /* We matched full line1 and line2 */
193 enum coalesce_direction
{ MATCH
, BASE
, NEW
};
195 /* Coalesce new lines into base by finding LCS */
196 static struct lline
*coalesce_lines(struct lline
*base
, int *lenbase
,
197 struct lline
*newline
, int lennew
,
198 unsigned long parent
, long flags
)
201 enum coalesce_direction
**directions
;
202 struct lline
*baseend
, *newend
= NULL
;
203 int i
, j
, origbaselen
= *lenbase
;
214 * Coalesce new lines into base by finding the LCS
215 * - Create the table to run dynamic programming
217 * - Then reverse read the direction structure:
218 * - If we have MATCH, assign parent to base flag, and consume
219 * both baseend and newend
220 * - Else if we have BASE, consume baseend
221 * - Else if we have NEW, insert newend lline into base and
224 CALLOC_ARRAY(lcs
, st_add(origbaselen
, 1));
225 CALLOC_ARRAY(directions
, st_add(origbaselen
, 1));
226 for (i
= 0; i
< origbaselen
+ 1; i
++) {
227 CALLOC_ARRAY(lcs
[i
], st_add(lennew
, 1));
228 CALLOC_ARRAY(directions
[i
], st_add(lennew
, 1));
229 directions
[i
][0] = BASE
;
231 for (j
= 1; j
< lennew
+ 1; j
++)
232 directions
[0][j
] = NEW
;
234 for (i
= 1, baseend
= base
; i
< origbaselen
+ 1; i
++) {
235 for (j
= 1, newend
= newline
; j
< lennew
+ 1; j
++) {
236 if (match_string_spaces(baseend
->line
, baseend
->len
,
237 newend
->line
, newend
->len
, flags
)) {
238 lcs
[i
][j
] = lcs
[i
- 1][j
- 1] + 1;
239 directions
[i
][j
] = MATCH
;
240 } else if (lcs
[i
][j
- 1] >= lcs
[i
- 1][j
]) {
241 lcs
[i
][j
] = lcs
[i
][j
- 1];
242 directions
[i
][j
] = NEW
;
244 lcs
[i
][j
] = lcs
[i
- 1][j
];
245 directions
[i
][j
] = BASE
;
248 newend
= newend
->next
;
251 baseend
= baseend
->next
;
254 for (i
= 0; i
< origbaselen
+ 1; i
++)
258 /* At this point, baseend and newend point to the end of each lists */
261 while (i
!= 0 || j
!= 0) {
262 if (directions
[i
][j
] == MATCH
) {
263 baseend
->parent_map
|= 1<<parent
;
264 baseend
= baseend
->prev
;
265 newend
= newend
->prev
;
268 } else if (directions
[i
][j
] == NEW
) {
272 /* Remove lline from new list and update newend */
274 lline
->prev
->next
= lline
->next
;
276 newline
= lline
->next
;
278 lline
->next
->prev
= lline
->prev
;
280 newend
= lline
->prev
;
283 /* Add lline to base list */
285 lline
->next
= baseend
->next
;
286 lline
->prev
= baseend
;
288 lline
->prev
->next
= lline
;
297 lline
->next
->prev
= lline
;
300 baseend
= baseend
->prev
;
307 struct lline
*lline
= newend
;
308 newend
= newend
->next
;
312 for (i
= 0; i
< origbaselen
+ 1; i
++)
319 static char *grab_blob(struct repository
*r
,
320 const struct object_id
*oid
, unsigned int mode
,
321 unsigned long *size
, struct userdiff_driver
*textconv
,
325 enum object_type type
;
327 if (S_ISGITLINK(mode
)) {
328 struct strbuf buf
= STRBUF_INIT
;
329 strbuf_addf(&buf
, "Subproject commit %s\n", oid_to_hex(oid
));
331 blob
= strbuf_detach(&buf
, NULL
);
332 } else if (is_null_oid(oid
)) {
335 return xcalloc(1, 1);
336 } else if (textconv
) {
337 struct diff_filespec
*df
= alloc_filespec(path
);
338 fill_filespec(df
, oid
, 1, mode
);
339 *size
= fill_textconv(r
, textconv
, df
, &blob
);
342 blob
= repo_read_object_file(r
, oid
, &type
, size
);
344 die(_("unable to read %s"), oid_to_hex(oid
));
345 if (type
!= OBJ_BLOB
)
346 die("object '%s' is not a blob!", oid_to_hex(oid
));
351 static void append_lost(struct sline
*sline
, int n
, const char *line
, int len
)
354 unsigned long this_mask
= (1UL<<n
);
355 if (line
[len
-1] == '\n')
358 FLEX_ALLOC_MEM(lline
, line
, line
, len
);
361 lline
->prev
= sline
->plost
.lost_tail
;
363 lline
->prev
->next
= lline
;
365 sline
->plost
.lost_head
= lline
;
366 sline
->plost
.lost_tail
= lline
;
368 lline
->parent_map
= this_mask
;
371 struct combine_diff_state
{
378 struct sline
*lost_bucket
;
381 static void consume_hunk(void *state_
,
384 const char *func UNUSED
, long funclen UNUSED
)
386 struct combine_diff_state
*state
= state_
;
392 state
->lno
= state
->nb
;
393 if (state
->nn
== 0) {
394 /* @@ -X,Y +N,0 @@ removed Y lines
395 * that would have come *after* line N
396 * in the result. Our lost buckets hang
397 * to the line after the removed lines,
399 * Note that this is correct even when N == 0,
400 * in which case the hunk removes the first
403 state
->lost_bucket
= &state
->sline
[state
->nb
];
407 state
->lost_bucket
= &state
->sline
[state
->nb
-1];
409 if (!state
->sline
[state
->nb
-1].p_lno
)
410 CALLOC_ARRAY(state
->sline
[state
->nb
- 1].p_lno
,
412 state
->sline
[state
->nb
-1].p_lno
[state
->n
] = state
->ob
;
415 static int consume_line(void *state_
, char *line
, unsigned long len
)
417 struct combine_diff_state
*state
= state_
;
418 if (!state
->lost_bucket
)
419 return 0; /* not in any hunk yet */
422 append_lost(state
->lost_bucket
, state
->n
, line
+1, len
-1);
425 state
->sline
[state
->lno
-1].flag
|= state
->nmask
;
432 static void combine_diff(struct repository
*r
,
433 const struct object_id
*parent
, unsigned int mode
,
434 mmfile_t
*result_file
,
435 struct sline
*sline
, unsigned int cnt
, int n
,
436 int num_parent
, int result_deleted
,
437 struct userdiff_driver
*textconv
,
438 const char *path
, long flags
)
440 unsigned int p_lno
, lno
;
441 unsigned long nmask
= (1UL << n
);
444 mmfile_t parent_file
;
445 struct combine_diff_state state
;
449 return; /* result deleted */
451 parent_file
.ptr
= grab_blob(r
, parent
, mode
, &sz
, textconv
, path
);
452 parent_file
.size
= sz
;
453 memset(&xpp
, 0, sizeof(xpp
));
455 memset(&xecfg
, 0, sizeof(xecfg
));
456 memset(&state
, 0, sizeof(state
));
460 state
.num_parent
= num_parent
;
463 if (xdi_diff_outf(&parent_file
, result_file
, consume_hunk
,
464 consume_line
, &state
, &xpp
, &xecfg
))
465 die("unable to generate combined diff for %s",
467 free(parent_file
.ptr
);
469 /* Assign line numbers for this parent.
471 * sline[lno].p_lno[n] records the first line number
472 * (counting from 1) for parent N if the final hunk display
473 * started by showing sline[lno] (possibly showing the lost
474 * lines attached to it first).
476 for (lno
= 0, p_lno
= 1; lno
<= cnt
; lno
++) {
478 sline
[lno
].p_lno
[n
] = p_lno
;
480 /* Coalesce new lines */
481 if (sline
[lno
].plost
.lost_head
) {
482 struct sline
*sl
= &sline
[lno
];
483 sl
->lost
= coalesce_lines(sl
->lost
, &sl
->lenlost
,
485 sl
->plost
.len
, n
, flags
);
486 sl
->plost
.lost_head
= sl
->plost
.lost_tail
= NULL
;
490 /* How many lines would this sline advance the p_lno? */
491 ll
= sline
[lno
].lost
;
493 if (ll
->parent_map
& nmask
)
494 p_lno
++; /* '-' means parent had it */
497 if (lno
< cnt
&& !(sline
[lno
].flag
& nmask
))
498 p_lno
++; /* no '+' means parent had it */
500 sline
[lno
].p_lno
[n
] = p_lno
; /* trailer */
503 static unsigned long context
= 3;
504 static char combine_marker
= '@';
506 static int interesting(struct sline
*sline
, unsigned long all_mask
)
508 /* If some parents lost lines here, or if we have added to
509 * some parent, it is interesting.
511 return ((sline
->flag
& all_mask
) || sline
->lost
);
514 static unsigned long adjust_hunk_tail(struct sline
*sline
,
515 unsigned long all_mask
,
516 unsigned long hunk_begin
,
519 /* i points at the first uninteresting line. If the last line
520 * of the hunk was interesting only because it has some
521 * deletion, then it is not all that interesting for the
522 * purpose of giving trailing context lines. This is because
523 * we output '-' line and then unmodified sline[i-1] itself in
524 * that case which gives us one extra context line.
526 if ((hunk_begin
+ 1 <= i
) && !(sline
[i
-1].flag
& all_mask
))
531 static unsigned long find_next(struct sline
*sline
,
535 int look_for_uninteresting
)
537 /* We have examined up to i-1 and are about to look at i.
538 * Find next interesting or uninteresting line. Here,
539 * "interesting" does not mean interesting(), but marked by
540 * the give_context() function below (i.e. it includes context
541 * lines that are not interesting to interesting() function
542 * that are surrounded by interesting() ones.
545 if (look_for_uninteresting
546 ? !(sline
[i
].flag
& mark
)
547 : (sline
[i
].flag
& mark
))
554 static int give_context(struct sline
*sline
, unsigned long cnt
, int num_parent
)
556 unsigned long all_mask
= (1UL<<num_parent
) - 1;
557 unsigned long mark
= (1UL<<num_parent
);
558 unsigned long no_pre_delete
= (2UL<<num_parent
);
561 /* Two groups of interesting lines may have a short gap of
562 * uninteresting lines. Connect such groups to give them a
565 * We first start from what the interesting() function says,
566 * and mark them with "mark", and paint context lines with the
567 * mark. So interesting() would still say false for such context
568 * lines but they are treated as "interesting" in the end.
570 i
= find_next(sline
, mark
, 0, cnt
, 0);
575 unsigned long j
= (context
< i
) ? (i
- context
) : 0;
578 /* Paint a few lines before the first interesting line. */
580 if (!(sline
[j
].flag
& mark
))
581 sline
[j
].flag
|= no_pre_delete
;
582 sline
[j
++].flag
|= mark
;
586 /* we know up to i is to be included. where does the
587 * next uninteresting one start?
589 j
= find_next(sline
, mark
, i
, cnt
, 1);
591 break; /* the rest are all interesting */
593 /* lookahead context lines */
594 k
= find_next(sline
, mark
, j
, cnt
, 0);
595 j
= adjust_hunk_tail(sline
, all_mask
, i
, j
);
597 if (k
< j
+ context
) {
598 /* k is interesting and [j,k) are not, but
599 * paint them interesting because the gap is small.
602 sline
[j
++].flag
|= mark
;
607 /* j is the first uninteresting line and there is
608 * no overlap beyond it within context lines. Paint
609 * the trailing edge a bit.
612 k
= (j
+ context
< cnt
+1) ? j
+ context
: cnt
+1;
614 sline
[j
++].flag
|= mark
;
619 static int make_hunks(struct sline
*sline
, unsigned long cnt
,
620 int num_parent
, int dense
)
622 unsigned long all_mask
= (1UL<<num_parent
) - 1;
623 unsigned long mark
= (1UL<<num_parent
);
625 int has_interesting
= 0;
627 for (i
= 0; i
<= cnt
; i
++) {
628 if (interesting(&sline
[i
], all_mask
))
629 sline
[i
].flag
|= mark
;
631 sline
[i
].flag
&= ~mark
;
634 return give_context(sline
, cnt
, num_parent
);
636 /* Look at each hunk, and if we have changes from only one
637 * parent, or the changes are the same from all but one
638 * parent, mark that uninteresting.
642 unsigned long j
, hunk_begin
, hunk_end
;
643 unsigned long same_diff
;
644 while (i
<= cnt
&& !(sline
[i
].flag
& mark
))
647 break; /* No more interesting hunks */
649 for (j
= i
+ 1; j
<= cnt
; j
++) {
650 if (!(sline
[j
].flag
& mark
)) {
651 /* Look beyond the end to see if there
652 * is an interesting line after this
653 * hunk within context span.
655 unsigned long la
; /* lookahead */
657 la
= adjust_hunk_tail(sline
, all_mask
,
659 la
= (la
+ context
< cnt
+ 1) ?
660 (la
+ context
) : cnt
+ 1;
661 while (la
&& j
<= --la
) {
662 if (sline
[la
].flag
& mark
) {
674 /* [i..hunk_end) are interesting. Now is it really
675 * interesting? We check if there are only two versions
676 * and the result matches one of them. That is, we look
678 * (+) line, which records lines added to which parents;
679 * this line appears in the result.
680 * (-) line, which records from what parents the line
681 * was removed; this line does not appear in the result.
682 * then check the set of parents the result has difference
683 * from, from all lines. If there are lines that has
684 * different set of parents that the result has differences
685 * from, that means we have more than two versions.
687 * Even when we have only two versions, if the result does
688 * not match any of the parents, the it should be considered
689 * interesting. In such a case, we would have all '+' line.
690 * After passing the above "two versions" test, that would
691 * appear as "the same set of parents" to be "all parents".
695 for (j
= i
; j
< hunk_end
&& !has_interesting
; j
++) {
696 unsigned long this_diff
= sline
[j
].flag
& all_mask
;
697 struct lline
*ll
= sline
[j
].lost
;
699 /* This has some changes. Is it the
703 same_diff
= this_diff
;
704 else if (same_diff
!= this_diff
) {
709 while (ll
&& !has_interesting
) {
710 /* Lost this line from these parents;
711 * who are they? Are they the same?
713 this_diff
= ll
->parent_map
;
715 same_diff
= this_diff
;
716 else if (same_diff
!= this_diff
) {
723 if (!has_interesting
&& same_diff
!= all_mask
) {
724 /* This hunk is not that interesting after all */
725 for (j
= hunk_begin
; j
< hunk_end
; j
++)
726 sline
[j
].flag
&= ~mark
;
731 has_interesting
= give_context(sline
, cnt
, num_parent
);
732 return has_interesting
;
735 static void show_parent_lno(struct sline
*sline
, unsigned long l0
, unsigned long l1
, int n
, unsigned long null_context
)
737 l0
= sline
[l0
].p_lno
[n
];
738 l1
= sline
[l1
].p_lno
[n
];
739 printf(" -%lu,%lu", l0
, l1
-l0
-null_context
);
742 static int hunk_comment_line(const char *bol
)
749 return (isalpha(ch
) || ch
== '_' || ch
== '$');
752 static void show_line_to_eol(const char *line
, int len
, const char *reset
)
754 int saw_cr_at_eol
= 0;
757 saw_cr_at_eol
= (len
&& line
[len
-1] == '\r');
759 printf("%.*s%s%s\n", len
- saw_cr_at_eol
, line
,
761 saw_cr_at_eol
? "\r" : "");
764 static void dump_sline(struct sline
*sline
, const char *line_prefix
,
765 unsigned long cnt
, int num_parent
,
766 int use_color
, int result_deleted
)
768 unsigned long mark
= (1UL<<num_parent
);
769 unsigned long no_pre_delete
= (2UL<<num_parent
);
771 unsigned long lno
= 0;
772 const char *c_frag
= diff_get_color(use_color
, DIFF_FRAGINFO
);
773 const char *c_func
= diff_get_color(use_color
, DIFF_FUNCINFO
);
774 const char *c_new
= diff_get_color(use_color
, DIFF_FILE_NEW
);
775 const char *c_old
= diff_get_color(use_color
, DIFF_FILE_OLD
);
776 const char *c_context
= diff_get_color(use_color
, DIFF_CONTEXT
);
777 const char *c_reset
= diff_get_color(use_color
, DIFF_RESET
);
780 return; /* result deleted */
783 unsigned long hunk_end
;
784 unsigned long rlines
;
785 const char *hunk_comment
= NULL
;
786 unsigned long null_context
= 0;
788 while (lno
<= cnt
&& !(sline
[lno
].flag
& mark
)) {
789 if (hunk_comment_line(sline
[lno
].bol
))
790 hunk_comment
= sline
[lno
].bol
;
796 for (hunk_end
= lno
+ 1; hunk_end
<= cnt
; hunk_end
++)
797 if (!(sline
[hunk_end
].flag
& mark
))
800 rlines
= hunk_end
- lno
;
802 rlines
--; /* pointing at the last delete hunk */
806 * Even when running with --unified=0, all
807 * lines in the hunk needs to be processed in
808 * the loop below in order to show the
809 * deletion recorded in lost_head. However,
810 * we do not want to show the resulting line
811 * with all blank context markers in such a
815 for (j
= lno
; j
< hunk_end
; j
++)
816 if (!(sline
[j
].flag
& (mark
-1)))
818 rlines
-= null_context
;
821 printf("%s%s", line_prefix
, c_frag
);
822 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
823 for (i
= 0; i
< num_parent
; i
++)
824 show_parent_lno(sline
, lno
, hunk_end
, i
, null_context
);
825 printf(" +%lu,%lu ", lno
+1, rlines
);
826 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
830 for (i
= 0; i
< 40; i
++) {
831 int ch
= hunk_comment
[i
] & 0xff;
832 if (!ch
|| ch
== '\n')
838 printf("%s%s %s%s", c_reset
,
841 for (i
= 0; i
< comment_end
; i
++)
842 putchar(hunk_comment
[i
]);
845 printf("%s\n", c_reset
);
846 while (lno
< hunk_end
) {
849 unsigned long p_mask
;
850 struct sline
*sl
= &sline
[lno
++];
851 ll
= (sl
->flag
& no_pre_delete
) ? NULL
: sl
->lost
;
853 printf("%s%s", line_prefix
, c_old
);
854 for (j
= 0; j
< num_parent
; j
++) {
855 if (ll
->parent_map
& (1UL<<j
))
860 show_line_to_eol(ll
->line
, -1, c_reset
);
866 fputs(line_prefix
, stdout
);
867 if (!(sl
->flag
& (mark
-1))) {
869 * This sline was here to hang the
870 * lost lines in front of it.
874 fputs(c_context
, stdout
);
877 fputs(c_new
, stdout
);
878 for (j
= 0; j
< num_parent
; j
++) {
879 if (p_mask
& sl
->flag
)
885 show_line_to_eol(sl
->bol
, sl
->len
, c_reset
);
890 static void reuse_combine_diff(struct sline
*sline
, unsigned long cnt
,
893 /* We have already examined parent j and we know parent i
894 * and parent j are the same, so reuse the combined result
895 * of parent j for parent i.
897 unsigned long lno
, imask
, jmask
;
901 for (lno
= 0; lno
<= cnt
; lno
++) {
902 struct lline
*ll
= sline
->lost
;
903 sline
->p_lno
[i
] = sline
->p_lno
[j
];
905 if (ll
->parent_map
& jmask
)
906 ll
->parent_map
|= imask
;
909 if (sline
->flag
& jmask
)
910 sline
->flag
|= imask
;
913 /* the overall size of the file (sline[cnt]) */
914 sline
->p_lno
[i
] = sline
->p_lno
[j
];
917 static void dump_quoted_path(const char *head
,
920 const char *line_prefix
,
921 const char *c_meta
, const char *c_reset
)
923 static struct strbuf buf
= STRBUF_INIT
;
926 strbuf_addstr(&buf
, line_prefix
);
927 strbuf_addstr(&buf
, c_meta
);
928 strbuf_addstr(&buf
, head
);
929 quote_two_c_style(&buf
, prefix
, path
, 0);
930 strbuf_addstr(&buf
, c_reset
);
934 static void show_combined_header(struct combine_diff_path
*elem
,
936 struct rev_info
*rev
,
937 const char *line_prefix
,
939 int show_file_header
)
941 struct diff_options
*opt
= &rev
->diffopt
;
942 int abbrev
= opt
->flags
.full_index
? the_hash_algo
->hexsz
: DEFAULT_ABBREV
;
943 const char *a_prefix
= opt
->a_prefix
? opt
->a_prefix
: "a/";
944 const char *b_prefix
= opt
->b_prefix
? opt
->b_prefix
: "b/";
945 const char *c_meta
= diff_get_color_opt(opt
, DIFF_METAINFO
);
946 const char *c_reset
= diff_get_color_opt(opt
, DIFF_RESET
);
951 int dense
= rev
->dense_combined_merges
;
953 if (rev
->loginfo
&& !rev
->no_commit_id
)
956 dump_quoted_path(dense
? "diff --cc " : "diff --combined ",
957 "", elem
->path
, line_prefix
, c_meta
, c_reset
);
958 printf("%s%sindex ", line_prefix
, c_meta
);
959 for (i
= 0; i
< num_parent
; i
++) {
960 abb
= repo_find_unique_abbrev(the_repository
,
961 &elem
->parent
[i
].oid
, abbrev
);
962 printf("%s%s", i
? "," : "", abb
);
964 abb
= repo_find_unique_abbrev(the_repository
, &elem
->oid
, abbrev
);
965 printf("..%s%s\n", abb
, c_reset
);
968 deleted
= !elem
->mode
;
970 /* We say it was added if nobody had it */
972 for (i
= 0; added
&& i
< num_parent
; i
++)
973 if (elem
->parent
[i
].status
!=
977 printf("%s%snew file mode %06o",
978 line_prefix
, c_meta
, elem
->mode
);
981 printf("%s%sdeleted file ",
982 line_prefix
, c_meta
);
984 for (i
= 0; i
< num_parent
; i
++) {
985 printf("%s%06o", i
? "," : "",
986 elem
->parent
[i
].mode
);
989 printf("..%06o", elem
->mode
);
991 printf("%s\n", c_reset
);
994 if (!show_file_header
)
997 if (rev
->combined_all_paths
) {
998 for (i
= 0; i
< num_parent
; i
++) {
999 char *path
= filename_changed(elem
->parent
[i
].status
)
1000 ? elem
->parent
[i
].path
.buf
: elem
->path
;
1001 if (elem
->parent
[i
].status
== DIFF_STATUS_ADDED
)
1002 dump_quoted_path("--- ", "", "/dev/null",
1003 line_prefix
, c_meta
, c_reset
);
1005 dump_quoted_path("--- ", a_prefix
, path
,
1006 line_prefix
, c_meta
, c_reset
);
1010 dump_quoted_path("--- ", "", "/dev/null",
1011 line_prefix
, c_meta
, c_reset
);
1013 dump_quoted_path("--- ", a_prefix
, elem
->path
,
1014 line_prefix
, c_meta
, c_reset
);
1017 dump_quoted_path("+++ ", "", "/dev/null",
1018 line_prefix
, c_meta
, c_reset
);
1020 dump_quoted_path("+++ ", b_prefix
, elem
->path
,
1021 line_prefix
, c_meta
, c_reset
);
1024 static void show_patch_diff(struct combine_diff_path
*elem
, int num_parent
,
1025 int working_tree_file
,
1026 struct rev_info
*rev
)
1028 struct diff_options
*opt
= &rev
->diffopt
;
1029 unsigned long result_size
, cnt
, lno
;
1030 int result_deleted
= 0;
1032 struct sline
*sline
; /* survived lines */
1033 int mode_differs
= 0;
1035 mmfile_t result_file
;
1036 struct userdiff_driver
*userdiff
;
1037 struct userdiff_driver
*textconv
= NULL
;
1039 const char *line_prefix
= diff_line_prefix(opt
);
1041 context
= opt
->context
;
1042 userdiff
= userdiff_find_by_path(opt
->repo
->index
, elem
->path
);
1044 userdiff
= userdiff_find_by_name("default");
1045 if (opt
->flags
.allow_textconv
)
1046 textconv
= userdiff_get_textconv(opt
->repo
, userdiff
);
1048 /* Read the result of merge first */
1049 if (!working_tree_file
)
1050 result
= grab_blob(opt
->repo
, &elem
->oid
, elem
->mode
, &result_size
,
1051 textconv
, elem
->path
);
1053 /* Used by diff-tree to read from the working tree */
1057 if (lstat(elem
->path
, &st
) < 0)
1060 if (S_ISLNK(st
.st_mode
)) {
1061 struct strbuf buf
= STRBUF_INIT
;
1063 if (strbuf_readlink(&buf
, elem
->path
, st
.st_size
) < 0) {
1064 error_errno("readlink(%s)", elem
->path
);
1067 result_size
= buf
.len
;
1068 result
= strbuf_detach(&buf
, NULL
);
1069 elem
->mode
= canon_mode(st
.st_mode
);
1070 } else if (S_ISDIR(st
.st_mode
)) {
1071 struct object_id oid
;
1072 if (repo_resolve_gitlink_ref(the_repository
, elem
->path
,
1074 result
= grab_blob(opt
->repo
, &elem
->oid
,
1075 elem
->mode
, &result_size
,
1078 result
= grab_blob(opt
->repo
, &oid
, elem
->mode
,
1079 &result_size
, NULL
, NULL
);
1080 } else if (textconv
) {
1081 struct diff_filespec
*df
= alloc_filespec(elem
->path
);
1082 fill_filespec(df
, null_oid(), 0, st
.st_mode
);
1083 result_size
= fill_textconv(opt
->repo
, textconv
, df
, &result
);
1085 } else if (0 <= (fd
= open(elem
->path
, O_RDONLY
))) {
1086 size_t len
= xsize_t(st
.st_size
);
1090 elem
->mode
= canon_mode(st
.st_mode
);
1091 /* if symlinks don't work, assume symlink if all parents
1094 is_file
= has_symlinks
;
1095 for (i
= 0; !is_file
&& i
< num_parent
; i
++)
1096 is_file
= !S_ISLNK(elem
->parent
[i
].mode
);
1098 elem
->mode
= canon_mode(S_IFLNK
);
1101 result
= xmallocz(len
);
1103 done
= read_in_full(fd
, result
, len
);
1105 die_errno("read error '%s'", elem
->path
);
1106 else if (done
< len
)
1107 die("early EOF '%s'", elem
->path
);
1109 /* If not a fake symlink, apply filters, e.g. autocrlf */
1111 struct strbuf buf
= STRBUF_INIT
;
1113 if (convert_to_git(rev
->diffopt
.repo
->index
,
1114 elem
->path
, result
, len
, &buf
, global_conv_flags_eol
)) {
1116 result
= strbuf_detach(&buf
, &len
);
1126 result
= xcalloc(1, 1);
1133 for (i
= 0; i
< num_parent
; i
++) {
1134 if (elem
->parent
[i
].mode
!= elem
->mode
) {
1142 else if (userdiff
->binary
!= -1)
1143 is_binary
= userdiff
->binary
;
1145 is_binary
= buffer_is_binary(result
, result_size
);
1146 for (i
= 0; !is_binary
&& i
< num_parent
; i
++) {
1149 buf
= grab_blob(opt
->repo
,
1150 &elem
->parent
[i
].oid
,
1151 elem
->parent
[i
].mode
,
1153 if (buffer_is_binary(buf
, size
))
1159 show_combined_header(elem
, num_parent
, rev
,
1160 line_prefix
, mode_differs
, 0);
1161 printf("Binary files differ\n");
1166 for (cnt
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
1170 if (result_size
&& result
[result_size
-1] != '\n')
1171 cnt
++; /* incomplete line */
1173 CALLOC_ARRAY(sline
, st_add(cnt
, 2));
1174 sline
[0].bol
= result
;
1175 for (lno
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
1177 sline
[lno
].len
= cp
- sline
[lno
].bol
;
1180 sline
[lno
].bol
= cp
+ 1;
1183 if (result_size
&& result
[result_size
-1] != '\n')
1184 sline
[cnt
-1].len
= result_size
- (sline
[cnt
-1].bol
- result
);
1186 result_file
.ptr
= result
;
1187 result_file
.size
= result_size
;
1190 * Even p_lno[cnt+1] is valid -- that is for the end line number
1191 * for deletion hunk at the end.
1193 CALLOC_ARRAY(sline
[0].p_lno
, st_mult(st_add(cnt
, 2), num_parent
));
1194 for (lno
= 0; lno
<= cnt
; lno
++)
1195 sline
[lno
+1].p_lno
= sline
[lno
].p_lno
+ num_parent
;
1197 for (i
= 0; i
< num_parent
; i
++) {
1199 for (j
= 0; j
< i
; j
++) {
1200 if (oideq(&elem
->parent
[i
].oid
,
1201 &elem
->parent
[j
].oid
)) {
1202 reuse_combine_diff(sline
, cnt
, i
, j
);
1207 combine_diff(opt
->repo
,
1208 &elem
->parent
[i
].oid
,
1209 elem
->parent
[i
].mode
,
1210 &result_file
, sline
,
1211 cnt
, i
, num_parent
, result_deleted
,
1212 textconv
, elem
->path
, opt
->xdl_opts
);
1215 show_hunks
= make_hunks(sline
, cnt
, num_parent
, rev
->dense_combined_merges
);
1217 if (show_hunks
|| mode_differs
|| working_tree_file
) {
1218 show_combined_header(elem
, num_parent
, rev
,
1219 line_prefix
, mode_differs
, 1);
1220 dump_sline(sline
, line_prefix
, cnt
, num_parent
,
1221 opt
->use_color
, result_deleted
);
1225 for (lno
= 0; lno
< cnt
+ 2; lno
++) {
1226 if (sline
[lno
].lost
) {
1227 struct lline
*ll
= sline
[lno
].lost
;
1229 struct lline
*tmp
= ll
;
1235 free(sline
[0].p_lno
);
1239 static void show_raw_diff(struct combine_diff_path
*p
, int num_parent
, struct rev_info
*rev
)
1241 struct diff_options
*opt
= &rev
->diffopt
;
1242 int line_termination
, inter_name_termination
, i
;
1243 const char *line_prefix
= diff_line_prefix(opt
);
1245 line_termination
= opt
->line_termination
;
1246 inter_name_termination
= '\t';
1247 if (!line_termination
)
1248 inter_name_termination
= 0;
1250 if (rev
->loginfo
&& !rev
->no_commit_id
)
1254 if (opt
->output_format
& DIFF_FORMAT_RAW
) {
1255 printf("%s", line_prefix
);
1257 /* As many colons as there are parents */
1258 for (i
= 0; i
< num_parent
; i
++)
1261 /* Show the modes */
1262 for (i
= 0; i
< num_parent
; i
++)
1263 printf("%06o ", p
->parent
[i
].mode
);
1264 printf("%06o", p
->mode
);
1267 for (i
= 0; i
< num_parent
; i
++)
1268 printf(" %s", diff_aligned_abbrev(&p
->parent
[i
].oid
,
1270 printf(" %s ", diff_aligned_abbrev(&p
->oid
, opt
->abbrev
));
1273 if (opt
->output_format
& (DIFF_FORMAT_RAW
| DIFF_FORMAT_NAME_STATUS
)) {
1274 for (i
= 0; i
< num_parent
; i
++)
1275 putchar(p
->parent
[i
].status
);
1276 putchar(inter_name_termination
);
1279 for (i
= 0; i
< num_parent
; i
++)
1280 if (rev
->combined_all_paths
) {
1281 if (filename_changed(p
->parent
[i
].status
))
1282 write_name_quoted(p
->parent
[i
].path
.buf
, stdout
,
1283 inter_name_termination
);
1285 write_name_quoted(p
->path
, stdout
,
1286 inter_name_termination
);
1288 write_name_quoted(p
->path
, stdout
, line_termination
);
1292 * The result (p->elem) is from the working tree and their
1293 * parents are typically from multiple stages during a merge
1294 * (i.e. diff-files) or the state in HEAD and in the index
1295 * (i.e. diff-index).
1297 void show_combined_diff(struct combine_diff_path
*p
,
1299 struct rev_info
*rev
)
1301 struct diff_options
*opt
= &rev
->diffopt
;
1303 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
1305 DIFF_FORMAT_NAME_STATUS
))
1306 show_raw_diff(p
, num_parent
, rev
);
1307 else if (opt
->output_format
& DIFF_FORMAT_PATCH
)
1308 show_patch_diff(p
, num_parent
, 1, rev
);
1311 static void free_combined_pair(struct diff_filepair
*pair
)
1318 * A combine_diff_path expresses N parents on the LHS against 1 merge
1319 * result. Synthesize a diff_filepair that has N entries on the "one"
1320 * side and 1 entry on the "two" side.
1322 * In the future, we might want to add more data to combine_diff_path
1323 * so that we can fill fields we are ignoring (most notably, size) here,
1324 * but currently nobody uses it, so this should suffice for now.
1326 static struct diff_filepair
*combined_pair(struct combine_diff_path
*p
,
1330 struct diff_filepair
*pair
;
1331 struct diff_filespec
*pool
;
1333 pair
= xmalloc(sizeof(*pair
));
1334 CALLOC_ARRAY(pool
, st_add(num_parent
, 1));
1335 pair
->one
= pool
+ 1;
1338 for (i
= 0; i
< num_parent
; i
++) {
1339 pair
->one
[i
].path
= p
->path
;
1340 pair
->one
[i
].mode
= p
->parent
[i
].mode
;
1341 oidcpy(&pair
->one
[i
].oid
, &p
->parent
[i
].oid
);
1342 pair
->one
[i
].oid_valid
= !is_null_oid(&p
->parent
[i
].oid
);
1343 pair
->one
[i
].has_more_entries
= 1;
1345 pair
->one
[num_parent
- 1].has_more_entries
= 0;
1347 pair
->two
->path
= p
->path
;
1348 pair
->two
->mode
= p
->mode
;
1349 oidcpy(&pair
->two
->oid
, &p
->oid
);
1350 pair
->two
->oid_valid
= !is_null_oid(&p
->oid
);
1354 static void handle_combined_callback(struct diff_options
*opt
,
1355 struct combine_diff_path
*paths
,
1359 struct combine_diff_path
*p
;
1360 struct diff_queue_struct q
;
1363 CALLOC_ARRAY(q
.queue
, num_paths
);
1364 q
.alloc
= num_paths
;
1366 for (i
= 0, p
= paths
; p
; p
= p
->next
)
1367 q
.queue
[i
++] = combined_pair(p
, num_parent
);
1368 opt
->format_callback(&q
, opt
, opt
->format_callback_data
);
1369 for (i
= 0; i
< num_paths
; i
++)
1370 free_combined_pair(q
.queue
[i
]);
1374 static const char *path_path(void *obj
)
1376 struct combine_diff_path
*path
= (struct combine_diff_path
*)obj
;
1382 * Diff stat formats which we always compute solely against the first parent.
1384 #define STAT_FORMAT_MASK (DIFF_FORMAT_NUMSTAT \
1385 | DIFF_FORMAT_SHORTSTAT \
1386 | DIFF_FORMAT_SUMMARY \
1387 | DIFF_FORMAT_DIRSTAT \
1388 | DIFF_FORMAT_DIFFSTAT)
1390 /* find set of paths that every parent touches */
1391 static struct combine_diff_path
*find_paths_generic(const struct object_id
*oid
,
1392 const struct oid_array
*parents
,
1393 struct diff_options
*opt
,
1394 int combined_all_paths
)
1396 struct combine_diff_path
*paths
= NULL
;
1397 int i
, num_parent
= parents
->nr
;
1398 int output_format
= opt
->output_format
;
1399 char *orderfile
= opt
->orderfile
;
1401 opt
->output_format
= DIFF_FORMAT_NO_OUTPUT
;
1402 /* tell diff_tree to emit paths in sorted (=tree) order */
1403 opt
->orderfile
= NULL
;
1405 /* D(A,P1...Pn) = D(A,P1) ^ ... ^ D(A,Pn) (wrt paths) */
1406 for (i
= 0; i
< num_parent
; i
++) {
1408 * show stat against the first parent even when doing
1411 int stat_opt
= output_format
& STAT_FORMAT_MASK
;
1412 if (i
== 0 && stat_opt
)
1413 opt
->output_format
= stat_opt
;
1415 opt
->output_format
= DIFF_FORMAT_NO_OUTPUT
;
1416 diff_tree_oid(&parents
->oid
[i
], oid
, "", opt
);
1418 paths
= intersect_paths(paths
, i
, num_parent
,
1419 combined_all_paths
);
1421 /* if showing diff, show it in requested order */
1422 if (opt
->output_format
!= DIFF_FORMAT_NO_OUTPUT
&&
1424 diffcore_order(orderfile
);
1430 opt
->output_format
= output_format
;
1431 opt
->orderfile
= orderfile
;
1437 * find set of paths that everybody touches, assuming diff is run without
1438 * rename/copy detection, etc, comparing all trees simultaneously (= faster).
1440 static struct combine_diff_path
*find_paths_multitree(
1441 const struct object_id
*oid
, const struct oid_array
*parents
,
1442 struct diff_options
*opt
)
1444 int i
, nparent
= parents
->nr
;
1445 const struct object_id
**parents_oid
;
1446 struct combine_diff_path paths_head
;
1449 ALLOC_ARRAY(parents_oid
, nparent
);
1450 for (i
= 0; i
< nparent
; i
++)
1451 parents_oid
[i
] = &parents
->oid
[i
];
1453 /* fake list head, so worker can assume it is non-NULL */
1454 paths_head
.next
= NULL
;
1456 strbuf_init(&base
, PATH_MAX
);
1457 diff_tree_paths(&paths_head
, oid
, parents_oid
, nparent
, &base
, opt
);
1459 strbuf_release(&base
);
1461 return paths_head
.next
;
1464 static int match_objfind(struct combine_diff_path
*path
,
1466 const struct oidset
*set
)
1469 if (oidset_contains(set
, &path
->oid
))
1471 for (i
= 0; i
< num_parent
; i
++) {
1472 if (oidset_contains(set
, &path
->parent
[i
].oid
))
1478 static struct combine_diff_path
*combined_objfind(struct diff_options
*opt
,
1479 struct combine_diff_path
*paths
,
1482 struct combine_diff_path
*ret
= NULL
, **tail
= &ret
;
1483 struct combine_diff_path
*p
= paths
;
1486 struct combine_diff_path
*next
= p
->next
;
1488 if (match_objfind(p
, num_parent
, opt
->objfind
)) {
1501 void diff_tree_combined(const struct object_id
*oid
,
1502 const struct oid_array
*parents
,
1503 struct rev_info
*rev
)
1505 struct diff_options
*opt
= &rev
->diffopt
;
1506 struct diff_options diffopts
;
1507 struct combine_diff_path
*p
, *paths
;
1508 int i
, num_paths
, needsep
, show_log_first
, num_parent
= parents
->nr
;
1509 int need_generic_pathscan
;
1511 if (opt
->ignore_regex_nr
)
1512 die("combined diff and '%s' cannot be used together",
1513 "--ignore-matching-lines");
1514 if (opt
->close_file
)
1515 die("combined diff and '%s' cannot be used together",
1518 /* nothing to do, if no parents */
1522 show_log_first
= !!rev
->loginfo
&& !rev
->no_commit_id
;
1524 if (show_log_first
) {
1527 if (rev
->verbose_header
&& opt
->output_format
&&
1528 opt
->output_format
!= DIFF_FORMAT_NO_OUTPUT
&&
1529 !commit_format_is_empty(rev
->commit_format
))
1530 printf("%s%c", diff_line_prefix(opt
),
1531 opt
->line_termination
);
1535 copy_pathspec(&diffopts
.pathspec
, &opt
->pathspec
);
1536 diffopts
.flags
.recursive
= 1;
1537 diffopts
.flags
.allow_external
= 0;
1539 /* find set of paths that everybody touches
1543 * Diffcore transformations are bound to diff_filespec and logic
1544 * comparing two entries - i.e. they do not apply directly to combine
1547 * If some of such transformations is requested - we launch generic
1548 * path scanning, which works significantly slower compared to
1549 * simultaneous all-trees-in-one-go scan in find_paths_multitree().
1551 * TODO some of the filters could be ported to work on
1552 * combine_diff_paths - i.e. all functionality that skips paths, so in
1553 * theory, we could end up having only multitree path scanning.
1555 * NOTE please keep this semantically in sync with diffcore_std()
1557 need_generic_pathscan
= opt
->skip_stat_unmatch
||
1558 opt
->flags
.follow_renames
||
1559 opt
->break_opt
!= -1 ||
1560 opt
->detect_rename
||
1561 (opt
->pickaxe_opts
&
1562 (DIFF_PICKAXE_KINDS_MASK
& ~DIFF_PICKAXE_KIND_OBJFIND
)) ||
1565 if (need_generic_pathscan
) {
1567 * NOTE generic case also handles --stat, as it computes
1568 * diff(sha1,parent_i) for all i to do the job, specifically
1571 paths
= find_paths_generic(oid
, parents
, &diffopts
,
1572 rev
->combined_all_paths
);
1576 paths
= find_paths_multitree(oid
, parents
, &diffopts
);
1578 if (opt
->pickaxe_opts
& DIFF_PICKAXE_KIND_OBJFIND
)
1579 paths
= combined_objfind(opt
, paths
, num_parent
);
1582 * show stat against the first parent even
1583 * when doing combined diff.
1585 stat_opt
= opt
->output_format
& STAT_FORMAT_MASK
;
1587 diffopts
.output_format
= stat_opt
;
1589 diff_tree_oid(&parents
->oid
[0], oid
, "", &diffopts
);
1590 diffcore_std(&diffopts
);
1592 diffcore_order(opt
->orderfile
);
1593 diff_flush(&diffopts
);
1597 /* find out number of surviving paths */
1598 for (num_paths
= 0, p
= paths
; p
; p
= p
->next
)
1601 /* order paths according to diffcore_order */
1602 if (opt
->orderfile
&& num_paths
) {
1603 struct obj_order
*o
;
1605 ALLOC_ARRAY(o
, num_paths
);
1606 for (i
= 0, p
= paths
; p
; p
= p
->next
, i
++)
1608 order_objects(opt
->orderfile
, path_path
, o
, num_paths
);
1609 for (i
= 0; i
< num_paths
- 1; i
++) {
1611 p
->next
= o
[i
+1].obj
;
1614 p
= o
[num_paths
-1].obj
;
1622 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
1624 DIFF_FORMAT_NAME_STATUS
)) {
1625 for (p
= paths
; p
; p
= p
->next
)
1626 show_raw_diff(p
, num_parent
, rev
);
1629 else if (opt
->output_format
& STAT_FORMAT_MASK
)
1631 else if (opt
->output_format
& DIFF_FORMAT_CALLBACK
)
1632 handle_combined_callback(opt
, paths
, num_parent
, num_paths
);
1634 if (opt
->output_format
& DIFF_FORMAT_PATCH
) {
1636 printf("%s%c", diff_line_prefix(opt
),
1637 opt
->line_termination
);
1638 for (p
= paths
; p
; p
= p
->next
)
1639 show_patch_diff(p
, num_parent
, 0, rev
);
1643 /* Clean things up */
1645 struct combine_diff_path
*tmp
= paths
;
1646 paths
= paths
->next
;
1647 for (i
= 0; i
< num_parent
; i
++)
1648 if (rev
->combined_all_paths
&&
1649 filename_changed(tmp
->parent
[i
].status
))
1650 strbuf_release(&tmp
->parent
[i
].path
);
1654 clear_pathspec(&diffopts
.pathspec
);
1657 void diff_tree_combined_merge(const struct commit
*commit
,
1658 struct rev_info
*rev
)
1660 struct commit_list
*parent
= get_saved_parents(rev
, commit
);
1661 struct oid_array parents
= OID_ARRAY_INIT
;
1664 oid_array_append(&parents
, &parent
->item
->object
.oid
);
1665 parent
= parent
->next
;
1667 diff_tree_combined(&commit
->object
.oid
, &parents
, rev
);
1668 oid_array_clear(&parents
);