6 static void show_parents(struct commit *commit, int abbrev)
9 for (p = commit->parents; p ; p = p->next) {
10 struct commit *parent = p->item;
11 printf(" %s", diff_unique_abbrev(parent->object.sha1, abbrev));
15 void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
17 static char this_header[16384];
18 struct commit *commit = log->commit, *parent = log->parent;
19 int abbrev = opt->diffopt.abbrev;
20 int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
25 if (!opt->verbose_header) {
26 fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
28 show_parents(commit, abbrev_commit);
34 * The "oneline" format has several special cases:
35 * - The pretty-printed commit lacks a newline at the end
36 * of the buffer, but we do want to make sure that we
37 * have a newline there. If the separator isn't already
38 * a newline, add an extra one.
39 * - unlike other log messages, the one-line format does
40 * not have an empty line between entries.
43 if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
45 if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
50 * Print header line of header..
53 opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
54 diff_unique_abbrev(commit->object.sha1, abbrev_commit));
56 show_parents(commit, abbrev_commit);
58 printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit));
59 putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
62 * And then the pretty-printed message itself
64 len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev);
65 printf("%s%s%s", this_header, extra, sep);
68 int log_tree_diff_flush(struct rev_info *opt)
70 diffcore_std(&opt->diffopt);
72 if (diff_queue_is_empty()) {
73 int saved_fmt = opt->diffopt.output_format;
74 opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
75 diff_flush(&opt->diffopt);
76 opt->diffopt.output_format = saved_fmt;
80 if (opt->loginfo && !opt->no_commit_id)
81 show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "---\n" : "\n");
82 diff_flush(&opt->diffopt);
86 static int diff_root_tree(struct rev_info *opt,
87 const unsigned char *new, const char *base)
91 struct tree_desc empty, real;
93 tree = read_object_with_reference(new, tree_type, &real.size, NULL);
95 die("unable to read root tree (%s)", sha1_to_hex(new));
100 retval = diff_tree(&empty, &real, base, &opt->diffopt);
102 log_tree_diff_flush(opt);
106 static int do_diff_combined(struct rev_info *opt, struct commit *commit)
108 unsigned const char *sha1 = commit->object.sha1;
110 diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
111 return !opt->loginfo;
115 * Show the diff of a commit.
117 * Return true if we printed any log info messages
119 static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
122 struct commit_list *parents;
123 unsigned const char *sha1 = commit->object.sha1;
129 parents = commit->parents;
131 if (opt->show_root_diff)
132 diff_root_tree(opt, sha1, "");
133 return !opt->loginfo;
136 /* More than one parent? */
137 if (parents && parents->next) {
138 if (opt->ignore_merges)
140 else if (opt->combine_merges)
141 return do_diff_combined(opt, commit);
143 /* If we show individual diffs, show the parent info */
144 log->parent = parents->item;
149 struct commit *parent = parents->item;
151 diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
152 log_tree_diff_flush(opt);
154 showed_log |= !opt->loginfo;
156 /* Set up the log info for the next parent, if any.. */
157 parents = parents->next;
160 log->parent = parents->item;
166 int log_tree_commit(struct rev_info *opt, struct commit *commit)
174 if (!log_tree_diff(opt, commit, &log) && opt->loginfo && opt->always_show_header) {
176 show_log(opt, opt->loginfo, "");