7 #include "reflog-walk.h"
9 #include "string-list.h"
11 #include "gpg-interface.h"
13 struct decoration name_decoration
= { "object names" };
15 enum decoration_type
{
18 DECORATION_REF_REMOTE
,
25 static char decoration_colors
[][COLOR_MAXLEN
] = {
27 GIT_COLOR_BOLD_GREEN
, /* REF_LOCAL */
28 GIT_COLOR_BOLD_RED
, /* REF_REMOTE */
29 GIT_COLOR_BOLD_YELLOW
, /* REF_TAG */
30 GIT_COLOR_BOLD_MAGENTA
, /* REF_STASH */
31 GIT_COLOR_BOLD_CYAN
, /* REF_HEAD */
32 GIT_COLOR_BOLD_BLUE
, /* GRAFTED */
35 static const char *decorate_get_color(int decorate_use_color
, enum decoration_type ix
)
37 if (want_color(decorate_use_color
))
38 return decoration_colors
[ix
];
42 static int parse_decorate_color_slot(const char *slot
)
45 * We're comparing with 'ignore-case' on
46 * (because config.c sets them all tolower),
47 * but let's match the letters in the literal
48 * string values here with how they are
49 * documented in Documentation/config.txt, for
52 * We love being consistent, don't we?
54 if (!strcasecmp(slot
, "branch"))
55 return DECORATION_REF_LOCAL
;
56 if (!strcasecmp(slot
, "remoteBranch"))
57 return DECORATION_REF_REMOTE
;
58 if (!strcasecmp(slot
, "tag"))
59 return DECORATION_REF_TAG
;
60 if (!strcasecmp(slot
, "stash"))
61 return DECORATION_REF_STASH
;
62 if (!strcasecmp(slot
, "HEAD"))
63 return DECORATION_REF_HEAD
;
67 int parse_decorate_color_config(const char *var
, const int ofs
, const char *value
)
69 int slot
= parse_decorate_color_slot(var
+ ofs
);
73 return config_error_nonbool(var
);
74 color_parse(value
, var
, decoration_colors
[slot
]);
79 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
80 * for showing the commit sha1, use the same check for --decorate
82 #define decorate_get_color_opt(o, ix) \
83 decorate_get_color((o)->use_color, ix)
85 static void add_name_decoration(enum decoration_type type
, const char *name
, struct object
*obj
)
87 int nlen
= strlen(name
);
88 struct name_decoration
*res
= xmalloc(sizeof(struct name_decoration
) + nlen
);
89 memcpy(res
->name
, name
, nlen
+ 1);
91 res
->next
= add_decoration(&name_decoration
, obj
, res
);
94 static int add_ref_decoration(const char *refname
, const unsigned char *sha1
, int flags
, void *cb_data
)
97 enum decoration_type type
= DECORATION_NONE
;
99 if (!prefixcmp(refname
, "refs/replace/")) {
100 unsigned char original_sha1
[20];
101 if (!read_replace_refs
)
103 if (get_sha1_hex(refname
+ 13, original_sha1
)) {
104 warning("invalid replace ref %s", refname
);
107 obj
= parse_object(original_sha1
);
109 add_name_decoration(DECORATION_GRAFTED
, "replaced", obj
);
113 obj
= parse_object(sha1
);
117 if (!prefixcmp(refname
, "refs/heads/"))
118 type
= DECORATION_REF_LOCAL
;
119 else if (!prefixcmp(refname
, "refs/remotes/"))
120 type
= DECORATION_REF_REMOTE
;
121 else if (!prefixcmp(refname
, "refs/tags/"))
122 type
= DECORATION_REF_TAG
;
123 else if (!strcmp(refname
, "refs/stash"))
124 type
= DECORATION_REF_STASH
;
125 else if (!strcmp(refname
, "HEAD"))
126 type
= DECORATION_REF_HEAD
;
128 if (!cb_data
|| *(int *)cb_data
== DECORATE_SHORT_REFS
)
129 refname
= prettify_refname(refname
);
130 add_name_decoration(type
, refname
, obj
);
131 while (obj
->type
== OBJ_TAG
) {
132 obj
= ((struct tag
*)obj
)->tagged
;
135 add_name_decoration(DECORATION_REF_TAG
, refname
, obj
);
140 static int add_graft_decoration(const struct commit_graft
*graft
, void *cb_data
)
142 struct commit
*commit
= lookup_commit(graft
->sha1
);
145 add_name_decoration(DECORATION_GRAFTED
, "grafted", &commit
->object
);
149 void load_ref_decorations(int flags
)
154 for_each_ref(add_ref_decoration
, &flags
);
155 head_ref(add_ref_decoration
, &flags
);
156 for_each_commit_graft(add_graft_decoration
, NULL
);
160 static void show_parents(struct commit
*commit
, int abbrev
)
162 struct commit_list
*p
;
163 for (p
= commit
->parents
; p
; p
= p
->next
) {
164 struct commit
*parent
= p
->item
;
165 printf(" %s", find_unique_abbrev(parent
->object
.sha1
, abbrev
));
169 static void show_children(struct rev_info
*opt
, struct commit
*commit
, int abbrev
)
171 struct commit_list
*p
= lookup_decoration(&opt
->children
, &commit
->object
);
172 for ( ; p
; p
= p
->next
) {
173 printf(" %s", find_unique_abbrev(p
->item
->object
.sha1
, abbrev
));
177 void show_decorations(struct rev_info
*opt
, struct commit
*commit
)
180 struct name_decoration
*decoration
;
181 const char *color_commit
=
182 diff_get_color_opt(&opt
->diffopt
, DIFF_COMMIT
);
183 const char *color_reset
=
184 decorate_get_color_opt(&opt
->diffopt
, DECORATION_NONE
);
186 if (opt
->show_source
&& commit
->util
)
187 printf("\t%s", (char *) commit
->util
);
188 if (!opt
->show_decorations
)
190 decoration
= lookup_decoration(&name_decoration
, &commit
->object
);
195 printf("%s", prefix
);
196 fputs(decorate_get_color_opt(&opt
->diffopt
, decoration
->type
),
198 if (decoration
->type
== DECORATION_REF_TAG
)
199 fputs("tag: ", stdout
);
200 printf("%s", decoration
->name
);
201 fputs(color_reset
, stdout
);
202 fputs(color_commit
, stdout
);
204 decoration
= decoration
->next
;
210 * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
211 * Signed-off-by: and Acked-by: lines.
213 static int detect_any_signoff(char *letter
, int size
)
222 while (letter
<= --cp
&& *cp
== '\n')
225 while (letter
<= cp
) {
244 if (('A' <= ch
&& ch
<= 'Z') ||
245 ('a' <= ch
&& ch
<= 'z') ||
250 /* no empty last line doesn't match */
253 return seen_head
&& seen_name
;
256 static void append_signoff(struct strbuf
*sb
, const char *signoff
)
258 static const char signed_off_by
[] = "Signed-off-by: ";
259 size_t signoff_len
= strlen(signoff
);
265 /* First see if we already have the sign-off by the signer */
266 while ((cp
= strstr(cp
, signed_off_by
))) {
270 cp
+= strlen(signed_off_by
);
271 if (cp
+ signoff_len
>= sb
->buf
+ sb
->len
)
273 if (strncmp(cp
, signoff
, signoff_len
))
275 if (!isspace(cp
[signoff_len
]))
277 /* we already have him */
282 has_signoff
= detect_any_signoff(sb
->buf
, sb
->len
);
285 strbuf_addch(sb
, '\n');
287 strbuf_addstr(sb
, signed_off_by
);
288 strbuf_add(sb
, signoff
, signoff_len
);
289 strbuf_addch(sb
, '\n');
292 static unsigned int digits_in_number(unsigned int number
)
294 unsigned int i
= 10, result
= 1;
295 while (i
<= number
) {
302 void fmt_output_subject(struct strbuf
*filename
,
304 struct rev_info
*info
)
306 const char *suffix
= info
->patch_suffix
;
308 int start_len
= filename
->len
;
309 int max_len
= start_len
+ FORMAT_PATCH_NAME_MAX
- (strlen(suffix
) + 1);
311 if (0 < info
->reroll_count
)
312 strbuf_addf(filename
, "v%d-", info
->reroll_count
);
313 strbuf_addf(filename
, "%04d-%s", nr
, subject
);
315 if (max_len
< filename
->len
)
316 strbuf_setlen(filename
, max_len
);
317 strbuf_addstr(filename
, suffix
);
320 void fmt_output_commit(struct strbuf
*filename
,
321 struct commit
*commit
,
322 struct rev_info
*info
)
324 struct pretty_print_context ctx
= {0};
325 struct strbuf subject
= STRBUF_INIT
;
327 format_commit_message(commit
, "%f", &subject
, &ctx
);
328 fmt_output_subject(filename
, subject
.buf
, info
);
329 strbuf_release(&subject
);
332 void log_write_email_headers(struct rev_info
*opt
, struct commit
*commit
,
333 const char **subject_p
,
334 const char **extra_headers_p
,
335 int *need_8bit_cte_p
)
337 const char *subject
= NULL
;
338 const char *extra_headers
= opt
->extra_headers
;
339 const char *name
= sha1_to_hex(commit
->object
.sha1
);
341 *need_8bit_cte_p
= 0; /* unknown */
342 if (opt
->total
> 0) {
343 static char buffer
[64];
344 snprintf(buffer
, sizeof(buffer
),
345 "Subject: [%s%s%0*d/%d] ",
347 *opt
->subject_prefix
? " " : "",
348 digits_in_number(opt
->total
),
349 opt
->nr
, opt
->total
);
351 } else if (opt
->total
== 0 && opt
->subject_prefix
&& *opt
->subject_prefix
) {
352 static char buffer
[256];
353 snprintf(buffer
, sizeof(buffer
),
355 opt
->subject_prefix
);
358 subject
= "Subject: ";
361 printf("From %s Mon Sep 17 00:00:00 2001\n", name
);
362 graph_show_oneline(opt
->graph
);
363 if (opt
->message_id
) {
364 printf("Message-Id: <%s>\n", opt
->message_id
);
365 graph_show_oneline(opt
->graph
);
367 if (opt
->ref_message_ids
&& opt
->ref_message_ids
->nr
> 0) {
369 n
= opt
->ref_message_ids
->nr
;
370 printf("In-Reply-To: <%s>\n", opt
->ref_message_ids
->items
[n
-1].string
);
371 for (i
= 0; i
< n
; i
++)
372 printf("%s<%s>\n", (i
> 0 ? "\t" : "References: "),
373 opt
->ref_message_ids
->items
[i
].string
);
374 graph_show_oneline(opt
->graph
);
376 if (opt
->mime_boundary
) {
377 static char subject_buffer
[1024];
378 static char buffer
[1024];
379 struct strbuf filename
= STRBUF_INIT
;
380 *need_8bit_cte_p
= -1; /* NEVER */
381 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
383 "MIME-Version: 1.0\n"
384 "Content-Type: multipart/mixed;"
385 " boundary=\"%s%s\"\n"
387 "This is a multi-part message in MIME "
390 "Content-Type: text/plain; "
391 "charset=UTF-8; format=fixed\n"
392 "Content-Transfer-Encoding: 8bit\n\n",
393 extra_headers
? extra_headers
: "",
394 mime_boundary_leader
, opt
->mime_boundary
,
395 mime_boundary_leader
, opt
->mime_boundary
);
396 extra_headers
= subject_buffer
;
398 if (opt
->numbered_files
)
399 strbuf_addf(&filename
, "%d", opt
->nr
);
401 fmt_output_commit(&filename
, commit
, opt
);
402 snprintf(buffer
, sizeof(buffer
) - 1,
404 "Content-Type: text/x-patch;"
406 "Content-Transfer-Encoding: 8bit\n"
407 "Content-Disposition: %s;"
408 " filename=\"%s\"\n\n",
409 mime_boundary_leader
, opt
->mime_boundary
,
411 opt
->no_inline
? "attachment" : "inline",
413 opt
->diffopt
.stat_sep
= buffer
;
414 strbuf_release(&filename
);
416 *subject_p
= subject
;
417 *extra_headers_p
= extra_headers
;
420 static void show_sig_lines(struct rev_info
*opt
, int status
, const char *bol
)
422 const char *color
, *reset
, *eol
;
424 color
= diff_get_color_opt(&opt
->diffopt
,
425 status
? DIFF_WHITESPACE
: DIFF_FRAGINFO
);
426 reset
= diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
);
428 eol
= strchrnul(bol
, '\n');
429 printf("%s%.*s%s%s", color
, (int)(eol
- bol
), bol
, reset
,
431 bol
= (*eol
) ? (eol
+ 1) : eol
;
435 static void show_signature(struct rev_info
*opt
, struct commit
*commit
)
437 struct strbuf payload
= STRBUF_INIT
;
438 struct strbuf signature
= STRBUF_INIT
;
439 struct strbuf gpg_output
= STRBUF_INIT
;
442 if (parse_signed_commit(commit
->object
.sha1
, &payload
, &signature
) <= 0)
445 status
= verify_signed_buffer(payload
.buf
, payload
.len
,
446 signature
.buf
, signature
.len
,
448 if (status
&& !gpg_output
.len
)
449 strbuf_addstr(&gpg_output
, "No signature\n");
451 show_sig_lines(opt
, status
, gpg_output
.buf
);
454 strbuf_release(&gpg_output
);
455 strbuf_release(&payload
);
456 strbuf_release(&signature
);
459 static int which_parent(const unsigned char *sha1
, const struct commit
*commit
)
462 const struct commit_list
*parent
;
464 for (nth
= 0, parent
= commit
->parents
; parent
; parent
= parent
->next
) {
465 if (!hashcmp(parent
->item
->object
.sha1
, sha1
))
472 static int is_common_merge(const struct commit
*commit
)
474 return (commit
->parents
475 && commit
->parents
->next
476 && !commit
->parents
->next
->next
);
479 static void show_one_mergetag(struct rev_info
*opt
,
480 struct commit_extra_header
*extra
,
481 struct commit
*commit
)
483 unsigned char sha1
[20];
485 struct strbuf verify_message
;
487 size_t payload_size
, gpg_message_offset
;
489 hash_sha1_file(extra
->value
, extra
->len
, typename(OBJ_TAG
), sha1
);
490 tag
= lookup_tag(sha1
);
492 return; /* error message already given */
494 strbuf_init(&verify_message
, 256);
495 if (parse_tag_buffer(tag
, extra
->value
, extra
->len
))
496 strbuf_addstr(&verify_message
, "malformed mergetag\n");
497 else if (is_common_merge(commit
) &&
498 !hashcmp(tag
->tagged
->sha1
,
499 commit
->parents
->next
->item
->object
.sha1
))
500 strbuf_addf(&verify_message
,
501 "merged tag '%s'\n", tag
->tag
);
502 else if ((nth
= which_parent(tag
->tagged
->sha1
, commit
)) < 0)
503 strbuf_addf(&verify_message
, "tag %s names a non-parent %s\n",
504 tag
->tag
, tag
->tagged
->sha1
);
506 strbuf_addf(&verify_message
,
507 "parent #%d, tagged '%s'\n", nth
+ 1, tag
->tag
);
508 gpg_message_offset
= verify_message
.len
;
510 payload_size
= parse_signature(extra
->value
, extra
->len
);
511 if ((extra
->len
<= payload_size
) ||
512 (verify_signed_buffer(extra
->value
, payload_size
,
513 extra
->value
+ payload_size
,
514 extra
->len
- payload_size
,
516 verify_message
.len
<= gpg_message_offset
)) {
517 strbuf_addstr(&verify_message
, "No signature\n");
520 else if (strstr(verify_message
.buf
+ gpg_message_offset
,
521 ": Good signature from "))
526 show_sig_lines(opt
, status
, verify_message
.buf
);
527 strbuf_release(&verify_message
);
530 static void show_mergetag(struct rev_info
*opt
, struct commit
*commit
)
532 struct commit_extra_header
*extra
, *to_free
;
534 to_free
= read_commit_extra_headers(commit
, NULL
);
535 for (extra
= to_free
; extra
; extra
= extra
->next
) {
536 if (strcmp(extra
->key
, "mergetag"))
537 continue; /* not a merge tag */
538 show_one_mergetag(opt
, extra
, commit
);
540 free_commit_extra_headers(to_free
);
543 void show_log(struct rev_info
*opt
)
545 struct strbuf msgbuf
= STRBUF_INIT
;
546 struct log_info
*log
= opt
->loginfo
;
547 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
548 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
549 const char *extra_headers
= opt
->extra_headers
;
550 struct pretty_print_context ctx
= {0};
553 if (!opt
->verbose_header
) {
554 graph_show_commit(opt
->graph
);
557 put_revision_mark(opt
, commit
);
558 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
559 if (opt
->print_parents
)
560 show_parents(commit
, abbrev_commit
);
561 if (opt
->children
.name
)
562 show_children(opt
, commit
, abbrev_commit
);
563 show_decorations(opt
, commit
);
564 if (opt
->graph
&& !graph_is_commit_finished(opt
->graph
)) {
566 graph_show_remainder(opt
->graph
);
568 putchar(opt
->diffopt
.line_termination
);
573 * If use_terminator is set, we already handled any record termination
574 * at the end of the last record.
575 * Otherwise, add a diffopt.line_termination character before all
576 * entries but the first. (IOW, as a separator between entries)
578 if (opt
->shown_one
&& !opt
->use_terminator
) {
580 * If entries are separated by a newline, the output
581 * should look human-readable. If the last entry ended
582 * with a newline, print the graph output before this
583 * newline. Otherwise it will end up as a completely blank
584 * line and will look like a gap in the graph.
586 * If the entry separator is not a newline, the output is
587 * primarily intended for programmatic consumption, and we
588 * never want the extra graph output before the entry
591 if (opt
->diffopt
.line_termination
== '\n' &&
592 !opt
->missing_newline
)
593 graph_show_padding(opt
->graph
);
594 putchar(opt
->diffopt
.line_termination
);
599 * If the history graph was requested,
600 * print the graph, up to this commit's line
602 graph_show_commit(opt
->graph
);
605 * Print header line of header..
608 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
609 log_write_email_headers(opt
, commit
, &ctx
.subject
, &extra_headers
,
611 } else if (opt
->commit_format
!= CMIT_FMT_USERFORMAT
) {
612 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_COMMIT
), stdout
);
613 if (opt
->commit_format
!= CMIT_FMT_ONELINE
)
614 fputs("commit ", stdout
);
617 put_revision_mark(opt
, commit
);
618 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
),
620 if (opt
->print_parents
)
621 show_parents(commit
, abbrev_commit
);
622 if (opt
->children
.name
)
623 show_children(opt
, commit
, abbrev_commit
);
626 find_unique_abbrev(parent
->object
.sha1
,
628 show_decorations(opt
, commit
);
629 printf("%s", diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
));
630 if (opt
->commit_format
== CMIT_FMT_ONELINE
) {
634 graph_show_oneline(opt
->graph
);
636 if (opt
->reflog_info
) {
638 * setup_revisions() ensures that opt->reflog_info
639 * and opt->graph cannot both be set,
640 * so we don't need to worry about printing the
643 show_reflog_message(opt
->reflog_info
,
644 opt
->commit_format
== CMIT_FMT_ONELINE
,
646 opt
->date_mode_explicit
);
647 if (opt
->commit_format
== CMIT_FMT_ONELINE
)
652 if (opt
->show_signature
) {
653 show_signature(opt
, commit
);
654 show_mergetag(opt
, commit
);
660 if (opt
->show_notes
) {
662 struct strbuf notebuf
= STRBUF_INIT
;
664 raw
= (opt
->commit_format
== CMIT_FMT_USERFORMAT
);
665 format_display_notes(commit
->object
.sha1
, ¬ebuf
,
666 get_log_output_encoding(), raw
);
667 ctx
.notes_message
= notebuf
.len
668 ? strbuf_detach(¬ebuf
, NULL
)
673 * And then the pretty-printed message itself
675 if (ctx
.need_8bit_cte
>= 0)
676 ctx
.need_8bit_cte
= has_non_ascii(opt
->add_signoff
);
677 ctx
.date_mode
= opt
->date_mode
;
678 ctx
.date_mode_explicit
= opt
->date_mode_explicit
;
679 ctx
.abbrev
= opt
->diffopt
.abbrev
;
680 ctx
.after_subject
= extra_headers
;
681 ctx
.preserve_subject
= opt
->preserve_subject
;
682 ctx
.reflog_info
= opt
->reflog_info
;
683 ctx
.fmt
= opt
->commit_format
;
684 ctx
.mailmap
= opt
->mailmap
;
685 ctx
.color
= opt
->diffopt
.use_color
;
686 pretty_print_commit(&ctx
, commit
, &msgbuf
);
688 if (opt
->add_signoff
)
689 append_signoff(&msgbuf
, opt
->add_signoff
);
691 if ((ctx
.fmt
!= CMIT_FMT_USERFORMAT
) &&
692 ctx
.notes_message
&& *ctx
.notes_message
) {
693 if (ctx
.fmt
== CMIT_FMT_EMAIL
) {
694 strbuf_addstr(&msgbuf
, "---\n");
695 opt
->shown_dashes
= 1;
697 strbuf_addstr(&msgbuf
, ctx
.notes_message
);
700 if (opt
->show_log_size
) {
701 printf("log size %i\n", (int)msgbuf
.len
);
702 graph_show_oneline(opt
->graph
);
706 * Set opt->missing_newline if msgbuf doesn't
707 * end in a newline (including if it is empty)
709 if (!msgbuf
.len
|| msgbuf
.buf
[msgbuf
.len
- 1] != '\n')
710 opt
->missing_newline
= 1;
712 opt
->missing_newline
= 0;
715 graph_show_commit_msg(opt
->graph
, &msgbuf
);
717 fwrite(msgbuf
.buf
, sizeof(char), msgbuf
.len
, stdout
);
718 if (opt
->use_terminator
) {
719 if (!opt
->missing_newline
)
720 graph_show_padding(opt
->graph
);
721 putchar(opt
->diffopt
.line_termination
);
724 strbuf_release(&msgbuf
);
725 free(ctx
.notes_message
);
728 int log_tree_diff_flush(struct rev_info
*opt
)
730 opt
->shown_dashes
= 0;
731 diffcore_std(&opt
->diffopt
);
733 if (diff_queue_is_empty()) {
734 int saved_fmt
= opt
->diffopt
.output_format
;
735 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
736 diff_flush(&opt
->diffopt
);
737 opt
->diffopt
.output_format
= saved_fmt
;
741 if (opt
->loginfo
&& !opt
->no_commit_id
) {
743 if ((opt
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
) &&
744 opt
->verbose_header
&&
745 opt
->commit_format
!= CMIT_FMT_ONELINE
) {
747 * When showing a verbose header (i.e. log message),
748 * and not in --pretty=oneline format, we would want
749 * an extra newline between the end of log and the
750 * diff/diffstat output for readability.
752 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
753 if (opt
->diffopt
.output_prefix
) {
754 struct strbuf
*msg
= NULL
;
755 msg
= opt
->diffopt
.output_prefix(&opt
->diffopt
,
756 opt
->diffopt
.output_prefix_data
);
757 fwrite(msg
->buf
, msg
->len
, 1, stdout
);
761 * We may have shown three-dashes line early
762 * between notes and the log message, in which
763 * case we only want a blank line after the
764 * notes without (an extra) three-dashes line.
765 * Otherwise, we show the three-dashes line if
766 * we are showing the patch with diffstat, but
767 * in that case, there is no extra blank line
768 * after the three-dashes line.
770 if (!opt
->shown_dashes
&&
771 (pch
& opt
->diffopt
.output_format
) == pch
)
776 diff_flush(&opt
->diffopt
);
780 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
782 diff_tree_combined_merge(commit
, opt
->dense_combined_merges
, opt
);
783 return !opt
->loginfo
;
787 * Show the diff of a commit.
789 * Return true if we printed any log info messages
791 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
794 struct commit_list
*parents
;
795 unsigned const char *sha1
= commit
->object
.sha1
;
797 if (!opt
->diff
&& !DIFF_OPT_TST(&opt
->diffopt
, EXIT_WITH_STATUS
))
801 parents
= commit
->parents
;
803 if (opt
->show_root_diff
) {
804 diff_root_tree_sha1(sha1
, "", &opt
->diffopt
);
805 log_tree_diff_flush(opt
);
807 return !opt
->loginfo
;
810 /* More than one parent? */
811 if (parents
&& parents
->next
) {
812 if (opt
->ignore_merges
)
814 else if (opt
->combine_merges
)
815 return do_diff_combined(opt
, commit
);
816 else if (opt
->first_parent_only
) {
818 * Generate merge log entry only for the first
819 * parent, showing summary diff of the others
822 diff_tree_sha1(parents
->item
->object
.sha1
, sha1
, "", &opt
->diffopt
);
823 log_tree_diff_flush(opt
);
824 return !opt
->loginfo
;
827 /* If we show individual diffs, show the parent info */
828 log
->parent
= parents
->item
;
833 struct commit
*parent
= parents
->item
;
835 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
836 log_tree_diff_flush(opt
);
838 showed_log
|= !opt
->loginfo
;
840 /* Set up the log info for the next parent, if any.. */
841 parents
= parents
->next
;
844 log
->parent
= parents
->item
;
850 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
859 shown
= log_tree_diff(opt
, commit
, &log
);
860 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
866 maybe_flush_or_die(stdout
, "stdout");