2 #include "object-store.h"
8 #include "environment.h"
10 #include "object-name.h"
12 #include "xdiff-interface.h"
13 #include "xdiff/xmacros.h"
17 #include "oid-array.h"
21 static int compare_paths(const struct combine_diff_path
*one
,
22 const struct diff_filespec
*two
)
24 if (!S_ISDIR(one
->mode
) && !S_ISDIR(two
->mode
))
25 return strcmp(one
->path
, two
->path
);
27 return base_name_compare(one
->path
, strlen(one
->path
), one
->mode
,
28 two
->path
, strlen(two
->path
), two
->mode
);
31 static int filename_changed(char status
)
33 return status
== 'R' || status
== 'C';
36 static struct combine_diff_path
*intersect_paths(
37 struct combine_diff_path
*curr
,
40 int combined_all_paths
)
42 struct diff_queue_struct
*q
= &diff_queued_diff
;
43 struct combine_diff_path
*p
, **tail
= &curr
;
47 for (i
= 0; i
< q
->nr
; i
++) {
50 if (diff_unmodified_pair(q
->queue
[i
]))
52 path
= q
->queue
[i
]->two
->path
;
54 p
= xmalloc(combine_diff_path_size(num_parent
, len
));
55 p
->path
= (char *) &(p
->parent
[num_parent
]);
56 memcpy(p
->path
, path
, len
);
60 sizeof(p
->parent
[0]) * num_parent
);
62 oidcpy(&p
->oid
, &q
->queue
[i
]->two
->oid
);
63 p
->mode
= q
->queue
[i
]->two
->mode
;
64 oidcpy(&p
->parent
[n
].oid
, &q
->queue
[i
]->one
->oid
);
65 p
->parent
[n
].mode
= q
->queue
[i
]->one
->mode
;
66 p
->parent
[n
].status
= q
->queue
[i
]->status
;
68 if (combined_all_paths
&&
69 filename_changed(p
->parent
[n
].status
)) {
70 strbuf_init(&p
->parent
[n
].path
, 0);
71 strbuf_addstr(&p
->parent
[n
].path
,
72 q
->queue
[i
]->one
->path
);
81 * paths in curr (linked list) and q->queue[] (array) are
82 * both sorted in the tree order.
85 while ((p
= *tail
) != NULL
) {
87 ? -1 : compare_paths(p
, q
->queue
[i
]->two
));
90 /* p->path not in q->queue[]; drop it */
92 for (j
= 0; j
< num_parent
; j
++)
93 if (combined_all_paths
&&
94 filename_changed(p
->parent
[j
].status
))
95 strbuf_release(&p
->parent
[j
].path
);
101 /* q->queue[i] not in p->path; skip it */
106 oidcpy(&p
->parent
[n
].oid
, &q
->queue
[i
]->one
->oid
);
107 p
->parent
[n
].mode
= q
->queue
[i
]->one
->mode
;
108 p
->parent
[n
].status
= q
->queue
[i
]->status
;
109 if (combined_all_paths
&&
110 filename_changed(p
->parent
[n
].status
))
111 strbuf_addstr(&p
->parent
[n
].path
,
112 q
->queue
[i
]->one
->path
);
120 /* Lines lost from parent */
122 struct lline
*next
, *prev
;
124 unsigned long parent_map
;
125 char line
[FLEX_ARRAY
];
128 /* Lines lost from current parent (before coalescing) */
130 struct lline
*lost_head
, *lost_tail
;
134 /* Lines surviving in the merge result */
136 /* Accumulated and coalesced lost lines */
142 /* bit 0 up to (N-1) are on if the parent has this line (i.e.
143 * we did not change it).
144 * bit N is used for "interesting" lines, including context.
145 * bit (N+1) is used for "do not show deletion before this".
148 unsigned long *p_lno
;
151 static int match_string_spaces(const char *line1
, int len1
,
152 const char *line2
, int len2
,
155 if (flags
& XDF_WHITESPACE_FLAGS
) {
156 for (; len1
> 0 && XDL_ISSPACE(line1
[len1
- 1]); len1
--);
157 for (; len2
> 0 && XDL_ISSPACE(line2
[len2
- 1]); len2
--);
160 if (!(flags
& (XDF_IGNORE_WHITESPACE
| XDF_IGNORE_WHITESPACE_CHANGE
)))
161 return (len1
== len2
&& !memcmp(line1
, line2
, len1
));
163 while (len1
> 0 && len2
> 0) {
166 if (XDL_ISSPACE(line1
[len1
]) || XDL_ISSPACE(line2
[len2
])) {
167 if ((flags
& XDF_IGNORE_WHITESPACE_CHANGE
) &&
168 (!XDL_ISSPACE(line1
[len1
]) || !XDL_ISSPACE(line2
[len2
])))
171 for (; len1
> 0 && XDL_ISSPACE(line1
[len1
]); len1
--);
172 for (; len2
> 0 && XDL_ISSPACE(line2
[len2
]); len2
--);
174 if (line1
[len1
] != line2
[len2
])
178 if (flags
& XDF_IGNORE_WHITESPACE
) {
179 /* Consume remaining spaces */
180 for (; len1
> 0 && XDL_ISSPACE(line1
[len1
- 1]); len1
--);
181 for (; len2
> 0 && XDL_ISSPACE(line2
[len2
- 1]); len2
--);
184 /* We matched full line1 and line2 */
191 enum coalesce_direction
{ MATCH
, BASE
, NEW
};
193 /* Coalesce new lines into base by finding LCS */
194 static struct lline
*coalesce_lines(struct lline
*base
, int *lenbase
,
195 struct lline
*newline
, int lennew
,
196 unsigned long parent
, long flags
)
199 enum coalesce_direction
**directions
;
200 struct lline
*baseend
, *newend
= NULL
;
201 int i
, j
, origbaselen
= *lenbase
;
212 * Coalesce new lines into base by finding the LCS
213 * - Create the table to run dynamic programming
215 * - Then reverse read the direction structure:
216 * - If we have MATCH, assign parent to base flag, and consume
217 * both baseend and newend
218 * - Else if we have BASE, consume baseend
219 * - Else if we have NEW, insert newend lline into base and
222 CALLOC_ARRAY(lcs
, st_add(origbaselen
, 1));
223 CALLOC_ARRAY(directions
, st_add(origbaselen
, 1));
224 for (i
= 0; i
< origbaselen
+ 1; i
++) {
225 CALLOC_ARRAY(lcs
[i
], st_add(lennew
, 1));
226 CALLOC_ARRAY(directions
[i
], st_add(lennew
, 1));
227 directions
[i
][0] = BASE
;
229 for (j
= 1; j
< lennew
+ 1; j
++)
230 directions
[0][j
] = NEW
;
232 for (i
= 1, baseend
= base
; i
< origbaselen
+ 1; i
++) {
233 for (j
= 1, newend
= newline
; j
< lennew
+ 1; j
++) {
234 if (match_string_spaces(baseend
->line
, baseend
->len
,
235 newend
->line
, newend
->len
, flags
)) {
236 lcs
[i
][j
] = lcs
[i
- 1][j
- 1] + 1;
237 directions
[i
][j
] = MATCH
;
238 } else if (lcs
[i
][j
- 1] >= lcs
[i
- 1][j
]) {
239 lcs
[i
][j
] = lcs
[i
][j
- 1];
240 directions
[i
][j
] = NEW
;
242 lcs
[i
][j
] = lcs
[i
- 1][j
];
243 directions
[i
][j
] = BASE
;
246 newend
= newend
->next
;
249 baseend
= baseend
->next
;
252 for (i
= 0; i
< origbaselen
+ 1; i
++)
256 /* At this point, baseend and newend point to the end of each lists */
259 while (i
!= 0 || j
!= 0) {
260 if (directions
[i
][j
] == MATCH
) {
261 baseend
->parent_map
|= 1<<parent
;
262 baseend
= baseend
->prev
;
263 newend
= newend
->prev
;
266 } else if (directions
[i
][j
] == NEW
) {
270 /* Remove lline from new list and update newend */
272 lline
->prev
->next
= lline
->next
;
274 newline
= lline
->next
;
276 lline
->next
->prev
= lline
->prev
;
278 newend
= lline
->prev
;
281 /* Add lline to base list */
283 lline
->next
= baseend
->next
;
284 lline
->prev
= baseend
;
286 lline
->prev
->next
= lline
;
295 lline
->next
->prev
= lline
;
298 baseend
= baseend
->prev
;
305 struct lline
*lline
= newend
;
306 newend
= newend
->next
;
310 for (i
= 0; i
< origbaselen
+ 1; i
++)
317 static char *grab_blob(struct repository
*r
,
318 const struct object_id
*oid
, unsigned int mode
,
319 unsigned long *size
, struct userdiff_driver
*textconv
,
323 enum object_type type
;
325 if (S_ISGITLINK(mode
)) {
326 struct strbuf buf
= STRBUF_INIT
;
327 strbuf_addf(&buf
, "Subproject commit %s\n", oid_to_hex(oid
));
329 blob
= strbuf_detach(&buf
, NULL
);
330 } else if (is_null_oid(oid
)) {
333 return xcalloc(1, 1);
334 } else if (textconv
) {
335 struct diff_filespec
*df
= alloc_filespec(path
);
336 fill_filespec(df
, oid
, 1, mode
);
337 *size
= fill_textconv(r
, textconv
, df
, &blob
);
340 blob
= repo_read_object_file(r
, oid
, &type
, size
);
341 if (type
!= OBJ_BLOB
)
342 die("object '%s' is not a blob!", oid_to_hex(oid
));
347 static void append_lost(struct sline
*sline
, int n
, const char *line
, int len
)
350 unsigned long this_mask
= (1UL<<n
);
351 if (line
[len
-1] == '\n')
354 FLEX_ALLOC_MEM(lline
, line
, line
, len
);
357 lline
->prev
= sline
->plost
.lost_tail
;
359 lline
->prev
->next
= lline
;
361 sline
->plost
.lost_head
= lline
;
362 sline
->plost
.lost_tail
= lline
;
364 lline
->parent_map
= this_mask
;
367 struct combine_diff_state
{
374 struct sline
*lost_bucket
;
377 static void consume_hunk(void *state_
,
380 const char *func UNUSED
, long funclen UNUSED
)
382 struct combine_diff_state
*state
= state_
;
388 state
->lno
= state
->nb
;
389 if (state
->nn
== 0) {
390 /* @@ -X,Y +N,0 @@ removed Y lines
391 * that would have come *after* line N
392 * in the result. Our lost buckets hang
393 * to the line after the removed lines,
395 * Note that this is correct even when N == 0,
396 * in which case the hunk removes the first
399 state
->lost_bucket
= &state
->sline
[state
->nb
];
403 state
->lost_bucket
= &state
->sline
[state
->nb
-1];
405 if (!state
->sline
[state
->nb
-1].p_lno
)
406 CALLOC_ARRAY(state
->sline
[state
->nb
- 1].p_lno
,
408 state
->sline
[state
->nb
-1].p_lno
[state
->n
] = state
->ob
;
411 static int consume_line(void *state_
, char *line
, unsigned long len
)
413 struct combine_diff_state
*state
= state_
;
414 if (!state
->lost_bucket
)
415 return 0; /* not in any hunk yet */
418 append_lost(state
->lost_bucket
, state
->n
, line
+1, len
-1);
421 state
->sline
[state
->lno
-1].flag
|= state
->nmask
;
428 static void combine_diff(struct repository
*r
,
429 const struct object_id
*parent
, unsigned int mode
,
430 mmfile_t
*result_file
,
431 struct sline
*sline
, unsigned int cnt
, int n
,
432 int num_parent
, int result_deleted
,
433 struct userdiff_driver
*textconv
,
434 const char *path
, long flags
)
436 unsigned int p_lno
, lno
;
437 unsigned long nmask
= (1UL << n
);
440 mmfile_t parent_file
;
441 struct combine_diff_state state
;
445 return; /* result deleted */
447 parent_file
.ptr
= grab_blob(r
, parent
, mode
, &sz
, textconv
, path
);
448 parent_file
.size
= sz
;
449 memset(&xpp
, 0, sizeof(xpp
));
451 memset(&xecfg
, 0, sizeof(xecfg
));
452 memset(&state
, 0, sizeof(state
));
456 state
.num_parent
= num_parent
;
459 if (xdi_diff_outf(&parent_file
, result_file
, consume_hunk
,
460 consume_line
, &state
, &xpp
, &xecfg
))
461 die("unable to generate combined diff for %s",
463 free(parent_file
.ptr
);
465 /* Assign line numbers for this parent.
467 * sline[lno].p_lno[n] records the first line number
468 * (counting from 1) for parent N if the final hunk display
469 * started by showing sline[lno] (possibly showing the lost
470 * lines attached to it first).
472 for (lno
= 0, p_lno
= 1; lno
<= cnt
; lno
++) {
474 sline
[lno
].p_lno
[n
] = p_lno
;
476 /* Coalesce new lines */
477 if (sline
[lno
].plost
.lost_head
) {
478 struct sline
*sl
= &sline
[lno
];
479 sl
->lost
= coalesce_lines(sl
->lost
, &sl
->lenlost
,
481 sl
->plost
.len
, n
, flags
);
482 sl
->plost
.lost_head
= sl
->plost
.lost_tail
= NULL
;
486 /* How many lines would this sline advance the p_lno? */
487 ll
= sline
[lno
].lost
;
489 if (ll
->parent_map
& nmask
)
490 p_lno
++; /* '-' means parent had it */
493 if (lno
< cnt
&& !(sline
[lno
].flag
& nmask
))
494 p_lno
++; /* no '+' means parent had it */
496 sline
[lno
].p_lno
[n
] = p_lno
; /* trailer */
499 static unsigned long context
= 3;
500 static char combine_marker
= '@';
502 static int interesting(struct sline
*sline
, unsigned long all_mask
)
504 /* If some parents lost lines here, or if we have added to
505 * some parent, it is interesting.
507 return ((sline
->flag
& all_mask
) || sline
->lost
);
510 static unsigned long adjust_hunk_tail(struct sline
*sline
,
511 unsigned long all_mask
,
512 unsigned long hunk_begin
,
515 /* i points at the first uninteresting line. If the last line
516 * of the hunk was interesting only because it has some
517 * deletion, then it is not all that interesting for the
518 * purpose of giving trailing context lines. This is because
519 * we output '-' line and then unmodified sline[i-1] itself in
520 * that case which gives us one extra context line.
522 if ((hunk_begin
+ 1 <= i
) && !(sline
[i
-1].flag
& all_mask
))
527 static unsigned long find_next(struct sline
*sline
,
531 int look_for_uninteresting
)
533 /* We have examined up to i-1 and are about to look at i.
534 * Find next interesting or uninteresting line. Here,
535 * "interesting" does not mean interesting(), but marked by
536 * the give_context() function below (i.e. it includes context
537 * lines that are not interesting to interesting() function
538 * that are surrounded by interesting() ones.
541 if (look_for_uninteresting
542 ? !(sline
[i
].flag
& mark
)
543 : (sline
[i
].flag
& mark
))
550 static int give_context(struct sline
*sline
, unsigned long cnt
, int num_parent
)
552 unsigned long all_mask
= (1UL<<num_parent
) - 1;
553 unsigned long mark
= (1UL<<num_parent
);
554 unsigned long no_pre_delete
= (2UL<<num_parent
);
557 /* Two groups of interesting lines may have a short gap of
558 * uninteresting lines. Connect such groups to give them a
561 * We first start from what the interesting() function says,
562 * and mark them with "mark", and paint context lines with the
563 * mark. So interesting() would still say false for such context
564 * lines but they are treated as "interesting" in the end.
566 i
= find_next(sline
, mark
, 0, cnt
, 0);
571 unsigned long j
= (context
< i
) ? (i
- context
) : 0;
574 /* Paint a few lines before the first interesting line. */
576 if (!(sline
[j
].flag
& mark
))
577 sline
[j
].flag
|= no_pre_delete
;
578 sline
[j
++].flag
|= mark
;
582 /* we know up to i is to be included. where does the
583 * next uninteresting one start?
585 j
= find_next(sline
, mark
, i
, cnt
, 1);
587 break; /* the rest are all interesting */
589 /* lookahead context lines */
590 k
= find_next(sline
, mark
, j
, cnt
, 0);
591 j
= adjust_hunk_tail(sline
, all_mask
, i
, j
);
593 if (k
< j
+ context
) {
594 /* k is interesting and [j,k) are not, but
595 * paint them interesting because the gap is small.
598 sline
[j
++].flag
|= mark
;
603 /* j is the first uninteresting line and there is
604 * no overlap beyond it within context lines. Paint
605 * the trailing edge a bit.
608 k
= (j
+ context
< cnt
+1) ? j
+ context
: cnt
+1;
610 sline
[j
++].flag
|= mark
;
615 static int make_hunks(struct sline
*sline
, unsigned long cnt
,
616 int num_parent
, int dense
)
618 unsigned long all_mask
= (1UL<<num_parent
) - 1;
619 unsigned long mark
= (1UL<<num_parent
);
621 int has_interesting
= 0;
623 for (i
= 0; i
<= cnt
; i
++) {
624 if (interesting(&sline
[i
], all_mask
))
625 sline
[i
].flag
|= mark
;
627 sline
[i
].flag
&= ~mark
;
630 return give_context(sline
, cnt
, num_parent
);
632 /* Look at each hunk, and if we have changes from only one
633 * parent, or the changes are the same from all but one
634 * parent, mark that uninteresting.
638 unsigned long j
, hunk_begin
, hunk_end
;
639 unsigned long same_diff
;
640 while (i
<= cnt
&& !(sline
[i
].flag
& mark
))
643 break; /* No more interesting hunks */
645 for (j
= i
+ 1; j
<= cnt
; j
++) {
646 if (!(sline
[j
].flag
& mark
)) {
647 /* Look beyond the end to see if there
648 * is an interesting line after this
649 * hunk within context span.
651 unsigned long la
; /* lookahead */
653 la
= adjust_hunk_tail(sline
, all_mask
,
655 la
= (la
+ context
< cnt
+ 1) ?
656 (la
+ context
) : cnt
+ 1;
657 while (la
&& j
<= --la
) {
658 if (sline
[la
].flag
& mark
) {
670 /* [i..hunk_end) are interesting. Now is it really
671 * interesting? We check if there are only two versions
672 * and the result matches one of them. That is, we look
674 * (+) line, which records lines added to which parents;
675 * this line appears in the result.
676 * (-) line, which records from what parents the line
677 * was removed; this line does not appear in the result.
678 * then check the set of parents the result has difference
679 * from, from all lines. If there are lines that has
680 * different set of parents that the result has differences
681 * from, that means we have more than two versions.
683 * Even when we have only two versions, if the result does
684 * not match any of the parents, the it should be considered
685 * interesting. In such a case, we would have all '+' line.
686 * After passing the above "two versions" test, that would
687 * appear as "the same set of parents" to be "all parents".
691 for (j
= i
; j
< hunk_end
&& !has_interesting
; j
++) {
692 unsigned long this_diff
= sline
[j
].flag
& all_mask
;
693 struct lline
*ll
= sline
[j
].lost
;
695 /* This has some changes. Is it the
699 same_diff
= this_diff
;
700 else if (same_diff
!= this_diff
) {
705 while (ll
&& !has_interesting
) {
706 /* Lost this line from these parents;
707 * who are they? Are they the same?
709 this_diff
= ll
->parent_map
;
711 same_diff
= this_diff
;
712 else if (same_diff
!= this_diff
) {
719 if (!has_interesting
&& same_diff
!= all_mask
) {
720 /* This hunk is not that interesting after all */
721 for (j
= hunk_begin
; j
< hunk_end
; j
++)
722 sline
[j
].flag
&= ~mark
;
727 has_interesting
= give_context(sline
, cnt
, num_parent
);
728 return has_interesting
;
731 static void show_parent_lno(struct sline
*sline
, unsigned long l0
, unsigned long l1
, int n
, unsigned long null_context
)
733 l0
= sline
[l0
].p_lno
[n
];
734 l1
= sline
[l1
].p_lno
[n
];
735 printf(" -%lu,%lu", l0
, l1
-l0
-null_context
);
738 static int hunk_comment_line(const char *bol
)
745 return (isalpha(ch
) || ch
== '_' || ch
== '$');
748 static void show_line_to_eol(const char *line
, int len
, const char *reset
)
750 int saw_cr_at_eol
= 0;
753 saw_cr_at_eol
= (len
&& line
[len
-1] == '\r');
755 printf("%.*s%s%s\n", len
- saw_cr_at_eol
, line
,
757 saw_cr_at_eol
? "\r" : "");
760 static void dump_sline(struct sline
*sline
, const char *line_prefix
,
761 unsigned long cnt
, int num_parent
,
762 int use_color
, int result_deleted
)
764 unsigned long mark
= (1UL<<num_parent
);
765 unsigned long no_pre_delete
= (2UL<<num_parent
);
767 unsigned long lno
= 0;
768 const char *c_frag
= diff_get_color(use_color
, DIFF_FRAGINFO
);
769 const char *c_func
= diff_get_color(use_color
, DIFF_FUNCINFO
);
770 const char *c_new
= diff_get_color(use_color
, DIFF_FILE_NEW
);
771 const char *c_old
= diff_get_color(use_color
, DIFF_FILE_OLD
);
772 const char *c_context
= diff_get_color(use_color
, DIFF_CONTEXT
);
773 const char *c_reset
= diff_get_color(use_color
, DIFF_RESET
);
776 return; /* result deleted */
779 unsigned long hunk_end
;
780 unsigned long rlines
;
781 const char *hunk_comment
= NULL
;
782 unsigned long null_context
= 0;
784 while (lno
<= cnt
&& !(sline
[lno
].flag
& mark
)) {
785 if (hunk_comment_line(sline
[lno
].bol
))
786 hunk_comment
= sline
[lno
].bol
;
792 for (hunk_end
= lno
+ 1; hunk_end
<= cnt
; hunk_end
++)
793 if (!(sline
[hunk_end
].flag
& mark
))
796 rlines
= hunk_end
- lno
;
798 rlines
--; /* pointing at the last delete hunk */
802 * Even when running with --unified=0, all
803 * lines in the hunk needs to be processed in
804 * the loop below in order to show the
805 * deletion recorded in lost_head. However,
806 * we do not want to show the resulting line
807 * with all blank context markers in such a
811 for (j
= lno
; j
< hunk_end
; j
++)
812 if (!(sline
[j
].flag
& (mark
-1)))
814 rlines
-= null_context
;
817 printf("%s%s", line_prefix
, c_frag
);
818 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
819 for (i
= 0; i
< num_parent
; i
++)
820 show_parent_lno(sline
, lno
, hunk_end
, i
, null_context
);
821 printf(" +%lu,%lu ", lno
+1, rlines
);
822 for (i
= 0; i
<= num_parent
; i
++) putchar(combine_marker
);
826 for (i
= 0; i
< 40; i
++) {
827 int ch
= hunk_comment
[i
] & 0xff;
828 if (!ch
|| ch
== '\n')
834 printf("%s%s %s%s", c_reset
,
837 for (i
= 0; i
< comment_end
; i
++)
838 putchar(hunk_comment
[i
]);
841 printf("%s\n", c_reset
);
842 while (lno
< hunk_end
) {
845 unsigned long p_mask
;
846 struct sline
*sl
= &sline
[lno
++];
847 ll
= (sl
->flag
& no_pre_delete
) ? NULL
: sl
->lost
;
849 printf("%s%s", line_prefix
, c_old
);
850 for (j
= 0; j
< num_parent
; j
++) {
851 if (ll
->parent_map
& (1UL<<j
))
856 show_line_to_eol(ll
->line
, -1, c_reset
);
862 fputs(line_prefix
, stdout
);
863 if (!(sl
->flag
& (mark
-1))) {
865 * This sline was here to hang the
866 * lost lines in front of it.
870 fputs(c_context
, stdout
);
873 fputs(c_new
, stdout
);
874 for (j
= 0; j
< num_parent
; j
++) {
875 if (p_mask
& sl
->flag
)
881 show_line_to_eol(sl
->bol
, sl
->len
, c_reset
);
886 static void reuse_combine_diff(struct sline
*sline
, unsigned long cnt
,
889 /* We have already examined parent j and we know parent i
890 * and parent j are the same, so reuse the combined result
891 * of parent j for parent i.
893 unsigned long lno
, imask
, jmask
;
897 for (lno
= 0; lno
<= cnt
; lno
++) {
898 struct lline
*ll
= sline
->lost
;
899 sline
->p_lno
[i
] = sline
->p_lno
[j
];
901 if (ll
->parent_map
& jmask
)
902 ll
->parent_map
|= imask
;
905 if (sline
->flag
& jmask
)
906 sline
->flag
|= imask
;
909 /* the overall size of the file (sline[cnt]) */
910 sline
->p_lno
[i
] = sline
->p_lno
[j
];
913 static void dump_quoted_path(const char *head
,
916 const char *line_prefix
,
917 const char *c_meta
, const char *c_reset
)
919 static struct strbuf buf
= STRBUF_INIT
;
922 strbuf_addstr(&buf
, line_prefix
);
923 strbuf_addstr(&buf
, c_meta
);
924 strbuf_addstr(&buf
, head
);
925 quote_two_c_style(&buf
, prefix
, path
, 0);
926 strbuf_addstr(&buf
, c_reset
);
930 static void show_combined_header(struct combine_diff_path
*elem
,
932 struct rev_info
*rev
,
933 const char *line_prefix
,
935 int show_file_header
)
937 struct diff_options
*opt
= &rev
->diffopt
;
938 int abbrev
= opt
->flags
.full_index
? the_hash_algo
->hexsz
: DEFAULT_ABBREV
;
939 const char *a_prefix
= opt
->a_prefix
? opt
->a_prefix
: "a/";
940 const char *b_prefix
= opt
->b_prefix
? opt
->b_prefix
: "b/";
941 const char *c_meta
= diff_get_color_opt(opt
, DIFF_METAINFO
);
942 const char *c_reset
= diff_get_color_opt(opt
, DIFF_RESET
);
947 int dense
= rev
->dense_combined_merges
;
949 if (rev
->loginfo
&& !rev
->no_commit_id
)
952 dump_quoted_path(dense
? "diff --cc " : "diff --combined ",
953 "", elem
->path
, line_prefix
, c_meta
, c_reset
);
954 printf("%s%sindex ", line_prefix
, c_meta
);
955 for (i
= 0; i
< num_parent
; i
++) {
956 abb
= repo_find_unique_abbrev(the_repository
,
957 &elem
->parent
[i
].oid
, abbrev
);
958 printf("%s%s", i
? "," : "", abb
);
960 abb
= repo_find_unique_abbrev(the_repository
, &elem
->oid
, abbrev
);
961 printf("..%s%s\n", abb
, c_reset
);
964 deleted
= !elem
->mode
;
966 /* We say it was added if nobody had it */
968 for (i
= 0; added
&& i
< num_parent
; i
++)
969 if (elem
->parent
[i
].status
!=
973 printf("%s%snew file mode %06o",
974 line_prefix
, c_meta
, elem
->mode
);
977 printf("%s%sdeleted file ",
978 line_prefix
, c_meta
);
980 for (i
= 0; i
< num_parent
; i
++) {
981 printf("%s%06o", i
? "," : "",
982 elem
->parent
[i
].mode
);
985 printf("..%06o", elem
->mode
);
987 printf("%s\n", c_reset
);
990 if (!show_file_header
)
993 if (rev
->combined_all_paths
) {
994 for (i
= 0; i
< num_parent
; i
++) {
995 char *path
= filename_changed(elem
->parent
[i
].status
)
996 ? elem
->parent
[i
].path
.buf
: elem
->path
;
997 if (elem
->parent
[i
].status
== DIFF_STATUS_ADDED
)
998 dump_quoted_path("--- ", "", "/dev/null",
999 line_prefix
, c_meta
, c_reset
);
1001 dump_quoted_path("--- ", a_prefix
, path
,
1002 line_prefix
, c_meta
, c_reset
);
1006 dump_quoted_path("--- ", "", "/dev/null",
1007 line_prefix
, c_meta
, c_reset
);
1009 dump_quoted_path("--- ", a_prefix
, elem
->path
,
1010 line_prefix
, c_meta
, c_reset
);
1013 dump_quoted_path("+++ ", "", "/dev/null",
1014 line_prefix
, c_meta
, c_reset
);
1016 dump_quoted_path("+++ ", b_prefix
, elem
->path
,
1017 line_prefix
, c_meta
, c_reset
);
1020 static void show_patch_diff(struct combine_diff_path
*elem
, int num_parent
,
1021 int working_tree_file
,
1022 struct rev_info
*rev
)
1024 struct diff_options
*opt
= &rev
->diffopt
;
1025 unsigned long result_size
, cnt
, lno
;
1026 int result_deleted
= 0;
1028 struct sline
*sline
; /* survived lines */
1029 int mode_differs
= 0;
1031 mmfile_t result_file
;
1032 struct userdiff_driver
*userdiff
;
1033 struct userdiff_driver
*textconv
= NULL
;
1035 const char *line_prefix
= diff_line_prefix(opt
);
1037 context
= opt
->context
;
1038 userdiff
= userdiff_find_by_path(opt
->repo
->index
, elem
->path
);
1040 userdiff
= userdiff_find_by_name("default");
1041 if (opt
->flags
.allow_textconv
)
1042 textconv
= userdiff_get_textconv(opt
->repo
, userdiff
);
1044 /* Read the result of merge first */
1045 if (!working_tree_file
)
1046 result
= grab_blob(opt
->repo
, &elem
->oid
, elem
->mode
, &result_size
,
1047 textconv
, elem
->path
);
1049 /* Used by diff-tree to read from the working tree */
1053 if (lstat(elem
->path
, &st
) < 0)
1056 if (S_ISLNK(st
.st_mode
)) {
1057 struct strbuf buf
= STRBUF_INIT
;
1059 if (strbuf_readlink(&buf
, elem
->path
, st
.st_size
) < 0) {
1060 error_errno("readlink(%s)", elem
->path
);
1063 result_size
= buf
.len
;
1064 result
= strbuf_detach(&buf
, NULL
);
1065 elem
->mode
= canon_mode(st
.st_mode
);
1066 } else if (S_ISDIR(st
.st_mode
)) {
1067 struct object_id oid
;
1068 if (resolve_gitlink_ref(elem
->path
, "HEAD", &oid
) < 0)
1069 result
= grab_blob(opt
->repo
, &elem
->oid
,
1070 elem
->mode
, &result_size
,
1073 result
= grab_blob(opt
->repo
, &oid
, elem
->mode
,
1074 &result_size
, NULL
, NULL
);
1075 } else if (textconv
) {
1076 struct diff_filespec
*df
= alloc_filespec(elem
->path
);
1077 fill_filespec(df
, null_oid(), 0, st
.st_mode
);
1078 result_size
= fill_textconv(opt
->repo
, textconv
, df
, &result
);
1080 } else if (0 <= (fd
= open(elem
->path
, O_RDONLY
))) {
1081 size_t len
= xsize_t(st
.st_size
);
1085 elem
->mode
= canon_mode(st
.st_mode
);
1086 /* if symlinks don't work, assume symlink if all parents
1089 is_file
= has_symlinks
;
1090 for (i
= 0; !is_file
&& i
< num_parent
; i
++)
1091 is_file
= !S_ISLNK(elem
->parent
[i
].mode
);
1093 elem
->mode
= canon_mode(S_IFLNK
);
1096 result
= xmallocz(len
);
1098 done
= read_in_full(fd
, result
, len
);
1100 die_errno("read error '%s'", elem
->path
);
1101 else if (done
< len
)
1102 die("early EOF '%s'", elem
->path
);
1104 /* If not a fake symlink, apply filters, e.g. autocrlf */
1106 struct strbuf buf
= STRBUF_INIT
;
1108 if (convert_to_git(rev
->diffopt
.repo
->index
,
1109 elem
->path
, result
, len
, &buf
, global_conv_flags_eol
)) {
1111 result
= strbuf_detach(&buf
, &len
);
1121 result
= xcalloc(1, 1);
1128 for (i
= 0; i
< num_parent
; i
++) {
1129 if (elem
->parent
[i
].mode
!= elem
->mode
) {
1137 else if (userdiff
->binary
!= -1)
1138 is_binary
= userdiff
->binary
;
1140 is_binary
= buffer_is_binary(result
, result_size
);
1141 for (i
= 0; !is_binary
&& i
< num_parent
; i
++) {
1144 buf
= grab_blob(opt
->repo
,
1145 &elem
->parent
[i
].oid
,
1146 elem
->parent
[i
].mode
,
1148 if (buffer_is_binary(buf
, size
))
1154 show_combined_header(elem
, num_parent
, rev
,
1155 line_prefix
, mode_differs
, 0);
1156 printf("Binary files differ\n");
1161 for (cnt
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
1165 if (result_size
&& result
[result_size
-1] != '\n')
1166 cnt
++; /* incomplete line */
1168 CALLOC_ARRAY(sline
, st_add(cnt
, 2));
1169 sline
[0].bol
= result
;
1170 for (lno
= 0, cp
= result
; cp
< result
+ result_size
; cp
++) {
1172 sline
[lno
].len
= cp
- sline
[lno
].bol
;
1175 sline
[lno
].bol
= cp
+ 1;
1178 if (result_size
&& result
[result_size
-1] != '\n')
1179 sline
[cnt
-1].len
= result_size
- (sline
[cnt
-1].bol
- result
);
1181 result_file
.ptr
= result
;
1182 result_file
.size
= result_size
;
1184 /* Even p_lno[cnt+1] is valid -- that is for the end line number
1185 * for deletion hunk at the end.
1187 CALLOC_ARRAY(sline
[0].p_lno
, st_mult(st_add(cnt
, 2), num_parent
));
1188 for (lno
= 0; lno
<= cnt
; lno
++)
1189 sline
[lno
+1].p_lno
= sline
[lno
].p_lno
+ num_parent
;
1191 for (i
= 0; i
< num_parent
; i
++) {
1193 for (j
= 0; j
< i
; j
++) {
1194 if (oideq(&elem
->parent
[i
].oid
,
1195 &elem
->parent
[j
].oid
)) {
1196 reuse_combine_diff(sline
, cnt
, i
, j
);
1201 combine_diff(opt
->repo
,
1202 &elem
->parent
[i
].oid
,
1203 elem
->parent
[i
].mode
,
1204 &result_file
, sline
,
1205 cnt
, i
, num_parent
, result_deleted
,
1206 textconv
, elem
->path
, opt
->xdl_opts
);
1209 show_hunks
= make_hunks(sline
, cnt
, num_parent
, rev
->dense_combined_merges
);
1211 if (show_hunks
|| mode_differs
|| working_tree_file
) {
1212 show_combined_header(elem
, num_parent
, rev
,
1213 line_prefix
, mode_differs
, 1);
1214 dump_sline(sline
, line_prefix
, cnt
, num_parent
,
1215 opt
->use_color
, result_deleted
);
1219 for (lno
= 0; lno
< cnt
; lno
++) {
1220 if (sline
[lno
].lost
) {
1221 struct lline
*ll
= sline
[lno
].lost
;
1223 struct lline
*tmp
= ll
;
1229 free(sline
[0].p_lno
);
1233 static void show_raw_diff(struct combine_diff_path
*p
, int num_parent
, struct rev_info
*rev
)
1235 struct diff_options
*opt
= &rev
->diffopt
;
1236 int line_termination
, inter_name_termination
, i
;
1237 const char *line_prefix
= diff_line_prefix(opt
);
1239 line_termination
= opt
->line_termination
;
1240 inter_name_termination
= '\t';
1241 if (!line_termination
)
1242 inter_name_termination
= 0;
1244 if (rev
->loginfo
&& !rev
->no_commit_id
)
1248 if (opt
->output_format
& DIFF_FORMAT_RAW
) {
1249 printf("%s", line_prefix
);
1251 /* As many colons as there are parents */
1252 for (i
= 0; i
< num_parent
; i
++)
1255 /* Show the modes */
1256 for (i
= 0; i
< num_parent
; i
++)
1257 printf("%06o ", p
->parent
[i
].mode
);
1258 printf("%06o", p
->mode
);
1261 for (i
= 0; i
< num_parent
; i
++)
1262 printf(" %s", diff_aligned_abbrev(&p
->parent
[i
].oid
,
1264 printf(" %s ", diff_aligned_abbrev(&p
->oid
, opt
->abbrev
));
1267 if (opt
->output_format
& (DIFF_FORMAT_RAW
| DIFF_FORMAT_NAME_STATUS
)) {
1268 for (i
= 0; i
< num_parent
; i
++)
1269 putchar(p
->parent
[i
].status
);
1270 putchar(inter_name_termination
);
1273 for (i
= 0; i
< num_parent
; i
++)
1274 if (rev
->combined_all_paths
) {
1275 if (filename_changed(p
->parent
[i
].status
))
1276 write_name_quoted(p
->parent
[i
].path
.buf
, stdout
,
1277 inter_name_termination
);
1279 write_name_quoted(p
->path
, stdout
,
1280 inter_name_termination
);
1282 write_name_quoted(p
->path
, stdout
, line_termination
);
1286 * The result (p->elem) is from the working tree and their
1287 * parents are typically from multiple stages during a merge
1288 * (i.e. diff-files) or the state in HEAD and in the index
1289 * (i.e. diff-index).
1291 void show_combined_diff(struct combine_diff_path
*p
,
1293 struct rev_info
*rev
)
1295 struct diff_options
*opt
= &rev
->diffopt
;
1297 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
1299 DIFF_FORMAT_NAME_STATUS
))
1300 show_raw_diff(p
, num_parent
, rev
);
1301 else if (opt
->output_format
& DIFF_FORMAT_PATCH
)
1302 show_patch_diff(p
, num_parent
, 1, rev
);
1305 static void free_combined_pair(struct diff_filepair
*pair
)
1312 * A combine_diff_path expresses N parents on the LHS against 1 merge
1313 * result. Synthesize a diff_filepair that has N entries on the "one"
1314 * side and 1 entry on the "two" side.
1316 * In the future, we might want to add more data to combine_diff_path
1317 * so that we can fill fields we are ignoring (most notably, size) here,
1318 * but currently nobody uses it, so this should suffice for now.
1320 static struct diff_filepair
*combined_pair(struct combine_diff_path
*p
,
1324 struct diff_filepair
*pair
;
1325 struct diff_filespec
*pool
;
1327 pair
= xmalloc(sizeof(*pair
));
1328 CALLOC_ARRAY(pool
, st_add(num_parent
, 1));
1329 pair
->one
= pool
+ 1;
1332 for (i
= 0; i
< num_parent
; i
++) {
1333 pair
->one
[i
].path
= p
->path
;
1334 pair
->one
[i
].mode
= p
->parent
[i
].mode
;
1335 oidcpy(&pair
->one
[i
].oid
, &p
->parent
[i
].oid
);
1336 pair
->one
[i
].oid_valid
= !is_null_oid(&p
->parent
[i
].oid
);
1337 pair
->one
[i
].has_more_entries
= 1;
1339 pair
->one
[num_parent
- 1].has_more_entries
= 0;
1341 pair
->two
->path
= p
->path
;
1342 pair
->two
->mode
= p
->mode
;
1343 oidcpy(&pair
->two
->oid
, &p
->oid
);
1344 pair
->two
->oid_valid
= !is_null_oid(&p
->oid
);
1348 static void handle_combined_callback(struct diff_options
*opt
,
1349 struct combine_diff_path
*paths
,
1353 struct combine_diff_path
*p
;
1354 struct diff_queue_struct q
;
1357 CALLOC_ARRAY(q
.queue
, num_paths
);
1358 q
.alloc
= num_paths
;
1360 for (i
= 0, p
= paths
; p
; p
= p
->next
)
1361 q
.queue
[i
++] = combined_pair(p
, num_parent
);
1362 opt
->format_callback(&q
, opt
, opt
->format_callback_data
);
1363 for (i
= 0; i
< num_paths
; i
++)
1364 free_combined_pair(q
.queue
[i
]);
1368 static const char *path_path(void *obj
)
1370 struct combine_diff_path
*path
= (struct combine_diff_path
*)obj
;
1376 * Diff stat formats which we always compute solely against the first parent.
1378 #define STAT_FORMAT_MASK (DIFF_FORMAT_NUMSTAT \
1379 | DIFF_FORMAT_SHORTSTAT \
1380 | DIFF_FORMAT_SUMMARY \
1381 | DIFF_FORMAT_DIRSTAT \
1382 | DIFF_FORMAT_DIFFSTAT)
1384 /* find set of paths that every parent touches */
1385 static struct combine_diff_path
*find_paths_generic(const struct object_id
*oid
,
1386 const struct oid_array
*parents
,
1387 struct diff_options
*opt
,
1388 int combined_all_paths
)
1390 struct combine_diff_path
*paths
= NULL
;
1391 int i
, num_parent
= parents
->nr
;
1393 int output_format
= opt
->output_format
;
1394 const char *orderfile
= opt
->orderfile
;
1396 opt
->output_format
= DIFF_FORMAT_NO_OUTPUT
;
1397 /* tell diff_tree to emit paths in sorted (=tree) order */
1398 opt
->orderfile
= NULL
;
1400 /* D(A,P1...Pn) = D(A,P1) ^ ... ^ D(A,Pn) (wrt paths) */
1401 for (i
= 0; i
< num_parent
; i
++) {
1403 * show stat against the first parent even when doing
1406 int stat_opt
= output_format
& STAT_FORMAT_MASK
;
1407 if (i
== 0 && stat_opt
)
1408 opt
->output_format
= stat_opt
;
1410 opt
->output_format
= DIFF_FORMAT_NO_OUTPUT
;
1411 diff_tree_oid(&parents
->oid
[i
], oid
, "", opt
);
1413 paths
= intersect_paths(paths
, i
, num_parent
,
1414 combined_all_paths
);
1416 /* if showing diff, show it in requested order */
1417 if (opt
->output_format
!= DIFF_FORMAT_NO_OUTPUT
&&
1419 diffcore_order(orderfile
);
1425 opt
->output_format
= output_format
;
1426 opt
->orderfile
= orderfile
;
1432 * find set of paths that everybody touches, assuming diff is run without
1433 * rename/copy detection, etc, comparing all trees simultaneously (= faster).
1435 static struct combine_diff_path
*find_paths_multitree(
1436 const struct object_id
*oid
, const struct oid_array
*parents
,
1437 struct diff_options
*opt
)
1439 int i
, nparent
= parents
->nr
;
1440 const struct object_id
**parents_oid
;
1441 struct combine_diff_path paths_head
;
1444 ALLOC_ARRAY(parents_oid
, nparent
);
1445 for (i
= 0; i
< nparent
; i
++)
1446 parents_oid
[i
] = &parents
->oid
[i
];
1448 /* fake list head, so worker can assume it is non-NULL */
1449 paths_head
.next
= NULL
;
1451 strbuf_init(&base
, PATH_MAX
);
1452 diff_tree_paths(&paths_head
, oid
, parents_oid
, nparent
, &base
, opt
);
1454 strbuf_release(&base
);
1456 return paths_head
.next
;
1459 static int match_objfind(struct combine_diff_path
*path
,
1461 const struct oidset
*set
)
1464 if (oidset_contains(set
, &path
->oid
))
1466 for (i
= 0; i
< num_parent
; i
++) {
1467 if (oidset_contains(set
, &path
->parent
[i
].oid
))
1473 static struct combine_diff_path
*combined_objfind(struct diff_options
*opt
,
1474 struct combine_diff_path
*paths
,
1477 struct combine_diff_path
*ret
= NULL
, **tail
= &ret
;
1478 struct combine_diff_path
*p
= paths
;
1481 struct combine_diff_path
*next
= p
->next
;
1483 if (match_objfind(p
, num_parent
, opt
->objfind
)) {
1496 void diff_tree_combined(const struct object_id
*oid
,
1497 const struct oid_array
*parents
,
1498 struct rev_info
*rev
)
1500 struct diff_options
*opt
= &rev
->diffopt
;
1501 struct diff_options diffopts
;
1502 struct combine_diff_path
*p
, *paths
;
1503 int i
, num_paths
, needsep
, show_log_first
, num_parent
= parents
->nr
;
1504 int need_generic_pathscan
;
1506 if (opt
->ignore_regex_nr
)
1507 die("combined diff and '%s' cannot be used together",
1508 "--ignore-matching-lines");
1509 if (opt
->close_file
)
1510 die("combined diff and '%s' cannot be used together",
1513 /* nothing to do, if no parents */
1517 show_log_first
= !!rev
->loginfo
&& !rev
->no_commit_id
;
1519 if (show_log_first
) {
1522 if (rev
->verbose_header
&& opt
->output_format
&&
1523 opt
->output_format
!= DIFF_FORMAT_NO_OUTPUT
&&
1524 !commit_format_is_empty(rev
->commit_format
))
1525 printf("%s%c", diff_line_prefix(opt
),
1526 opt
->line_termination
);
1530 copy_pathspec(&diffopts
.pathspec
, &opt
->pathspec
);
1531 diffopts
.flags
.recursive
= 1;
1532 diffopts
.flags
.allow_external
= 0;
1534 /* find set of paths that everybody touches
1538 * Diffcore transformations are bound to diff_filespec and logic
1539 * comparing two entries - i.e. they do not apply directly to combine
1542 * If some of such transformations is requested - we launch generic
1543 * path scanning, which works significantly slower compared to
1544 * simultaneous all-trees-in-one-go scan in find_paths_multitree().
1546 * TODO some of the filters could be ported to work on
1547 * combine_diff_paths - i.e. all functionality that skips paths, so in
1548 * theory, we could end up having only multitree path scanning.
1550 * NOTE please keep this semantically in sync with diffcore_std()
1552 need_generic_pathscan
= opt
->skip_stat_unmatch
||
1553 opt
->flags
.follow_renames
||
1554 opt
->break_opt
!= -1 ||
1555 opt
->detect_rename
||
1556 (opt
->pickaxe_opts
&
1557 (DIFF_PICKAXE_KINDS_MASK
& ~DIFF_PICKAXE_KIND_OBJFIND
)) ||
1560 if (need_generic_pathscan
) {
1562 * NOTE generic case also handles --stat, as it computes
1563 * diff(sha1,parent_i) for all i to do the job, specifically
1566 paths
= find_paths_generic(oid
, parents
, &diffopts
,
1567 rev
->combined_all_paths
);
1571 paths
= find_paths_multitree(oid
, parents
, &diffopts
);
1573 if (opt
->pickaxe_opts
& DIFF_PICKAXE_KIND_OBJFIND
)
1574 paths
= combined_objfind(opt
, paths
, num_parent
);
1577 * show stat against the first parent even
1578 * when doing combined diff.
1580 stat_opt
= opt
->output_format
& STAT_FORMAT_MASK
;
1582 diffopts
.output_format
= stat_opt
;
1584 diff_tree_oid(&parents
->oid
[0], oid
, "", &diffopts
);
1585 diffcore_std(&diffopts
);
1587 diffcore_order(opt
->orderfile
);
1588 diff_flush(&diffopts
);
1592 /* find out number of surviving paths */
1593 for (num_paths
= 0, p
= paths
; p
; p
= p
->next
)
1596 /* order paths according to diffcore_order */
1597 if (opt
->orderfile
&& num_paths
) {
1598 struct obj_order
*o
;
1600 ALLOC_ARRAY(o
, num_paths
);
1601 for (i
= 0, p
= paths
; p
; p
= p
->next
, i
++)
1603 order_objects(opt
->orderfile
, path_path
, o
, num_paths
);
1604 for (i
= 0; i
< num_paths
- 1; i
++) {
1606 p
->next
= o
[i
+1].obj
;
1609 p
= o
[num_paths
-1].obj
;
1617 if (opt
->output_format
& (DIFF_FORMAT_RAW
|
1619 DIFF_FORMAT_NAME_STATUS
)) {
1620 for (p
= paths
; p
; p
= p
->next
)
1621 show_raw_diff(p
, num_parent
, rev
);
1624 else if (opt
->output_format
& STAT_FORMAT_MASK
)
1626 else if (opt
->output_format
& DIFF_FORMAT_CALLBACK
)
1627 handle_combined_callback(opt
, paths
, num_parent
, num_paths
);
1629 if (opt
->output_format
& DIFF_FORMAT_PATCH
) {
1631 printf("%s%c", diff_line_prefix(opt
),
1632 opt
->line_termination
);
1633 for (p
= paths
; p
; p
= p
->next
)
1634 show_patch_diff(p
, num_parent
, 0, rev
);
1638 /* Clean things up */
1640 struct combine_diff_path
*tmp
= paths
;
1641 paths
= paths
->next
;
1642 for (i
= 0; i
< num_parent
; i
++)
1643 if (rev
->combined_all_paths
&&
1644 filename_changed(tmp
->parent
[i
].status
))
1645 strbuf_release(&tmp
->parent
[i
].path
);
1649 clear_pathspec(&diffopts
.pathspec
);
1652 void diff_tree_combined_merge(const struct commit
*commit
,
1653 struct rev_info
*rev
)
1655 struct commit_list
*parent
= get_saved_parents(rev
, commit
);
1656 struct oid_array parents
= OID_ARRAY_INIT
;
1659 oid_array_append(&parents
, &parent
->item
->object
.oid
);
1660 parent
= parent
->next
;
1662 diff_tree_combined(&commit
->object
.oid
, &parents
, rev
);
1663 oid_array_clear(&parents
);