7 #include "reflog-walk.h"
9 #include "string-list.h"
11 #include "gpg-interface.h"
12 #include "sequencer.h"
15 struct decoration name_decoration
= { "object names" };
17 enum decoration_type
{
20 DECORATION_REF_REMOTE
,
27 static char decoration_colors
[][COLOR_MAXLEN
] = {
29 GIT_COLOR_BOLD_GREEN
, /* REF_LOCAL */
30 GIT_COLOR_BOLD_RED
, /* REF_REMOTE */
31 GIT_COLOR_BOLD_YELLOW
, /* REF_TAG */
32 GIT_COLOR_BOLD_MAGENTA
, /* REF_STASH */
33 GIT_COLOR_BOLD_CYAN
, /* REF_HEAD */
34 GIT_COLOR_BOLD_BLUE
, /* GRAFTED */
37 static const char *decorate_get_color(int decorate_use_color
, enum decoration_type ix
)
39 if (want_color(decorate_use_color
))
40 return decoration_colors
[ix
];
44 static int parse_decorate_color_slot(const char *slot
)
47 * We're comparing with 'ignore-case' on
48 * (because config.c sets them all tolower),
49 * but let's match the letters in the literal
50 * string values here with how they are
51 * documented in Documentation/config.txt, for
54 * We love being consistent, don't we?
56 if (!strcasecmp(slot
, "branch"))
57 return DECORATION_REF_LOCAL
;
58 if (!strcasecmp(slot
, "remoteBranch"))
59 return DECORATION_REF_REMOTE
;
60 if (!strcasecmp(slot
, "tag"))
61 return DECORATION_REF_TAG
;
62 if (!strcasecmp(slot
, "stash"))
63 return DECORATION_REF_STASH
;
64 if (!strcasecmp(slot
, "HEAD"))
65 return DECORATION_REF_HEAD
;
69 int parse_decorate_color_config(const char *var
, const int ofs
, const char *value
)
71 int slot
= parse_decorate_color_slot(var
+ ofs
);
75 return config_error_nonbool(var
);
76 color_parse(value
, var
, decoration_colors
[slot
]);
81 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
82 * for showing the commit sha1, use the same check for --decorate
84 #define decorate_get_color_opt(o, ix) \
85 decorate_get_color((o)->use_color, ix)
87 static void add_name_decoration(enum decoration_type type
, const char *name
, struct object
*obj
)
89 int nlen
= strlen(name
);
90 struct name_decoration
*res
= xmalloc(sizeof(struct name_decoration
) + nlen
);
91 memcpy(res
->name
, name
, nlen
+ 1);
93 res
->next
= add_decoration(&name_decoration
, obj
, res
);
96 static int add_ref_decoration(const char *refname
, const unsigned char *sha1
, int flags
, void *cb_data
)
99 enum decoration_type type
= DECORATION_NONE
;
101 if (!prefixcmp(refname
, "refs/replace/")) {
102 unsigned char original_sha1
[20];
103 if (!read_replace_refs
)
105 if (get_sha1_hex(refname
+ 13, original_sha1
)) {
106 warning("invalid replace ref %s", refname
);
109 obj
= parse_object(original_sha1
);
111 add_name_decoration(DECORATION_GRAFTED
, "replaced", obj
);
115 obj
= parse_object(sha1
);
119 if (!prefixcmp(refname
, "refs/heads/"))
120 type
= DECORATION_REF_LOCAL
;
121 else if (!prefixcmp(refname
, "refs/remotes/"))
122 type
= DECORATION_REF_REMOTE
;
123 else if (!prefixcmp(refname
, "refs/tags/"))
124 type
= DECORATION_REF_TAG
;
125 else if (!strcmp(refname
, "refs/stash"))
126 type
= DECORATION_REF_STASH
;
127 else if (!strcmp(refname
, "HEAD"))
128 type
= DECORATION_REF_HEAD
;
130 if (!cb_data
|| *(int *)cb_data
== DECORATE_SHORT_REFS
)
131 refname
= prettify_refname(refname
);
132 add_name_decoration(type
, refname
, obj
);
133 while (obj
->type
== OBJ_TAG
) {
134 obj
= ((struct tag
*)obj
)->tagged
;
138 parse_object(obj
->sha1
);
139 add_name_decoration(DECORATION_REF_TAG
, refname
, obj
);
144 static int add_graft_decoration(const struct commit_graft
*graft
, void *cb_data
)
146 struct commit
*commit
= lookup_commit(graft
->sha1
);
149 add_name_decoration(DECORATION_GRAFTED
, "grafted", &commit
->object
);
153 void load_ref_decorations(int flags
)
158 for_each_ref(add_ref_decoration
, &flags
);
159 head_ref(add_ref_decoration
, &flags
);
160 for_each_commit_graft(add_graft_decoration
, NULL
);
164 static void show_parents(struct commit
*commit
, int abbrev
)
166 struct commit_list
*p
;
167 for (p
= commit
->parents
; p
; p
= p
->next
) {
168 struct commit
*parent
= p
->item
;
169 printf(" %s", find_unique_abbrev(parent
->object
.sha1
, abbrev
));
173 static void show_children(struct rev_info
*opt
, struct commit
*commit
, int abbrev
)
175 struct commit_list
*p
= lookup_decoration(&opt
->children
, &commit
->object
);
176 for ( ; p
; p
= p
->next
) {
177 printf(" %s", find_unique_abbrev(p
->item
->object
.sha1
, abbrev
));
182 * The caller makes sure there is no funny color before
183 * calling. format_decorations makes sure the same after return.
185 void format_decorations(struct strbuf
*sb
,
186 const struct commit
*commit
,
190 struct name_decoration
*decoration
;
191 const char *color_commit
=
192 diff_get_color(use_color
, DIFF_COMMIT
);
193 const char *color_reset
=
194 decorate_get_color(use_color
, DECORATION_NONE
);
196 decoration
= lookup_decoration(&name_decoration
, &commit
->object
);
201 strbuf_addstr(sb
, color_commit
);
202 strbuf_addstr(sb
, prefix
);
203 strbuf_addstr(sb
, color_reset
);
204 strbuf_addstr(sb
, decorate_get_color(use_color
, decoration
->type
));
205 if (decoration
->type
== DECORATION_REF_TAG
)
206 strbuf_addstr(sb
, "tag: ");
207 strbuf_addstr(sb
, decoration
->name
);
208 strbuf_addstr(sb
, color_reset
);
210 decoration
= decoration
->next
;
212 strbuf_addstr(sb
, color_commit
);
213 strbuf_addch(sb
, ')');
214 strbuf_addstr(sb
, color_reset
);
217 void show_decorations(struct rev_info
*opt
, struct commit
*commit
)
219 struct strbuf sb
= STRBUF_INIT
;
221 if (opt
->show_source
&& commit
->util
)
222 printf("\t%s", (char *) commit
->util
);
223 if (!opt
->show_decorations
)
225 format_decorations(&sb
, commit
, opt
->diffopt
.use_color
);
226 fputs(sb
.buf
, stdout
);
230 static unsigned int digits_in_number(unsigned int number
)
232 unsigned int i
= 10, result
= 1;
233 while (i
<= number
) {
240 void fmt_output_subject(struct strbuf
*filename
,
242 struct rev_info
*info
)
244 const char *suffix
= info
->patch_suffix
;
246 int start_len
= filename
->len
;
247 int max_len
= start_len
+ FORMAT_PATCH_NAME_MAX
- (strlen(suffix
) + 1);
249 if (0 < info
->reroll_count
)
250 strbuf_addf(filename
, "v%d-", info
->reroll_count
);
251 strbuf_addf(filename
, "%04d-%s", nr
, subject
);
253 if (max_len
< filename
->len
)
254 strbuf_setlen(filename
, max_len
);
255 strbuf_addstr(filename
, suffix
);
258 void fmt_output_commit(struct strbuf
*filename
,
259 struct commit
*commit
,
260 struct rev_info
*info
)
262 struct pretty_print_context ctx
= {0};
263 struct strbuf subject
= STRBUF_INIT
;
265 format_commit_message(commit
, "%f", &subject
, &ctx
);
266 fmt_output_subject(filename
, subject
.buf
, info
);
267 strbuf_release(&subject
);
270 void log_write_email_headers(struct rev_info
*opt
, struct commit
*commit
,
271 const char **subject_p
,
272 const char **extra_headers_p
,
273 int *need_8bit_cte_p
)
275 const char *subject
= NULL
;
276 const char *extra_headers
= opt
->extra_headers
;
277 const char *name
= sha1_to_hex(commit
->object
.sha1
);
279 *need_8bit_cte_p
= 0; /* unknown */
280 if (opt
->total
> 0) {
281 static char buffer
[64];
282 snprintf(buffer
, sizeof(buffer
),
283 "Subject: [%s%s%0*d/%d] ",
285 *opt
->subject_prefix
? " " : "",
286 digits_in_number(opt
->total
),
287 opt
->nr
, opt
->total
);
289 } else if (opt
->total
== 0 && opt
->subject_prefix
&& *opt
->subject_prefix
) {
290 static char buffer
[256];
291 snprintf(buffer
, sizeof(buffer
),
293 opt
->subject_prefix
);
296 subject
= "Subject: ";
299 printf("From %s Mon Sep 17 00:00:00 2001\n", name
);
300 graph_show_oneline(opt
->graph
);
301 if (opt
->message_id
) {
302 printf("Message-Id: <%s>\n", opt
->message_id
);
303 graph_show_oneline(opt
->graph
);
305 if (opt
->ref_message_ids
&& opt
->ref_message_ids
->nr
> 0) {
307 n
= opt
->ref_message_ids
->nr
;
308 printf("In-Reply-To: <%s>\n", opt
->ref_message_ids
->items
[n
-1].string
);
309 for (i
= 0; i
< n
; i
++)
310 printf("%s<%s>\n", (i
> 0 ? "\t" : "References: "),
311 opt
->ref_message_ids
->items
[i
].string
);
312 graph_show_oneline(opt
->graph
);
314 if (opt
->mime_boundary
) {
315 static char subject_buffer
[1024];
316 static char buffer
[1024];
317 struct strbuf filename
= STRBUF_INIT
;
318 *need_8bit_cte_p
= -1; /* NEVER */
319 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
321 "MIME-Version: 1.0\n"
322 "Content-Type: multipart/mixed;"
323 " boundary=\"%s%s\"\n"
325 "This is a multi-part message in MIME "
328 "Content-Type: text/plain; "
329 "charset=UTF-8; format=fixed\n"
330 "Content-Transfer-Encoding: 8bit\n\n",
331 extra_headers
? extra_headers
: "",
332 mime_boundary_leader
, opt
->mime_boundary
,
333 mime_boundary_leader
, opt
->mime_boundary
);
334 extra_headers
= subject_buffer
;
336 if (opt
->numbered_files
)
337 strbuf_addf(&filename
, "%d", opt
->nr
);
339 fmt_output_commit(&filename
, commit
, opt
);
340 snprintf(buffer
, sizeof(buffer
) - 1,
342 "Content-Type: text/x-patch;"
344 "Content-Transfer-Encoding: 8bit\n"
345 "Content-Disposition: %s;"
346 " filename=\"%s\"\n\n",
347 mime_boundary_leader
, opt
->mime_boundary
,
349 opt
->no_inline
? "attachment" : "inline",
351 opt
->diffopt
.stat_sep
= buffer
;
352 strbuf_release(&filename
);
354 *subject_p
= subject
;
355 *extra_headers_p
= extra_headers
;
358 static void show_sig_lines(struct rev_info
*opt
, int status
, const char *bol
)
360 const char *color
, *reset
, *eol
;
362 color
= diff_get_color_opt(&opt
->diffopt
,
363 status
? DIFF_WHITESPACE
: DIFF_FRAGINFO
);
364 reset
= diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
);
366 eol
= strchrnul(bol
, '\n');
367 printf("%s%.*s%s%s", color
, (int)(eol
- bol
), bol
, reset
,
369 bol
= (*eol
) ? (eol
+ 1) : eol
;
373 static void show_signature(struct rev_info
*opt
, struct commit
*commit
)
375 struct strbuf payload
= STRBUF_INIT
;
376 struct strbuf signature
= STRBUF_INIT
;
377 struct strbuf gpg_output
= STRBUF_INIT
;
380 if (parse_signed_commit(commit
->object
.sha1
, &payload
, &signature
) <= 0)
383 status
= verify_signed_buffer(payload
.buf
, payload
.len
,
384 signature
.buf
, signature
.len
,
386 if (status
&& !gpg_output
.len
)
387 strbuf_addstr(&gpg_output
, "No signature\n");
389 show_sig_lines(opt
, status
, gpg_output
.buf
);
392 strbuf_release(&gpg_output
);
393 strbuf_release(&payload
);
394 strbuf_release(&signature
);
397 static int which_parent(const unsigned char *sha1
, const struct commit
*commit
)
400 const struct commit_list
*parent
;
402 for (nth
= 0, parent
= commit
->parents
; parent
; parent
= parent
->next
) {
403 if (!hashcmp(parent
->item
->object
.sha1
, sha1
))
410 static int is_common_merge(const struct commit
*commit
)
412 return (commit
->parents
413 && commit
->parents
->next
414 && !commit
->parents
->next
->next
);
417 static void show_one_mergetag(struct rev_info
*opt
,
418 struct commit_extra_header
*extra
,
419 struct commit
*commit
)
421 unsigned char sha1
[20];
423 struct strbuf verify_message
;
425 size_t payload_size
, gpg_message_offset
;
427 hash_sha1_file(extra
->value
, extra
->len
, typename(OBJ_TAG
), sha1
);
428 tag
= lookup_tag(sha1
);
430 return; /* error message already given */
432 strbuf_init(&verify_message
, 256);
433 if (parse_tag_buffer(tag
, extra
->value
, extra
->len
))
434 strbuf_addstr(&verify_message
, "malformed mergetag\n");
435 else if (is_common_merge(commit
) &&
436 !hashcmp(tag
->tagged
->sha1
,
437 commit
->parents
->next
->item
->object
.sha1
))
438 strbuf_addf(&verify_message
,
439 "merged tag '%s'\n", tag
->tag
);
440 else if ((nth
= which_parent(tag
->tagged
->sha1
, commit
)) < 0)
441 strbuf_addf(&verify_message
, "tag %s names a non-parent %s\n",
442 tag
->tag
, tag
->tagged
->sha1
);
444 strbuf_addf(&verify_message
,
445 "parent #%d, tagged '%s'\n", nth
+ 1, tag
->tag
);
446 gpg_message_offset
= verify_message
.len
;
448 payload_size
= parse_signature(extra
->value
, extra
->len
);
450 if (extra
->len
> payload_size
)
451 if (verify_signed_buffer(extra
->value
, payload_size
,
452 extra
->value
+ payload_size
,
453 extra
->len
- payload_size
,
454 &verify_message
, NULL
)) {
455 if (verify_message
.len
<= gpg_message_offset
)
456 strbuf_addstr(&verify_message
, "No signature\n");
461 show_sig_lines(opt
, status
, verify_message
.buf
);
462 strbuf_release(&verify_message
);
465 static void show_mergetag(struct rev_info
*opt
, struct commit
*commit
)
467 struct commit_extra_header
*extra
, *to_free
;
469 to_free
= read_commit_extra_headers(commit
, NULL
);
470 for (extra
= to_free
; extra
; extra
= extra
->next
) {
471 if (strcmp(extra
->key
, "mergetag"))
472 continue; /* not a merge tag */
473 show_one_mergetag(opt
, extra
, commit
);
475 free_commit_extra_headers(to_free
);
478 void show_log(struct rev_info
*opt
)
480 struct strbuf msgbuf
= STRBUF_INIT
;
481 struct log_info
*log
= opt
->loginfo
;
482 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
483 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
484 const char *extra_headers
= opt
->extra_headers
;
485 struct pretty_print_context ctx
= {0};
488 if (!opt
->verbose_header
) {
489 graph_show_commit(opt
->graph
);
492 put_revision_mark(opt
, commit
);
493 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
494 if (opt
->print_parents
)
495 show_parents(commit
, abbrev_commit
);
496 if (opt
->children
.name
)
497 show_children(opt
, commit
, abbrev_commit
);
498 show_decorations(opt
, commit
);
499 if (opt
->graph
&& !graph_is_commit_finished(opt
->graph
)) {
501 graph_show_remainder(opt
->graph
);
503 putchar(opt
->diffopt
.line_termination
);
508 * If use_terminator is set, we already handled any record termination
509 * at the end of the last record.
510 * Otherwise, add a diffopt.line_termination character before all
511 * entries but the first. (IOW, as a separator between entries)
513 if (opt
->shown_one
&& !opt
->use_terminator
) {
515 * If entries are separated by a newline, the output
516 * should look human-readable. If the last entry ended
517 * with a newline, print the graph output before this
518 * newline. Otherwise it will end up as a completely blank
519 * line and will look like a gap in the graph.
521 * If the entry separator is not a newline, the output is
522 * primarily intended for programmatic consumption, and we
523 * never want the extra graph output before the entry
526 if (opt
->diffopt
.line_termination
== '\n' &&
527 !opt
->missing_newline
)
528 graph_show_padding(opt
->graph
);
529 putchar(opt
->diffopt
.line_termination
);
534 * If the history graph was requested,
535 * print the graph, up to this commit's line
537 graph_show_commit(opt
->graph
);
540 * Print header line of header..
543 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
544 log_write_email_headers(opt
, commit
, &ctx
.subject
, &extra_headers
,
546 } else if (opt
->commit_format
!= CMIT_FMT_USERFORMAT
) {
547 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_COMMIT
), stdout
);
548 if (opt
->commit_format
!= CMIT_FMT_ONELINE
)
549 fputs("commit ", stdout
);
552 put_revision_mark(opt
, commit
);
553 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
),
555 if (opt
->print_parents
)
556 show_parents(commit
, abbrev_commit
);
557 if (opt
->children
.name
)
558 show_children(opt
, commit
, abbrev_commit
);
561 find_unique_abbrev(parent
->object
.sha1
,
563 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
), stdout
);
564 show_decorations(opt
, commit
);
565 if (opt
->commit_format
== CMIT_FMT_ONELINE
) {
569 graph_show_oneline(opt
->graph
);
571 if (opt
->reflog_info
) {
573 * setup_revisions() ensures that opt->reflog_info
574 * and opt->graph cannot both be set,
575 * so we don't need to worry about printing the
578 show_reflog_message(opt
->reflog_info
,
579 opt
->commit_format
== CMIT_FMT_ONELINE
,
581 opt
->date_mode_explicit
);
582 if (opt
->commit_format
== CMIT_FMT_ONELINE
)
587 if (opt
->show_signature
) {
588 show_signature(opt
, commit
);
589 show_mergetag(opt
, commit
);
595 if (opt
->show_notes
) {
597 struct strbuf notebuf
= STRBUF_INIT
;
599 raw
= (opt
->commit_format
== CMIT_FMT_USERFORMAT
);
600 format_display_notes(commit
->object
.sha1
, ¬ebuf
,
601 get_log_output_encoding(), raw
);
602 ctx
.notes_message
= notebuf
.len
603 ? strbuf_detach(¬ebuf
, NULL
)
608 * And then the pretty-printed message itself
610 if (ctx
.need_8bit_cte
>= 0 && opt
->add_signoff
)
612 has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
613 getenv("GIT_COMMITTER_EMAIL")));
614 ctx
.date_mode
= opt
->date_mode
;
615 ctx
.date_mode_explicit
= opt
->date_mode_explicit
;
616 ctx
.abbrev
= opt
->diffopt
.abbrev
;
617 ctx
.after_subject
= extra_headers
;
618 ctx
.preserve_subject
= opt
->preserve_subject
;
619 ctx
.reflog_info
= opt
->reflog_info
;
620 ctx
.fmt
= opt
->commit_format
;
621 ctx
.mailmap
= opt
->mailmap
;
622 ctx
.color
= opt
->diffopt
.use_color
;
623 ctx
.output_encoding
= get_log_output_encoding();
624 if (opt
->from_ident
.mail_begin
&& opt
->from_ident
.name_begin
)
625 ctx
.from_ident
= &opt
->from_ident
;
626 pretty_print_commit(&ctx
, commit
, &msgbuf
);
628 if (opt
->add_signoff
)
629 append_signoff(&msgbuf
, 0, APPEND_SIGNOFF_DEDUP
);
631 if ((ctx
.fmt
!= CMIT_FMT_USERFORMAT
) &&
632 ctx
.notes_message
&& *ctx
.notes_message
) {
633 if (ctx
.fmt
== CMIT_FMT_EMAIL
) {
634 strbuf_addstr(&msgbuf
, "---\n");
635 opt
->shown_dashes
= 1;
637 strbuf_addstr(&msgbuf
, ctx
.notes_message
);
640 if (opt
->show_log_size
) {
641 printf("log size %i\n", (int)msgbuf
.len
);
642 graph_show_oneline(opt
->graph
);
646 * Set opt->missing_newline if msgbuf doesn't
647 * end in a newline (including if it is empty)
649 if (!msgbuf
.len
|| msgbuf
.buf
[msgbuf
.len
- 1] != '\n')
650 opt
->missing_newline
= 1;
652 opt
->missing_newline
= 0;
655 graph_show_commit_msg(opt
->graph
, &msgbuf
);
657 fwrite(msgbuf
.buf
, sizeof(char), msgbuf
.len
, stdout
);
658 if (opt
->use_terminator
) {
659 if (!opt
->missing_newline
)
660 graph_show_padding(opt
->graph
);
661 putchar(opt
->diffopt
.line_termination
);
664 strbuf_release(&msgbuf
);
665 free(ctx
.notes_message
);
668 int log_tree_diff_flush(struct rev_info
*opt
)
670 opt
->shown_dashes
= 0;
671 diffcore_std(&opt
->diffopt
);
673 if (diff_queue_is_empty()) {
674 int saved_fmt
= opt
->diffopt
.output_format
;
675 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
676 diff_flush(&opt
->diffopt
);
677 opt
->diffopt
.output_format
= saved_fmt
;
681 if (opt
->loginfo
&& !opt
->no_commit_id
) {
683 if ((opt
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
) &&
684 opt
->verbose_header
&&
685 opt
->commit_format
!= CMIT_FMT_ONELINE
) {
687 * When showing a verbose header (i.e. log message),
688 * and not in --pretty=oneline format, we would want
689 * an extra newline between the end of log and the
690 * diff/diffstat output for readability.
692 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
693 if (opt
->diffopt
.output_prefix
) {
694 struct strbuf
*msg
= NULL
;
695 msg
= opt
->diffopt
.output_prefix(&opt
->diffopt
,
696 opt
->diffopt
.output_prefix_data
);
697 fwrite(msg
->buf
, msg
->len
, 1, stdout
);
701 * We may have shown three-dashes line early
702 * between notes and the log message, in which
703 * case we only want a blank line after the
704 * notes without (an extra) three-dashes line.
705 * Otherwise, we show the three-dashes line if
706 * we are showing the patch with diffstat, but
707 * in that case, there is no extra blank line
708 * after the three-dashes line.
710 if (!opt
->shown_dashes
&&
711 (pch
& opt
->diffopt
.output_format
) == pch
)
716 diff_flush(&opt
->diffopt
);
720 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
722 diff_tree_combined_merge(commit
, opt
->dense_combined_merges
, opt
);
723 return !opt
->loginfo
;
727 * Show the diff of a commit.
729 * Return true if we printed any log info messages
731 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
734 struct commit_list
*parents
;
735 unsigned const char *sha1
;
737 if (!opt
->diff
&& !DIFF_OPT_TST(&opt
->diffopt
, EXIT_WITH_STATUS
))
740 parse_commit(commit
);
741 sha1
= commit
->tree
->object
.sha1
;
744 parents
= get_saved_parents(opt
, commit
);
746 if (opt
->show_root_diff
) {
747 diff_root_tree_sha1(sha1
, "", &opt
->diffopt
);
748 log_tree_diff_flush(opt
);
750 return !opt
->loginfo
;
753 /* More than one parent? */
754 if (parents
&& parents
->next
) {
755 if (opt
->ignore_merges
)
757 else if (opt
->combine_merges
)
758 return do_diff_combined(opt
, commit
);
759 else if (opt
->first_parent_only
) {
761 * Generate merge log entry only for the first
762 * parent, showing summary diff of the others
765 parse_commit(parents
->item
);
766 diff_tree_sha1(parents
->item
->tree
->object
.sha1
,
767 sha1
, "", &opt
->diffopt
);
768 log_tree_diff_flush(opt
);
769 return !opt
->loginfo
;
772 /* If we show individual diffs, show the parent info */
773 log
->parent
= parents
->item
;
778 struct commit
*parent
= parents
->item
;
780 parse_commit(parent
);
781 diff_tree_sha1(parent
->tree
->object
.sha1
,
782 sha1
, "", &opt
->diffopt
);
783 log_tree_diff_flush(opt
);
785 showed_log
|= !opt
->loginfo
;
787 /* Set up the log info for the next parent, if any.. */
788 parents
= parents
->next
;
791 log
->parent
= parents
->item
;
797 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
806 if (opt
->line_level_traverse
)
807 return line_log_print(opt
, commit
);
809 shown
= log_tree_diff(opt
, commit
, &log
);
810 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
816 maybe_flush_or_die(stdout
, "stdout");