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 char *slot_name
, const char *value
)
71 int slot
= parse_decorate_color_slot(slot_name
);
75 return config_error_nonbool(var
);
76 return color_parse(value
, decoration_colors
[slot
]);
80 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
81 * for showing the commit sha1, use the same check for --decorate
83 #define decorate_get_color_opt(o, ix) \
84 decorate_get_color((o)->use_color, ix)
86 static void add_name_decoration(enum decoration_type type
, const char *name
, struct object
*obj
)
88 int nlen
= strlen(name
);
89 struct name_decoration
*res
= xmalloc(sizeof(struct name_decoration
) + nlen
);
90 memcpy(res
->name
, name
, nlen
+ 1);
92 res
->next
= add_decoration(&name_decoration
, obj
, res
);
95 static int add_ref_decoration(const char *refname
, const unsigned char *sha1
, int flags
, void *cb_data
)
98 enum decoration_type type
= DECORATION_NONE
;
100 if (starts_with(refname
, "refs/replace/")) {
101 unsigned char original_sha1
[20];
102 if (!check_replace_refs
)
104 if (get_sha1_hex(refname
+ 13, original_sha1
)) {
105 warning("invalid replace ref %s", refname
);
108 obj
= parse_object(original_sha1
);
110 add_name_decoration(DECORATION_GRAFTED
, "replaced", obj
);
114 obj
= parse_object(sha1
);
118 if (starts_with(refname
, "refs/heads/"))
119 type
= DECORATION_REF_LOCAL
;
120 else if (starts_with(refname
, "refs/remotes/"))
121 type
= DECORATION_REF_REMOTE
;
122 else if (starts_with(refname
, "refs/tags/"))
123 type
= DECORATION_REF_TAG
;
124 else if (!strcmp(refname
, "refs/stash"))
125 type
= DECORATION_REF_STASH
;
126 else if (!strcmp(refname
, "HEAD"))
127 type
= DECORATION_REF_HEAD
;
129 if (!cb_data
|| *(int *)cb_data
== DECORATE_SHORT_REFS
)
130 refname
= prettify_refname(refname
);
131 add_name_decoration(type
, refname
, obj
);
132 while (obj
->type
== OBJ_TAG
) {
133 obj
= ((struct tag
*)obj
)->tagged
;
137 parse_object(obj
->sha1
);
138 add_name_decoration(DECORATION_REF_TAG
, refname
, obj
);
143 static int add_graft_decoration(const struct commit_graft
*graft
, void *cb_data
)
145 struct commit
*commit
= lookup_commit(graft
->sha1
);
148 add_name_decoration(DECORATION_GRAFTED
, "grafted", &commit
->object
);
152 void load_ref_decorations(int flags
)
157 for_each_ref(add_ref_decoration
, &flags
);
158 head_ref(add_ref_decoration
, &flags
);
159 for_each_commit_graft(add_graft_decoration
, NULL
);
163 static void show_parents(struct commit
*commit
, int abbrev
)
165 struct commit_list
*p
;
166 for (p
= commit
->parents
; p
; p
= p
->next
) {
167 struct commit
*parent
= p
->item
;
168 printf(" %s", find_unique_abbrev(parent
->object
.sha1
, abbrev
));
172 static void show_children(struct rev_info
*opt
, struct commit
*commit
, int abbrev
)
174 struct commit_list
*p
= lookup_decoration(&opt
->children
, &commit
->object
);
175 for ( ; p
; p
= p
->next
) {
176 printf(" %s", find_unique_abbrev(p
->item
->object
.sha1
, abbrev
));
181 * The caller makes sure there is no funny color before
182 * calling. format_decorations makes sure the same after return.
184 void format_decorations(struct strbuf
*sb
,
185 const struct commit
*commit
,
189 struct name_decoration
*decoration
;
190 const char *color_commit
=
191 diff_get_color(use_color
, DIFF_COMMIT
);
192 const char *color_reset
=
193 decorate_get_color(use_color
, DECORATION_NONE
);
195 decoration
= lookup_decoration(&name_decoration
, &commit
->object
);
200 strbuf_addstr(sb
, color_commit
);
201 strbuf_addstr(sb
, prefix
);
202 strbuf_addstr(sb
, decorate_get_color(use_color
, decoration
->type
));
203 if (decoration
->type
== DECORATION_REF_TAG
)
204 strbuf_addstr(sb
, "tag: ");
205 strbuf_addstr(sb
, decoration
->name
);
206 strbuf_addstr(sb
, color_reset
);
208 decoration
= decoration
->next
;
210 strbuf_addstr(sb
, color_commit
);
211 strbuf_addch(sb
, ')');
212 strbuf_addstr(sb
, color_reset
);
215 void show_decorations(struct rev_info
*opt
, struct commit
*commit
)
217 struct strbuf sb
= STRBUF_INIT
;
219 if (opt
->show_source
&& commit
->util
)
220 printf("\t%s", (char *) commit
->util
);
221 if (!opt
->show_decorations
)
223 format_decorations(&sb
, commit
, opt
->diffopt
.use_color
);
224 fputs(sb
.buf
, stdout
);
228 static unsigned int digits_in_number(unsigned int number
)
230 unsigned int i
= 10, result
= 1;
231 while (i
<= number
) {
238 void fmt_output_subject(struct strbuf
*filename
,
240 struct rev_info
*info
)
242 const char *suffix
= info
->patch_suffix
;
244 int start_len
= filename
->len
;
245 int max_len
= start_len
+ FORMAT_PATCH_NAME_MAX
- (strlen(suffix
) + 1);
247 if (0 < info
->reroll_count
)
248 strbuf_addf(filename
, "v%d-", info
->reroll_count
);
249 strbuf_addf(filename
, "%04d-%s", nr
, subject
);
251 if (max_len
< filename
->len
)
252 strbuf_setlen(filename
, max_len
);
253 strbuf_addstr(filename
, suffix
);
256 void fmt_output_commit(struct strbuf
*filename
,
257 struct commit
*commit
,
258 struct rev_info
*info
)
260 struct pretty_print_context ctx
= {0};
261 struct strbuf subject
= STRBUF_INIT
;
263 format_commit_message(commit
, "%f", &subject
, &ctx
);
264 fmt_output_subject(filename
, subject
.buf
, info
);
265 strbuf_release(&subject
);
268 void log_write_email_headers(struct rev_info
*opt
, struct commit
*commit
,
269 const char **subject_p
,
270 const char **extra_headers_p
,
271 int *need_8bit_cte_p
)
273 const char *subject
= NULL
;
274 const char *extra_headers
= opt
->extra_headers
;
275 const char *name
= sha1_to_hex(commit
->object
.sha1
);
277 *need_8bit_cte_p
= 0; /* unknown */
278 if (opt
->total
> 0) {
279 static char buffer
[64];
280 snprintf(buffer
, sizeof(buffer
),
281 "Subject: [%s%s%0*d/%d] ",
283 *opt
->subject_prefix
? " " : "",
284 digits_in_number(opt
->total
),
285 opt
->nr
, opt
->total
);
287 } else if (opt
->total
== 0 && opt
->subject_prefix
&& *opt
->subject_prefix
) {
288 static char buffer
[256];
289 snprintf(buffer
, sizeof(buffer
),
291 opt
->subject_prefix
);
294 subject
= "Subject: ";
297 printf("From %s Mon Sep 17 00:00:00 2001\n", name
);
298 graph_show_oneline(opt
->graph
);
299 if (opt
->message_id
) {
300 printf("Message-Id: <%s>\n", opt
->message_id
);
301 graph_show_oneline(opt
->graph
);
303 if (opt
->ref_message_ids
&& opt
->ref_message_ids
->nr
> 0) {
305 n
= opt
->ref_message_ids
->nr
;
306 printf("In-Reply-To: <%s>\n", opt
->ref_message_ids
->items
[n
-1].string
);
307 for (i
= 0; i
< n
; i
++)
308 printf("%s<%s>\n", (i
> 0 ? "\t" : "References: "),
309 opt
->ref_message_ids
->items
[i
].string
);
310 graph_show_oneline(opt
->graph
);
312 if (opt
->mime_boundary
) {
313 static char subject_buffer
[1024];
314 static char buffer
[1024];
315 struct strbuf filename
= STRBUF_INIT
;
316 *need_8bit_cte_p
= -1; /* NEVER */
317 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
319 "MIME-Version: 1.0\n"
320 "Content-Type: multipart/mixed;"
321 " boundary=\"%s%s\"\n"
323 "This is a multi-part message in MIME "
326 "Content-Type: text/plain; "
327 "charset=UTF-8; format=fixed\n"
328 "Content-Transfer-Encoding: 8bit\n\n",
329 extra_headers
? extra_headers
: "",
330 mime_boundary_leader
, opt
->mime_boundary
,
331 mime_boundary_leader
, opt
->mime_boundary
);
332 extra_headers
= subject_buffer
;
334 if (opt
->numbered_files
)
335 strbuf_addf(&filename
, "%d", opt
->nr
);
337 fmt_output_commit(&filename
, commit
, opt
);
338 snprintf(buffer
, sizeof(buffer
) - 1,
340 "Content-Type: text/x-patch;"
342 "Content-Transfer-Encoding: 8bit\n"
343 "Content-Disposition: %s;"
344 " filename=\"%s\"\n\n",
345 mime_boundary_leader
, opt
->mime_boundary
,
347 opt
->no_inline
? "attachment" : "inline",
349 opt
->diffopt
.stat_sep
= buffer
;
350 strbuf_release(&filename
);
352 *subject_p
= subject
;
353 *extra_headers_p
= extra_headers
;
356 static void show_sig_lines(struct rev_info
*opt
, int status
, const char *bol
)
358 const char *color
, *reset
, *eol
;
360 color
= diff_get_color_opt(&opt
->diffopt
,
361 status
? DIFF_WHITESPACE
: DIFF_FRAGINFO
);
362 reset
= diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
);
364 eol
= strchrnul(bol
, '\n');
365 printf("%s%.*s%s%s", color
, (int)(eol
- bol
), bol
, reset
,
367 graph_show_oneline(opt
->graph
);
368 bol
= (*eol
) ? (eol
+ 1) : eol
;
372 static void show_signature(struct rev_info
*opt
, struct commit
*commit
)
374 struct strbuf payload
= STRBUF_INIT
;
375 struct strbuf signature
= STRBUF_INIT
;
376 struct strbuf gpg_output
= STRBUF_INIT
;
379 if (parse_signed_commit(commit
, &payload
, &signature
) <= 0)
382 status
= verify_signed_buffer(payload
.buf
, payload
.len
,
383 signature
.buf
, signature
.len
,
385 if (status
&& !gpg_output
.len
)
386 strbuf_addstr(&gpg_output
, "No signature\n");
388 show_sig_lines(opt
, status
, gpg_output
.buf
);
391 strbuf_release(&gpg_output
);
392 strbuf_release(&payload
);
393 strbuf_release(&signature
);
396 static int which_parent(const unsigned char *sha1
, const struct commit
*commit
)
399 const struct commit_list
*parent
;
401 for (nth
= 0, parent
= commit
->parents
; parent
; parent
= parent
->next
) {
402 if (!hashcmp(parent
->item
->object
.sha1
, sha1
))
409 static int is_common_merge(const struct commit
*commit
)
411 return (commit
->parents
412 && commit
->parents
->next
413 && !commit
->parents
->next
->next
);
416 static void show_one_mergetag(struct commit
*commit
,
417 struct commit_extra_header
*extra
,
420 struct rev_info
*opt
= (struct rev_info
*)data
;
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 /* could have a good signature */
452 if (!verify_signed_buffer(extra
->value
, payload_size
,
453 extra
->value
+ payload_size
,
454 extra
->len
- payload_size
,
455 &verify_message
, NULL
))
456 status
= 0; /* good */
457 else if (verify_message
.len
<= gpg_message_offset
)
458 strbuf_addstr(&verify_message
, "No signature\n");
459 /* otherwise we couldn't verify, which is shown as bad */
462 show_sig_lines(opt
, status
, verify_message
.buf
);
463 strbuf_release(&verify_message
);
466 static void show_mergetag(struct rev_info
*opt
, struct commit
*commit
)
468 for_each_mergetag(show_one_mergetag
, commit
, opt
);
471 void show_log(struct rev_info
*opt
)
473 struct strbuf msgbuf
= STRBUF_INIT
;
474 struct log_info
*log
= opt
->loginfo
;
475 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
476 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
477 const char *extra_headers
= opt
->extra_headers
;
478 struct pretty_print_context ctx
= {0};
481 if (!opt
->verbose_header
) {
482 graph_show_commit(opt
->graph
);
485 put_revision_mark(opt
, commit
);
486 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
487 if (opt
->print_parents
)
488 show_parents(commit
, abbrev_commit
);
489 if (opt
->children
.name
)
490 show_children(opt
, commit
, abbrev_commit
);
491 show_decorations(opt
, commit
);
492 if (opt
->graph
&& !graph_is_commit_finished(opt
->graph
)) {
494 graph_show_remainder(opt
->graph
);
496 putchar(opt
->diffopt
.line_termination
);
501 * If use_terminator is set, we already handled any record termination
502 * at the end of the last record.
503 * Otherwise, add a diffopt.line_termination character before all
504 * entries but the first. (IOW, as a separator between entries)
506 if (opt
->shown_one
&& !opt
->use_terminator
) {
508 * If entries are separated by a newline, the output
509 * should look human-readable. If the last entry ended
510 * with a newline, print the graph output before this
511 * newline. Otherwise it will end up as a completely blank
512 * line and will look like a gap in the graph.
514 * If the entry separator is not a newline, the output is
515 * primarily intended for programmatic consumption, and we
516 * never want the extra graph output before the entry
519 if (opt
->diffopt
.line_termination
== '\n' &&
520 !opt
->missing_newline
)
521 graph_show_padding(opt
->graph
);
522 putchar(opt
->diffopt
.line_termination
);
527 * If the history graph was requested,
528 * print the graph, up to this commit's line
530 graph_show_commit(opt
->graph
);
533 * Print header line of header..
536 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
537 log_write_email_headers(opt
, commit
, &ctx
.subject
, &extra_headers
,
539 } else if (opt
->commit_format
!= CMIT_FMT_USERFORMAT
) {
540 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_COMMIT
), stdout
);
541 if (opt
->commit_format
!= CMIT_FMT_ONELINE
)
542 fputs("commit ", stdout
);
545 put_revision_mark(opt
, commit
);
546 fputs(find_unique_abbrev(commit
->object
.sha1
, abbrev_commit
),
548 if (opt
->print_parents
)
549 show_parents(commit
, abbrev_commit
);
550 if (opt
->children
.name
)
551 show_children(opt
, commit
, abbrev_commit
);
554 find_unique_abbrev(parent
->object
.sha1
,
556 fputs(diff_get_color_opt(&opt
->diffopt
, DIFF_RESET
), stdout
);
557 show_decorations(opt
, commit
);
558 if (opt
->commit_format
== CMIT_FMT_ONELINE
) {
562 graph_show_oneline(opt
->graph
);
564 if (opt
->reflog_info
) {
566 * setup_revisions() ensures that opt->reflog_info
567 * and opt->graph cannot both be set,
568 * so we don't need to worry about printing the
571 show_reflog_message(opt
->reflog_info
,
572 opt
->commit_format
== CMIT_FMT_ONELINE
,
574 opt
->date_mode_explicit
);
575 if (opt
->commit_format
== CMIT_FMT_ONELINE
)
580 if (opt
->show_signature
) {
581 show_signature(opt
, commit
);
582 show_mergetag(opt
, commit
);
585 if (!get_cached_commit_buffer(commit
, NULL
))
588 if (opt
->show_notes
) {
590 struct strbuf notebuf
= STRBUF_INIT
;
592 raw
= (opt
->commit_format
== CMIT_FMT_USERFORMAT
);
593 format_display_notes(commit
->object
.sha1
, ¬ebuf
,
594 get_log_output_encoding(), raw
);
595 ctx
.notes_message
= notebuf
.len
596 ? strbuf_detach(¬ebuf
, NULL
)
601 * And then the pretty-printed message itself
603 if (ctx
.need_8bit_cte
>= 0 && opt
->add_signoff
)
605 has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
606 getenv("GIT_COMMITTER_EMAIL")));
607 ctx
.date_mode
= opt
->date_mode
;
608 ctx
.date_mode_explicit
= opt
->date_mode_explicit
;
609 ctx
.abbrev
= opt
->diffopt
.abbrev
;
610 ctx
.after_subject
= extra_headers
;
611 ctx
.preserve_subject
= opt
->preserve_subject
;
612 ctx
.reflog_info
= opt
->reflog_info
;
613 ctx
.fmt
= opt
->commit_format
;
614 ctx
.mailmap
= opt
->mailmap
;
615 ctx
.color
= opt
->diffopt
.use_color
;
616 ctx
.output_encoding
= get_log_output_encoding();
617 if (opt
->from_ident
.mail_begin
&& opt
->from_ident
.name_begin
)
618 ctx
.from_ident
= &opt
->from_ident
;
619 pretty_print_commit(&ctx
, commit
, &msgbuf
);
621 if (opt
->add_signoff
)
622 append_signoff(&msgbuf
, 0, APPEND_SIGNOFF_DEDUP
);
624 if ((ctx
.fmt
!= CMIT_FMT_USERFORMAT
) &&
625 ctx
.notes_message
&& *ctx
.notes_message
) {
626 if (ctx
.fmt
== CMIT_FMT_EMAIL
) {
627 strbuf_addstr(&msgbuf
, "---\n");
628 opt
->shown_dashes
= 1;
630 strbuf_addstr(&msgbuf
, ctx
.notes_message
);
633 if (opt
->show_log_size
) {
634 printf("log size %i\n", (int)msgbuf
.len
);
635 graph_show_oneline(opt
->graph
);
639 * Set opt->missing_newline if msgbuf doesn't
640 * end in a newline (including if it is empty)
642 if (!msgbuf
.len
|| msgbuf
.buf
[msgbuf
.len
- 1] != '\n')
643 opt
->missing_newline
= 1;
645 opt
->missing_newline
= 0;
648 graph_show_commit_msg(opt
->graph
, &msgbuf
);
650 fwrite(msgbuf
.buf
, sizeof(char), msgbuf
.len
, stdout
);
651 if (opt
->use_terminator
&& !commit_format_is_empty(opt
->commit_format
)) {
652 if (!opt
->missing_newline
)
653 graph_show_padding(opt
->graph
);
654 putchar(opt
->diffopt
.line_termination
);
657 strbuf_release(&msgbuf
);
658 free(ctx
.notes_message
);
661 int log_tree_diff_flush(struct rev_info
*opt
)
663 opt
->shown_dashes
= 0;
664 diffcore_std(&opt
->diffopt
);
666 if (diff_queue_is_empty()) {
667 int saved_fmt
= opt
->diffopt
.output_format
;
668 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
669 diff_flush(&opt
->diffopt
);
670 opt
->diffopt
.output_format
= saved_fmt
;
674 if (opt
->loginfo
&& !opt
->no_commit_id
) {
676 if ((opt
->diffopt
.output_format
& ~DIFF_FORMAT_NO_OUTPUT
) &&
677 opt
->verbose_header
&&
678 opt
->commit_format
!= CMIT_FMT_ONELINE
&&
679 !commit_format_is_empty(opt
->commit_format
)) {
681 * When showing a verbose header (i.e. log message),
682 * and not in --pretty=oneline format, we would want
683 * an extra newline between the end of log and the
684 * diff/diffstat output for readability.
686 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
687 if (opt
->diffopt
.output_prefix
) {
688 struct strbuf
*msg
= NULL
;
689 msg
= opt
->diffopt
.output_prefix(&opt
->diffopt
,
690 opt
->diffopt
.output_prefix_data
);
691 fwrite(msg
->buf
, msg
->len
, 1, stdout
);
695 * We may have shown three-dashes line early
696 * between notes and the log message, in which
697 * case we only want a blank line after the
698 * notes without (an extra) three-dashes line.
699 * Otherwise, we show the three-dashes line if
700 * we are showing the patch with diffstat, but
701 * in that case, there is no extra blank line
702 * after the three-dashes line.
704 if (!opt
->shown_dashes
&&
705 (pch
& opt
->diffopt
.output_format
) == pch
)
710 diff_flush(&opt
->diffopt
);
714 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
716 diff_tree_combined_merge(commit
, opt
->dense_combined_merges
, opt
);
717 return !opt
->loginfo
;
721 * Show the diff of a commit.
723 * Return true if we printed any log info messages
725 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
728 struct commit_list
*parents
;
729 unsigned const char *sha1
;
731 if (!opt
->diff
&& !DIFF_OPT_TST(&opt
->diffopt
, EXIT_WITH_STATUS
))
734 parse_commit_or_die(commit
);
735 sha1
= commit
->tree
->object
.sha1
;
738 parents
= get_saved_parents(opt
, commit
);
740 if (opt
->show_root_diff
) {
741 diff_root_tree_sha1(sha1
, "", &opt
->diffopt
);
742 log_tree_diff_flush(opt
);
744 return !opt
->loginfo
;
747 /* More than one parent? */
748 if (parents
&& parents
->next
) {
749 if (opt
->ignore_merges
)
751 else if (opt
->combine_merges
)
752 return do_diff_combined(opt
, commit
);
753 else if (opt
->first_parent_only
) {
755 * Generate merge log entry only for the first
756 * parent, showing summary diff of the others
759 parse_commit_or_die(parents
->item
);
760 diff_tree_sha1(parents
->item
->tree
->object
.sha1
,
761 sha1
, "", &opt
->diffopt
);
762 log_tree_diff_flush(opt
);
763 return !opt
->loginfo
;
766 /* If we show individual diffs, show the parent info */
767 log
->parent
= parents
->item
;
772 struct commit
*parent
= parents
->item
;
774 parse_commit_or_die(parent
);
775 diff_tree_sha1(parent
->tree
->object
.sha1
,
776 sha1
, "", &opt
->diffopt
);
777 log_tree_diff_flush(opt
);
779 showed_log
|= !opt
->loginfo
;
781 /* Set up the log info for the next parent, if any.. */
782 parents
= parents
->next
;
785 log
->parent
= parents
->item
;
791 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
800 if (opt
->line_level_traverse
)
801 return line_log_print(opt
, commit
);
803 if (opt
->track_linear
&& !opt
->linear
&& !opt
->reverse_output_stage
)
804 printf("\n%s\n", opt
->break_bar
);
805 shown
= log_tree_diff(opt
, commit
, &log
);
806 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
811 if (opt
->track_linear
&& !opt
->linear
&& opt
->reverse_output_stage
)
812 printf("\n%s\n", opt
->break_bar
);
814 maybe_flush_or_die(stdout
, "stdout");