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;
26 if (!opt->verbose_header) {
27 fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
29 show_parents(commit, abbrev_commit);
35 * The "oneline" format has several special cases:
36 * - The pretty-printed commit lacks a newline at the end
37 * of the buffer, but we do want to make sure that we
38 * have a newline there. If the separator isn't already
39 * a newline, add an extra one.
40 * - unlike other log messages, the one-line format does
41 * not have an empty line between entries.
44 if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
46 if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
51 * Print header line of header..
54 if (opt->commit_format == CMIT_FMT_EMAIL) {
56 static char buffer[64];
57 snprintf(buffer, sizeof(buffer),
58 "Subject: [PATCH %d/%d] ",
61 } else if (opt->total == 0)
62 subject = "Subject: [PATCH] ";
64 subject = "Subject: ";
66 printf("From %s Thu Apr 7 15:13:13 2005\n",
67 sha1_to_hex(commit->object.sha1));
70 opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
71 diff_unique_abbrev(commit->object.sha1, abbrev_commit));
73 show_parents(commit, abbrev_commit);
76 diff_unique_abbrev(parent->object.sha1,
78 putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
82 * And then the pretty-printed message itself
84 len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject);
85 printf("%s%s%s", this_header, extra, sep);
88 int log_tree_diff_flush(struct rev_info *opt)
90 diffcore_std(&opt->diffopt);
92 if (diff_queue_is_empty()) {
93 int saved_fmt = opt->diffopt.output_format;
94 opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
95 diff_flush(&opt->diffopt);
96 opt->diffopt.output_format = saved_fmt;
100 if (opt->loginfo && !opt->no_commit_id)
101 show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "---\n" : "\n");
102 diff_flush(&opt->diffopt);
106 static int diff_root_tree(struct rev_info *opt,
107 const unsigned char *new, const char *base)
111 struct tree_desc empty, real;
113 tree = read_object_with_reference(new, tree_type, &real.size, NULL);
115 die("unable to read root tree (%s)", sha1_to_hex(new));
120 retval = diff_tree(&empty, &real, base, &opt->diffopt);
122 log_tree_diff_flush(opt);
126 static int do_diff_combined(struct rev_info *opt, struct commit *commit)
128 unsigned const char *sha1 = commit->object.sha1;
130 diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
131 return !opt->loginfo;
135 * Show the diff of a commit.
137 * Return true if we printed any log info messages
139 static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
142 struct commit_list *parents;
143 unsigned const char *sha1 = commit->object.sha1;
149 parents = commit->parents;
151 if (opt->show_root_diff)
152 diff_root_tree(opt, sha1, "");
153 return !opt->loginfo;
156 /* More than one parent? */
157 if (parents && parents->next) {
158 if (opt->ignore_merges)
160 else if (opt->combine_merges)
161 return do_diff_combined(opt, commit);
163 /* If we show individual diffs, show the parent info */
164 log->parent = parents->item;
169 struct commit *parent = parents->item;
171 diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
172 log_tree_diff_flush(opt);
174 showed_log |= !opt->loginfo;
176 /* Set up the log info for the next parent, if any.. */
177 parents = parents->next;
180 log->parent = parents->item;
186 int log_tree_commit(struct rev_info *opt, struct commit *commit)
195 shown = log_tree_diff(opt, commit, &log);
196 if (!shown && opt->loginfo && opt->always_show_header) {
198 show_log(opt, opt->loginfo, "");