log-tree: show mergetag in log --show-signature output
[git/jnareb-git.git] / log-tree.c
blob61a12a7cb01cbc36e8ed1d1a8997a8ca9bba3b05
1 #include "cache.h"
2 #include "diff.h"
3 #include "commit.h"
4 #include "tag.h"
5 #include "graph.h"
6 #include "log-tree.h"
7 #include "reflog-walk.h"
8 #include "refs.h"
9 #include "string-list.h"
10 #include "color.h"
11 #include "gpg-interface.h"
13 struct decoration name_decoration = { "object names" };
15 enum decoration_type {
16 DECORATION_NONE = 0,
17 DECORATION_REF_LOCAL,
18 DECORATION_REF_REMOTE,
19 DECORATION_REF_TAG,
20 DECORATION_REF_STASH,
21 DECORATION_REF_HEAD,
22 DECORATION_GRAFTED,
25 static char decoration_colors[][COLOR_MAXLEN] = {
26 GIT_COLOR_RESET,
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];
39 return "";
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
50 * consistency.
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;
64 return -1;
67 int parse_decorate_color_config(const char *var, const int ofs, const char *value)
69 int slot = parse_decorate_color_slot(var + ofs);
70 if (slot < 0)
71 return 0;
72 if (!value)
73 return config_error_nonbool(var);
74 color_parse(value, var, decoration_colors[slot]);
75 return 0;
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);
90 res->type = type;
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)
96 struct object *obj;
97 enum decoration_type type = DECORATION_NONE;
99 if (!prefixcmp(refname, "refs/replace/")) {
100 unsigned char original_sha1[20];
101 if (!read_replace_refs)
102 return 0;
103 if (get_sha1_hex(refname + 13, original_sha1)) {
104 warning("invalid replace ref %s", refname);
105 return 0;
107 obj = parse_object(original_sha1);
108 if (obj)
109 add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
110 return 0;
113 obj = parse_object(sha1);
114 if (!obj)
115 return 0;
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 (!prefixcmp(refname, "refs/stash"))
124 type = DECORATION_REF_STASH;
125 else if (!prefixcmp(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;
133 if (!obj)
134 break;
135 add_name_decoration(DECORATION_REF_TAG, refname, obj);
137 return 0;
140 static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
142 struct commit *commit = lookup_commit(graft->sha1);
143 if (!commit)
144 return 0;
145 add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
146 return 0;
149 void load_ref_decorations(int flags)
151 static int loaded;
152 if (!loaded) {
153 loaded = 1;
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)
179 const char *prefix;
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)
189 return;
190 decoration = lookup_decoration(&name_decoration, &commit->object);
191 if (!decoration)
192 return;
193 prefix = " (";
194 while (decoration) {
195 printf("%s", prefix);
196 fputs(decorate_get_color_opt(&opt->diffopt, decoration->type),
197 stdout);
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);
203 prefix = ", ";
204 decoration = decoration->next;
206 putchar(')');
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)
215 char *cp;
216 int seen_colon = 0;
217 int seen_at = 0;
218 int seen_name = 0;
219 int seen_head = 0;
221 cp = letter + size;
222 while (letter <= --cp && *cp == '\n')
223 continue;
225 while (letter <= cp) {
226 char ch = *cp--;
227 if (ch == '\n')
228 break;
230 if (!seen_at) {
231 if (ch == '@')
232 seen_at = 1;
233 continue;
235 if (!seen_colon) {
236 if (ch == '@')
237 return 0;
238 else if (ch == ':')
239 seen_colon = 1;
240 else
241 seen_name = 1;
242 continue;
244 if (('A' <= ch && ch <= 'Z') ||
245 ('a' <= ch && ch <= 'z') ||
246 ch == '-') {
247 seen_head = 1;
248 continue;
250 /* no empty last line doesn't match */
251 return 0;
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);
260 int has_signoff = 0;
261 char *cp;
263 cp = sb->buf;
265 /* First see if we already have the sign-off by the signer */
266 while ((cp = strstr(cp, signed_off_by))) {
268 has_signoff = 1;
270 cp += strlen(signed_off_by);
271 if (cp + signoff_len >= sb->buf + sb->len)
272 break;
273 if (strncmp(cp, signoff, signoff_len))
274 continue;
275 if (!isspace(cp[signoff_len]))
276 continue;
277 /* we already have him */
278 return;
281 if (!has_signoff)
282 has_signoff = detect_any_signoff(sb->buf, sb->len);
284 if (!has_signoff)
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) {
296 i *= 10;
297 result++;
299 return result;
302 void get_patch_filename(struct commit *commit, int nr, const char *suffix,
303 struct strbuf *buf)
305 int suffix_len = strlen(suffix) + 1;
306 int start_len = buf->len;
308 strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
309 if (commit) {
310 int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
311 struct pretty_print_context ctx = {0};
312 ctx.date_mode = DATE_NORMAL;
314 format_commit_message(commit, "%f", buf, &ctx);
315 if (max_len < buf->len)
316 strbuf_setlen(buf, max_len);
317 strbuf_addstr(buf, suffix);
321 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
322 const char **subject_p,
323 const char **extra_headers_p,
324 int *need_8bit_cte_p)
326 const char *subject = NULL;
327 const char *extra_headers = opt->extra_headers;
328 const char *name = sha1_to_hex(commit->object.sha1);
330 *need_8bit_cte_p = 0; /* unknown */
331 if (opt->total > 0) {
332 static char buffer[64];
333 snprintf(buffer, sizeof(buffer),
334 "Subject: [%s%s%0*d/%d] ",
335 opt->subject_prefix,
336 *opt->subject_prefix ? " " : "",
337 digits_in_number(opt->total),
338 opt->nr, opt->total);
339 subject = buffer;
340 } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
341 static char buffer[256];
342 snprintf(buffer, sizeof(buffer),
343 "Subject: [%s] ",
344 opt->subject_prefix);
345 subject = buffer;
346 } else {
347 subject = "Subject: ";
350 printf("From %s Mon Sep 17 00:00:00 2001\n", name);
351 graph_show_oneline(opt->graph);
352 if (opt->message_id) {
353 printf("Message-Id: <%s>\n", opt->message_id);
354 graph_show_oneline(opt->graph);
356 if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
357 int i, n;
358 n = opt->ref_message_ids->nr;
359 printf("In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string);
360 for (i = 0; i < n; i++)
361 printf("%s<%s>\n", (i > 0 ? "\t" : "References: "),
362 opt->ref_message_ids->items[i].string);
363 graph_show_oneline(opt->graph);
365 if (opt->mime_boundary) {
366 static char subject_buffer[1024];
367 static char buffer[1024];
368 struct strbuf filename = STRBUF_INIT;
369 *need_8bit_cte_p = -1; /* NEVER */
370 snprintf(subject_buffer, sizeof(subject_buffer) - 1,
371 "%s"
372 "MIME-Version: 1.0\n"
373 "Content-Type: multipart/mixed;"
374 " boundary=\"%s%s\"\n"
375 "\n"
376 "This is a multi-part message in MIME "
377 "format.\n"
378 "--%s%s\n"
379 "Content-Type: text/plain; "
380 "charset=UTF-8; format=fixed\n"
381 "Content-Transfer-Encoding: 8bit\n\n",
382 extra_headers ? extra_headers : "",
383 mime_boundary_leader, opt->mime_boundary,
384 mime_boundary_leader, opt->mime_boundary);
385 extra_headers = subject_buffer;
387 get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,
388 opt->patch_suffix, &filename);
389 snprintf(buffer, sizeof(buffer) - 1,
390 "\n--%s%s\n"
391 "Content-Type: text/x-patch;"
392 " name=\"%s\"\n"
393 "Content-Transfer-Encoding: 8bit\n"
394 "Content-Disposition: %s;"
395 " filename=\"%s\"\n\n",
396 mime_boundary_leader, opt->mime_boundary,
397 filename.buf,
398 opt->no_inline ? "attachment" : "inline",
399 filename.buf);
400 opt->diffopt.stat_sep = buffer;
401 strbuf_release(&filename);
403 *subject_p = subject;
404 *extra_headers_p = extra_headers;
407 static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
409 const char *color, *reset, *eol;
411 color = diff_get_color_opt(&opt->diffopt,
412 status ? DIFF_WHITESPACE : DIFF_FRAGINFO);
413 reset = diff_get_color_opt(&opt->diffopt, DIFF_RESET);
414 while (*bol) {
415 eol = strchrnul(bol, '\n');
416 printf("%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
417 *eol ? "\n" : "");
418 bol = (*eol) ? (eol + 1) : eol;
422 static void show_signature(struct rev_info *opt, struct commit *commit)
424 struct strbuf payload = STRBUF_INIT;
425 struct strbuf signature = STRBUF_INIT;
426 struct strbuf gpg_output = STRBUF_INIT;
427 int status;
429 if (parse_signed_commit(commit->object.sha1, &payload, &signature) <= 0)
430 goto out;
432 status = verify_signed_buffer(payload.buf, payload.len,
433 signature.buf, signature.len,
434 &gpg_output);
435 if (status && !gpg_output.len)
436 strbuf_addstr(&gpg_output, "No signature\n");
438 show_sig_lines(opt, status, gpg_output.buf);
440 out:
441 strbuf_release(&gpg_output);
442 strbuf_release(&payload);
443 strbuf_release(&signature);
446 static int which_parent(const unsigned char *sha1, const struct commit *commit)
448 int nth;
449 const struct commit_list *parent;
451 for (nth = 0, parent = commit->parents; parent; parent = parent->next) {
452 if (!hashcmp(parent->item->object.sha1, sha1))
453 return nth;
454 nth++;
456 return -1;
459 static void show_one_mergetag(struct rev_info *opt,
460 struct commit_extra_header *extra,
461 struct commit *commit)
463 unsigned char sha1[20];
464 struct tag *tag;
465 struct strbuf verify_message;
466 int status, nth;
467 size_t payload_size, gpg_message_offset;
469 hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), sha1);
470 tag = lookup_tag(sha1);
471 if (!tag)
472 return; /* error message already given */
474 strbuf_init(&verify_message, 256);
475 if (parse_tag_buffer(tag, extra->value, extra->len))
476 strbuf_addstr(&verify_message, "malformed mergetag\n");
477 else if ((nth = which_parent(tag->tagged->sha1, commit)) < 0)
478 strbuf_addf(&verify_message, "tag %s names a non-parent %s\n",
479 tag->tag, tag->tagged->sha1);
480 else
481 strbuf_addf(&verify_message,
482 "parent #%d, tagged '%s'\n", nth + 1, tag->tag);
483 gpg_message_offset = verify_message.len;
485 payload_size = parse_signature(extra->value, extra->len);
486 if ((extra->len <= payload_size) ||
487 (verify_signed_buffer(extra->value, payload_size,
488 extra->value + payload_size,
489 extra->len - payload_size,
490 &verify_message) &&
491 verify_message.len <= gpg_message_offset)) {
492 strbuf_addstr(&verify_message, "No signature\n");
493 status = -1;
495 else if (strstr(verify_message.buf + gpg_message_offset,
496 ": Good signature from "))
497 status = 0;
498 else
499 status = -1;
501 show_sig_lines(opt, status, verify_message.buf);
502 strbuf_release(&verify_message);
505 static void show_mergetag(struct rev_info *opt, struct commit *commit)
507 struct commit_extra_header *extra, *to_free;
509 to_free = read_commit_extra_headers(commit, NULL);
510 for (extra = to_free; extra; extra = extra->next) {
511 if (strcmp(extra->key, "mergetag"))
512 continue; /* not a merge tag */
513 show_one_mergetag(opt, extra, commit);
515 free_commit_extra_headers(to_free);
518 void show_log(struct rev_info *opt)
520 struct strbuf msgbuf = STRBUF_INIT;
521 struct log_info *log = opt->loginfo;
522 struct commit *commit = log->commit, *parent = log->parent;
523 int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
524 const char *extra_headers = opt->extra_headers;
525 struct pretty_print_context ctx = {0};
527 opt->loginfo = NULL;
528 ctx.show_notes = opt->show_notes;
529 if (!opt->verbose_header) {
530 graph_show_commit(opt->graph);
532 if (!opt->graph)
533 put_revision_mark(opt, commit);
534 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
535 if (opt->print_parents)
536 show_parents(commit, abbrev_commit);
537 if (opt->children.name)
538 show_children(opt, commit, abbrev_commit);
539 show_decorations(opt, commit);
540 if (opt->graph && !graph_is_commit_finished(opt->graph)) {
541 putchar('\n');
542 graph_show_remainder(opt->graph);
544 putchar(opt->diffopt.line_termination);
545 return;
549 * If use_terminator is set, we already handled any record termination
550 * at the end of the last record.
551 * Otherwise, add a diffopt.line_termination character before all
552 * entries but the first. (IOW, as a separator between entries)
554 if (opt->shown_one && !opt->use_terminator) {
556 * If entries are separated by a newline, the output
557 * should look human-readable. If the last entry ended
558 * with a newline, print the graph output before this
559 * newline. Otherwise it will end up as a completely blank
560 * line and will look like a gap in the graph.
562 * If the entry separator is not a newline, the output is
563 * primarily intended for programmatic consumption, and we
564 * never want the extra graph output before the entry
565 * separator.
567 if (opt->diffopt.line_termination == '\n' &&
568 !opt->missing_newline)
569 graph_show_padding(opt->graph);
570 putchar(opt->diffopt.line_termination);
572 opt->shown_one = 1;
575 * If the history graph was requested,
576 * print the graph, up to this commit's line
578 graph_show_commit(opt->graph);
581 * Print header line of header..
584 if (opt->commit_format == CMIT_FMT_EMAIL) {
585 log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
586 &ctx.need_8bit_cte);
587 } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
588 fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
589 if (opt->commit_format != CMIT_FMT_ONELINE)
590 fputs("commit ", stdout);
592 if (!opt->graph)
593 put_revision_mark(opt, commit);
594 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
595 stdout);
596 if (opt->print_parents)
597 show_parents(commit, abbrev_commit);
598 if (opt->children.name)
599 show_children(opt, commit, abbrev_commit);
600 if (parent)
601 printf(" (from %s)",
602 find_unique_abbrev(parent->object.sha1,
603 abbrev_commit));
604 show_decorations(opt, commit);
605 printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET));
606 if (opt->commit_format == CMIT_FMT_ONELINE) {
607 putchar(' ');
608 } else {
609 putchar('\n');
610 graph_show_oneline(opt->graph);
612 if (opt->reflog_info) {
614 * setup_revisions() ensures that opt->reflog_info
615 * and opt->graph cannot both be set,
616 * so we don't need to worry about printing the
617 * graph info here.
619 show_reflog_message(opt->reflog_info,
620 opt->commit_format == CMIT_FMT_ONELINE,
621 opt->date_mode_explicit ?
622 opt->date_mode :
623 DATE_NORMAL);
624 if (opt->commit_format == CMIT_FMT_ONELINE)
625 return;
629 if (opt->show_signature) {
630 show_signature(opt, commit);
631 show_mergetag(opt, commit);
634 if (!commit->buffer)
635 return;
638 * And then the pretty-printed message itself
640 if (ctx.need_8bit_cte >= 0)
641 ctx.need_8bit_cte = has_non_ascii(opt->add_signoff);
642 ctx.date_mode = opt->date_mode;
643 ctx.abbrev = opt->diffopt.abbrev;
644 ctx.after_subject = extra_headers;
645 ctx.preserve_subject = opt->preserve_subject;
646 ctx.reflog_info = opt->reflog_info;
647 ctx.fmt = opt->commit_format;
648 pretty_print_commit(&ctx, commit, &msgbuf);
650 if (opt->add_signoff)
651 append_signoff(&msgbuf, opt->add_signoff);
652 if (opt->show_log_size) {
653 printf("log size %i\n", (int)msgbuf.len);
654 graph_show_oneline(opt->graph);
658 * Set opt->missing_newline if msgbuf doesn't
659 * end in a newline (including if it is empty)
661 if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n')
662 opt->missing_newline = 1;
663 else
664 opt->missing_newline = 0;
666 if (opt->graph)
667 graph_show_commit_msg(opt->graph, &msgbuf);
668 else
669 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
670 if (opt->use_terminator) {
671 if (!opt->missing_newline)
672 graph_show_padding(opt->graph);
673 putchar('\n');
676 strbuf_release(&msgbuf);
679 int log_tree_diff_flush(struct rev_info *opt)
681 diffcore_std(&opt->diffopt);
683 if (diff_queue_is_empty()) {
684 int saved_fmt = opt->diffopt.output_format;
685 opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
686 diff_flush(&opt->diffopt);
687 opt->diffopt.output_format = saved_fmt;
688 return 0;
691 if (opt->loginfo && !opt->no_commit_id) {
692 /* When showing a verbose header (i.e. log message),
693 * and not in --pretty=oneline format, we would want
694 * an extra newline between the end of log and the
695 * output for readability.
697 show_log(opt);
698 if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
699 opt->verbose_header &&
700 opt->commit_format != CMIT_FMT_ONELINE) {
701 int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
702 if ((pch & opt->diffopt.output_format) == pch)
703 printf("---");
704 if (opt->diffopt.output_prefix) {
705 struct strbuf *msg = NULL;
706 msg = opt->diffopt.output_prefix(&opt->diffopt,
707 opt->diffopt.output_prefix_data);
708 fwrite(msg->buf, msg->len, 1, stdout);
710 putchar('\n');
713 diff_flush(&opt->diffopt);
714 return 1;
717 static int do_diff_combined(struct rev_info *opt, struct commit *commit)
719 unsigned const char *sha1 = commit->object.sha1;
721 diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
722 return !opt->loginfo;
726 * Show the diff of a commit.
728 * Return true if we printed any log info messages
730 static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
732 int showed_log;
733 struct commit_list *parents;
734 unsigned const char *sha1 = commit->object.sha1;
736 if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
737 return 0;
739 /* Root commit? */
740 parents = commit->parents;
741 if (!parents) {
742 if (opt->show_root_diff) {
743 diff_root_tree_sha1(sha1, "", &opt->diffopt);
744 log_tree_diff_flush(opt);
746 return !opt->loginfo;
749 /* More than one parent? */
750 if (parents && parents->next) {
751 if (opt->ignore_merges)
752 return 0;
753 else if (opt->combine_merges)
754 return do_diff_combined(opt, commit);
755 else if (opt->first_parent_only) {
757 * Generate merge log entry only for the first
758 * parent, showing summary diff of the others
759 * we merged _in_.
761 diff_tree_sha1(parents->item->object.sha1, 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;
770 showed_log = 0;
771 for (;;) {
772 struct commit *parent = parents->item;
774 diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
775 log_tree_diff_flush(opt);
777 showed_log |= !opt->loginfo;
779 /* Set up the log info for the next parent, if any.. */
780 parents = parents->next;
781 if (!parents)
782 break;
783 log->parent = parents->item;
784 opt->loginfo = log;
786 return showed_log;
789 int log_tree_commit(struct rev_info *opt, struct commit *commit)
791 struct log_info log;
792 int shown;
794 log.commit = commit;
795 log.parent = NULL;
796 opt->loginfo = &log;
798 shown = log_tree_diff(opt, commit, &log);
799 if (!shown && opt->loginfo && opt->always_show_header) {
800 log.parent = NULL;
801 show_log(opt);
802 shown = 1;
804 opt->loginfo = NULL;
805 maybe_flush_or_die(stdout, "stdout");
806 return shown;