Merge branch 'mc/count-objects-kibibytes' into next
[git/mjg.git] / log-tree.c
blob308b2c62d4b73018edeeed11442ba394356d47d4
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"
12 #include "sequencer.h"
13 #include "line-log.h"
15 struct decoration name_decoration = { "object names" };
17 enum decoration_type {
18 DECORATION_NONE = 0,
19 DECORATION_REF_LOCAL,
20 DECORATION_REF_REMOTE,
21 DECORATION_REF_TAG,
22 DECORATION_REF_STASH,
23 DECORATION_REF_HEAD,
24 DECORATION_GRAFTED,
27 static char decoration_colors[][COLOR_MAXLEN] = {
28 GIT_COLOR_RESET,
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];
41 return "";
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
52 * consistency.
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;
66 return -1;
69 int parse_decorate_color_config(const char *var, const int ofs, const char *value)
71 int slot = parse_decorate_color_slot(var + ofs);
72 if (slot < 0)
73 return 0;
74 if (!value)
75 return config_error_nonbool(var);
76 color_parse(value, var, decoration_colors[slot]);
77 return 0;
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);
92 res->type = type;
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)
98 struct object *obj;
99 enum decoration_type type = DECORATION_NONE;
101 if (!prefixcmp(refname, "refs/replace/")) {
102 unsigned char original_sha1[20];
103 if (!read_replace_refs)
104 return 0;
105 if (get_sha1_hex(refname + 13, original_sha1)) {
106 warning("invalid replace ref %s", refname);
107 return 0;
109 obj = parse_object(original_sha1);
110 if (obj)
111 add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
112 return 0;
115 obj = parse_object(sha1);
116 if (!obj)
117 return 0;
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;
135 if (!obj)
136 break;
137 add_name_decoration(DECORATION_REF_TAG, refname, obj);
139 return 0;
142 static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
144 struct commit *commit = lookup_commit(graft->sha1);
145 if (!commit)
146 return 0;
147 add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
148 return 0;
151 void load_ref_decorations(int flags)
153 static int loaded;
154 if (!loaded) {
155 loaded = 1;
156 for_each_ref(add_ref_decoration, &flags);
157 head_ref(add_ref_decoration, &flags);
158 for_each_commit_graft(add_graft_decoration, NULL);
162 static void show_parents(struct commit *commit, int abbrev)
164 struct commit_list *p;
165 for (p = commit->parents; p ; p = p->next) {
166 struct commit *parent = p->item;
167 printf(" %s", find_unique_abbrev(parent->object.sha1, abbrev));
171 static void show_children(struct rev_info *opt, struct commit *commit, int abbrev)
173 struct commit_list *p = lookup_decoration(&opt->children, &commit->object);
174 for ( ; p; p = p->next) {
175 printf(" %s", find_unique_abbrev(p->item->object.sha1, abbrev));
179 void show_decorations(struct rev_info *opt, struct commit *commit)
181 const char *prefix;
182 struct name_decoration *decoration;
183 const char *color_commit =
184 diff_get_color_opt(&opt->diffopt, DIFF_COMMIT);
185 const char *color_reset =
186 decorate_get_color_opt(&opt->diffopt, DECORATION_NONE);
188 if (opt->show_source && commit->util)
189 printf("\t%s", (char *) commit->util);
190 if (!opt->show_decorations)
191 return;
192 decoration = lookup_decoration(&name_decoration, &commit->object);
193 if (!decoration)
194 return;
195 prefix = " (";
196 while (decoration) {
197 printf("%s", prefix);
198 fputs(decorate_get_color_opt(&opt->diffopt, decoration->type),
199 stdout);
200 if (decoration->type == DECORATION_REF_TAG)
201 fputs("tag: ", stdout);
202 printf("%s", decoration->name);
203 fputs(color_reset, stdout);
204 fputs(color_commit, stdout);
205 prefix = ", ";
206 decoration = decoration->next;
208 putchar(')');
211 static unsigned int digits_in_number(unsigned int number)
213 unsigned int i = 10, result = 1;
214 while (i <= number) {
215 i *= 10;
216 result++;
218 return result;
221 void fmt_output_subject(struct strbuf *filename,
222 const char *subject,
223 struct rev_info *info)
225 const char *suffix = info->patch_suffix;
226 int nr = info->nr;
227 int start_len = filename->len;
228 int max_len = start_len + FORMAT_PATCH_NAME_MAX - (strlen(suffix) + 1);
230 if (0 < info->reroll_count)
231 strbuf_addf(filename, "v%d-", info->reroll_count);
232 strbuf_addf(filename, "%04d-%s", nr, subject);
234 if (max_len < filename->len)
235 strbuf_setlen(filename, max_len);
236 strbuf_addstr(filename, suffix);
239 void fmt_output_commit(struct strbuf *filename,
240 struct commit *commit,
241 struct rev_info *info)
243 struct pretty_print_context ctx = {0};
244 struct strbuf subject = STRBUF_INIT;
246 format_commit_message(commit, "%f", &subject, &ctx);
247 fmt_output_subject(filename, subject.buf, info);
248 strbuf_release(&subject);
251 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
252 const char **subject_p,
253 const char **extra_headers_p,
254 int *need_8bit_cte_p)
256 const char *subject = NULL;
257 const char *extra_headers = opt->extra_headers;
258 const char *name = sha1_to_hex(commit->object.sha1);
260 *need_8bit_cte_p = 0; /* unknown */
261 if (opt->total > 0) {
262 static char buffer[64];
263 snprintf(buffer, sizeof(buffer),
264 "Subject: [%s%s%0*d/%d] ",
265 opt->subject_prefix,
266 *opt->subject_prefix ? " " : "",
267 digits_in_number(opt->total),
268 opt->nr, opt->total);
269 subject = buffer;
270 } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
271 static char buffer[256];
272 snprintf(buffer, sizeof(buffer),
273 "Subject: [%s] ",
274 opt->subject_prefix);
275 subject = buffer;
276 } else {
277 subject = "Subject: ";
280 printf("From %s Mon Sep 17 00:00:00 2001\n", name);
281 graph_show_oneline(opt->graph);
282 if (opt->message_id) {
283 printf("Message-Id: <%s>\n", opt->message_id);
284 graph_show_oneline(opt->graph);
286 if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
287 int i, n;
288 n = opt->ref_message_ids->nr;
289 printf("In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string);
290 for (i = 0; i < n; i++)
291 printf("%s<%s>\n", (i > 0 ? "\t" : "References: "),
292 opt->ref_message_ids->items[i].string);
293 graph_show_oneline(opt->graph);
295 if (opt->mime_boundary) {
296 static char subject_buffer[1024];
297 static char buffer[1024];
298 struct strbuf filename = STRBUF_INIT;
299 *need_8bit_cte_p = -1; /* NEVER */
300 snprintf(subject_buffer, sizeof(subject_buffer) - 1,
301 "%s"
302 "MIME-Version: 1.0\n"
303 "Content-Type: multipart/mixed;"
304 " boundary=\"%s%s\"\n"
305 "\n"
306 "This is a multi-part message in MIME "
307 "format.\n"
308 "--%s%s\n"
309 "Content-Type: text/plain; "
310 "charset=UTF-8; format=fixed\n"
311 "Content-Transfer-Encoding: 8bit\n\n",
312 extra_headers ? extra_headers : "",
313 mime_boundary_leader, opt->mime_boundary,
314 mime_boundary_leader, opt->mime_boundary);
315 extra_headers = subject_buffer;
317 if (opt->numbered_files)
318 strbuf_addf(&filename, "%d", opt->nr);
319 else
320 fmt_output_commit(&filename, commit, opt);
321 snprintf(buffer, sizeof(buffer) - 1,
322 "\n--%s%s\n"
323 "Content-Type: text/x-patch;"
324 " name=\"%s\"\n"
325 "Content-Transfer-Encoding: 8bit\n"
326 "Content-Disposition: %s;"
327 " filename=\"%s\"\n\n",
328 mime_boundary_leader, opt->mime_boundary,
329 filename.buf,
330 opt->no_inline ? "attachment" : "inline",
331 filename.buf);
332 opt->diffopt.stat_sep = buffer;
333 strbuf_release(&filename);
335 *subject_p = subject;
336 *extra_headers_p = extra_headers;
339 static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
341 const char *color, *reset, *eol;
343 color = diff_get_color_opt(&opt->diffopt,
344 status ? DIFF_WHITESPACE : DIFF_FRAGINFO);
345 reset = diff_get_color_opt(&opt->diffopt, DIFF_RESET);
346 while (*bol) {
347 eol = strchrnul(bol, '\n');
348 printf("%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
349 *eol ? "\n" : "");
350 bol = (*eol) ? (eol + 1) : eol;
354 static void show_signature(struct rev_info *opt, struct commit *commit)
356 struct strbuf payload = STRBUF_INIT;
357 struct strbuf signature = STRBUF_INIT;
358 struct strbuf gpg_output = STRBUF_INIT;
359 int status;
361 if (parse_signed_commit(commit->object.sha1, &payload, &signature) <= 0)
362 goto out;
364 status = verify_signed_buffer(payload.buf, payload.len,
365 signature.buf, signature.len,
366 &gpg_output, NULL);
367 if (status && !gpg_output.len)
368 strbuf_addstr(&gpg_output, "No signature\n");
370 show_sig_lines(opt, status, gpg_output.buf);
372 out:
373 strbuf_release(&gpg_output);
374 strbuf_release(&payload);
375 strbuf_release(&signature);
378 static int which_parent(const unsigned char *sha1, const struct commit *commit)
380 int nth;
381 const struct commit_list *parent;
383 for (nth = 0, parent = commit->parents; parent; parent = parent->next) {
384 if (!hashcmp(parent->item->object.sha1, sha1))
385 return nth;
386 nth++;
388 return -1;
391 static int is_common_merge(const struct commit *commit)
393 return (commit->parents
394 && commit->parents->next
395 && !commit->parents->next->next);
398 static void show_one_mergetag(struct rev_info *opt,
399 struct commit_extra_header *extra,
400 struct commit *commit)
402 unsigned char sha1[20];
403 struct tag *tag;
404 struct strbuf verify_message;
405 int status, nth;
406 size_t payload_size, gpg_message_offset;
408 hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), sha1);
409 tag = lookup_tag(sha1);
410 if (!tag)
411 return; /* error message already given */
413 strbuf_init(&verify_message, 256);
414 if (parse_tag_buffer(tag, extra->value, extra->len))
415 strbuf_addstr(&verify_message, "malformed mergetag\n");
416 else if (is_common_merge(commit) &&
417 !hashcmp(tag->tagged->sha1,
418 commit->parents->next->item->object.sha1))
419 strbuf_addf(&verify_message,
420 "merged tag '%s'\n", tag->tag);
421 else if ((nth = which_parent(tag->tagged->sha1, commit)) < 0)
422 strbuf_addf(&verify_message, "tag %s names a non-parent %s\n",
423 tag->tag, tag->tagged->sha1);
424 else
425 strbuf_addf(&verify_message,
426 "parent #%d, tagged '%s'\n", nth + 1, tag->tag);
427 gpg_message_offset = verify_message.len;
429 payload_size = parse_signature(extra->value, extra->len);
430 status = -1;
431 if (extra->len > payload_size)
432 if (verify_signed_buffer(extra->value, payload_size,
433 extra->value + payload_size,
434 extra->len - payload_size,
435 &verify_message, NULL)) {
436 if (verify_message.len <= gpg_message_offset)
437 strbuf_addstr(&verify_message, "No signature\n");
438 else
439 status = 0;
442 show_sig_lines(opt, status, verify_message.buf);
443 strbuf_release(&verify_message);
446 static void show_mergetag(struct rev_info *opt, struct commit *commit)
448 struct commit_extra_header *extra, *to_free;
450 to_free = read_commit_extra_headers(commit, NULL);
451 for (extra = to_free; extra; extra = extra->next) {
452 if (strcmp(extra->key, "mergetag"))
453 continue; /* not a merge tag */
454 show_one_mergetag(opt, extra, commit);
456 free_commit_extra_headers(to_free);
459 void show_log(struct rev_info *opt)
461 struct strbuf msgbuf = STRBUF_INIT;
462 struct log_info *log = opt->loginfo;
463 struct commit *commit = log->commit, *parent = log->parent;
464 int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
465 const char *extra_headers = opt->extra_headers;
466 struct pretty_print_context ctx = {0};
468 opt->loginfo = NULL;
469 if (!opt->verbose_header) {
470 graph_show_commit(opt->graph);
472 if (!opt->graph)
473 put_revision_mark(opt, commit);
474 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
475 if (opt->print_parents)
476 show_parents(commit, abbrev_commit);
477 if (opt->children.name)
478 show_children(opt, commit, abbrev_commit);
479 show_decorations(opt, commit);
480 if (opt->graph && !graph_is_commit_finished(opt->graph)) {
481 putchar('\n');
482 graph_show_remainder(opt->graph);
484 putchar(opt->diffopt.line_termination);
485 return;
489 * If use_terminator is set, we already handled any record termination
490 * at the end of the last record.
491 * Otherwise, add a diffopt.line_termination character before all
492 * entries but the first. (IOW, as a separator between entries)
494 if (opt->shown_one && !opt->use_terminator) {
496 * If entries are separated by a newline, the output
497 * should look human-readable. If the last entry ended
498 * with a newline, print the graph output before this
499 * newline. Otherwise it will end up as a completely blank
500 * line and will look like a gap in the graph.
502 * If the entry separator is not a newline, the output is
503 * primarily intended for programmatic consumption, and we
504 * never want the extra graph output before the entry
505 * separator.
507 if (opt->diffopt.line_termination == '\n' &&
508 !opt->missing_newline)
509 graph_show_padding(opt->graph);
510 putchar(opt->diffopt.line_termination);
512 opt->shown_one = 1;
515 * If the history graph was requested,
516 * print the graph, up to this commit's line
518 graph_show_commit(opt->graph);
521 * Print header line of header..
524 if (opt->commit_format == CMIT_FMT_EMAIL) {
525 log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
526 &ctx.need_8bit_cte);
527 } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
528 fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
529 if (opt->commit_format != CMIT_FMT_ONELINE)
530 fputs("commit ", stdout);
532 if (!opt->graph)
533 put_revision_mark(opt, commit);
534 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
535 stdout);
536 if (opt->print_parents)
537 show_parents(commit, abbrev_commit);
538 if (opt->children.name)
539 show_children(opt, commit, abbrev_commit);
540 if (parent)
541 printf(" (from %s)",
542 find_unique_abbrev(parent->object.sha1,
543 abbrev_commit));
544 show_decorations(opt, commit);
545 printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET));
546 if (opt->commit_format == CMIT_FMT_ONELINE) {
547 putchar(' ');
548 } else {
549 putchar('\n');
550 graph_show_oneline(opt->graph);
552 if (opt->reflog_info) {
554 * setup_revisions() ensures that opt->reflog_info
555 * and opt->graph cannot both be set,
556 * so we don't need to worry about printing the
557 * graph info here.
559 show_reflog_message(opt->reflog_info,
560 opt->commit_format == CMIT_FMT_ONELINE,
561 opt->date_mode,
562 opt->date_mode_explicit);
563 if (opt->commit_format == CMIT_FMT_ONELINE)
564 return;
568 if (opt->show_signature) {
569 show_signature(opt, commit);
570 show_mergetag(opt, commit);
573 if (!commit->buffer)
574 return;
576 if (opt->show_notes) {
577 int raw;
578 struct strbuf notebuf = STRBUF_INIT;
580 raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
581 format_display_notes(commit->object.sha1, &notebuf,
582 get_log_output_encoding(), raw);
583 ctx.notes_message = notebuf.len
584 ? strbuf_detach(&notebuf, NULL)
585 : xcalloc(1, 1);
589 * And then the pretty-printed message itself
591 if (ctx.need_8bit_cte >= 0 && opt->add_signoff)
592 ctx.need_8bit_cte =
593 has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
594 getenv("GIT_COMMITTER_EMAIL")));
595 ctx.date_mode = opt->date_mode;
596 ctx.date_mode_explicit = opt->date_mode_explicit;
597 ctx.abbrev = opt->diffopt.abbrev;
598 ctx.after_subject = extra_headers;
599 ctx.preserve_subject = opt->preserve_subject;
600 ctx.reflog_info = opt->reflog_info;
601 ctx.fmt = opt->commit_format;
602 ctx.mailmap = opt->mailmap;
603 ctx.color = opt->diffopt.use_color;
604 pretty_print_commit(&ctx, commit, &msgbuf);
606 if (opt->add_signoff)
607 append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP);
609 if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
610 ctx.notes_message && *ctx.notes_message) {
611 if (ctx.fmt == CMIT_FMT_EMAIL) {
612 strbuf_addstr(&msgbuf, "---\n");
613 opt->shown_dashes = 1;
615 strbuf_addstr(&msgbuf, ctx.notes_message);
618 if (opt->show_log_size) {
619 printf("log size %i\n", (int)msgbuf.len);
620 graph_show_oneline(opt->graph);
624 * Set opt->missing_newline if msgbuf doesn't
625 * end in a newline (including if it is empty)
627 if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n')
628 opt->missing_newline = 1;
629 else
630 opt->missing_newline = 0;
632 if (opt->graph)
633 graph_show_commit_msg(opt->graph, &msgbuf);
634 else
635 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
636 if (opt->use_terminator) {
637 if (!opt->missing_newline)
638 graph_show_padding(opt->graph);
639 putchar(opt->diffopt.line_termination);
642 strbuf_release(&msgbuf);
643 free(ctx.notes_message);
646 int log_tree_diff_flush(struct rev_info *opt)
648 opt->shown_dashes = 0;
649 diffcore_std(&opt->diffopt);
651 if (diff_queue_is_empty()) {
652 int saved_fmt = opt->diffopt.output_format;
653 opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
654 diff_flush(&opt->diffopt);
655 opt->diffopt.output_format = saved_fmt;
656 return 0;
659 if (opt->loginfo && !opt->no_commit_id) {
660 show_log(opt);
661 if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
662 opt->verbose_header &&
663 opt->commit_format != CMIT_FMT_ONELINE) {
665 * When showing a verbose header (i.e. log message),
666 * and not in --pretty=oneline format, we would want
667 * an extra newline between the end of log and the
668 * diff/diffstat output for readability.
670 int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
671 if (opt->diffopt.output_prefix) {
672 struct strbuf *msg = NULL;
673 msg = opt->diffopt.output_prefix(&opt->diffopt,
674 opt->diffopt.output_prefix_data);
675 fwrite(msg->buf, msg->len, 1, stdout);
679 * We may have shown three-dashes line early
680 * between notes and the log message, in which
681 * case we only want a blank line after the
682 * notes without (an extra) three-dashes line.
683 * Otherwise, we show the three-dashes line if
684 * we are showing the patch with diffstat, but
685 * in that case, there is no extra blank line
686 * after the three-dashes line.
688 if (!opt->shown_dashes &&
689 (pch & opt->diffopt.output_format) == pch)
690 printf("---");
691 putchar('\n');
694 diff_flush(&opt->diffopt);
695 return 1;
698 static int do_diff_combined(struct rev_info *opt, struct commit *commit)
700 diff_tree_combined_merge(commit, opt->dense_combined_merges, opt);
701 return !opt->loginfo;
705 * Show the diff of a commit.
707 * Return true if we printed any log info messages
709 static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
711 int showed_log;
712 struct commit_list *parents;
713 unsigned const char *sha1;
715 if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
716 return 0;
718 parse_commit(commit);
719 sha1 = commit->tree->object.sha1;
721 /* Root commit? */
722 parents = commit->parents;
723 if (!parents) {
724 if (opt->show_root_diff) {
725 diff_root_tree_sha1(sha1, "", &opt->diffopt);
726 log_tree_diff_flush(opt);
728 return !opt->loginfo;
731 /* More than one parent? */
732 if (parents && parents->next) {
733 if (opt->ignore_merges)
734 return 0;
735 else if (opt->combine_merges)
736 return do_diff_combined(opt, commit);
737 else if (opt->first_parent_only) {
739 * Generate merge log entry only for the first
740 * parent, showing summary diff of the others
741 * we merged _in_.
743 parse_commit(parents->item);
744 diff_tree_sha1(parents->item->tree->object.sha1,
745 sha1, "", &opt->diffopt);
746 log_tree_diff_flush(opt);
747 return !opt->loginfo;
750 /* If we show individual diffs, show the parent info */
751 log->parent = parents->item;
754 showed_log = 0;
755 for (;;) {
756 struct commit *parent = parents->item;
758 parse_commit(parent);
759 diff_tree_sha1(parent->tree->object.sha1,
760 sha1, "", &opt->diffopt);
761 log_tree_diff_flush(opt);
763 showed_log |= !opt->loginfo;
765 /* Set up the log info for the next parent, if any.. */
766 parents = parents->next;
767 if (!parents)
768 break;
769 log->parent = parents->item;
770 opt->loginfo = log;
772 return showed_log;
775 int log_tree_commit(struct rev_info *opt, struct commit *commit)
777 struct log_info log;
778 int shown;
780 log.commit = commit;
781 log.parent = NULL;
782 opt->loginfo = &log;
784 if (opt->line_level_traverse)
785 return line_log_print(opt, commit);
787 shown = log_tree_diff(opt, commit, &log);
788 if (!shown && opt->loginfo && opt->always_show_header) {
789 log.parent = NULL;
790 show_log(opt);
791 shown = 1;
793 opt->loginfo = NULL;
794 maybe_flush_or_die(stdout, "stdout");
795 return shown;