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;
23 char *subject
= NULL
, *after_subject
= NULL
;
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
) {
55 char *sha1
= sha1_to_hex(commit
->object
.sha1
);
57 static char buffer
[64];
58 snprintf(buffer
, sizeof(buffer
),
59 "Subject: [PATCH %d/%d] ",
62 } else if (opt
->total
== 0)
63 subject
= "Subject: [PATCH] ";
65 subject
= "Subject: ";
67 printf("From %s Mon Sep 17 00:00:00 2001\n", sha1
);
68 if (opt
->mime_boundary
) {
69 static char subject_buffer
[1024];
70 static char buffer
[1024];
71 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
73 "Content-Type: multipart/mixed;\n"
74 " boundary=\"%s%s\"\n"
76 "This is a multi-part message in MIME "
79 "Content-Type: text/plain; "
80 "charset=UTF-8; format=fixed\n"
81 "Content-Transfer-Encoding: 8bit\n\n",
82 mime_boundary_leader
, opt
->mime_boundary
,
83 mime_boundary_leader
, opt
->mime_boundary
);
84 after_subject
= subject_buffer
;
86 snprintf(buffer
, sizeof(buffer
) - 1,
88 "Content-Type: text/x-patch;\n"
90 "Content-Transfer-Encoding: 8bit\n"
91 "Content-Disposition: inline;\n"
92 " filename=\"%s.diff\"\n\n",
93 mime_boundary_leader
, opt
->mime_boundary
,
95 opt
->diffopt
.stat_sep
= buffer
;
99 opt
->commit_format
== CMIT_FMT_ONELINE
? "" : "commit ",
100 diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
));
102 show_parents(commit
, abbrev_commit
);
105 diff_unique_abbrev(parent
->object
.sha1
,
107 putchar(opt
->commit_format
== CMIT_FMT_ONELINE
? ' ' : '\n');
111 * And then the pretty-printed message itself
113 len
= pretty_print_commit(opt
->commit_format
, commit
, ~0u, this_header
, sizeof(this_header
), abbrev
, subject
, after_subject
);
114 printf("%s%s%s", this_header
, extra
, sep
);
117 int log_tree_diff_flush(struct rev_info
*opt
)
119 diffcore_std(&opt
->diffopt
);
121 if (diff_queue_is_empty()) {
122 int saved_fmt
= opt
->diffopt
.output_format
;
123 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
124 diff_flush(&opt
->diffopt
);
125 opt
->diffopt
.output_format
= saved_fmt
;
129 if (opt
->loginfo
&& !opt
->no_commit_id
)
130 show_log(opt
, opt
->loginfo
, opt
->diffopt
.with_stat
? "---\n" : "\n");
131 diff_flush(&opt
->diffopt
);
135 static int diff_root_tree(struct rev_info
*opt
,
136 const unsigned char *new, const char *base
)
140 struct tree_desc empty
, real
;
142 tree
= read_object_with_reference(new, tree_type
, &real
.size
, NULL
);
144 die("unable to read root tree (%s)", sha1_to_hex(new));
149 retval
= diff_tree(&empty
, &real
, base
, &opt
->diffopt
);
151 log_tree_diff_flush(opt
);
155 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
157 unsigned const char *sha1
= commit
->object
.sha1
;
159 diff_tree_combined_merge(sha1
, opt
->dense_combined_merges
, opt
);
160 return !opt
->loginfo
;
164 * Show the diff of a commit.
166 * Return true if we printed any log info messages
168 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
171 struct commit_list
*parents
;
172 unsigned const char *sha1
= commit
->object
.sha1
;
178 parents
= commit
->parents
;
180 if (opt
->show_root_diff
)
181 diff_root_tree(opt
, sha1
, "");
182 return !opt
->loginfo
;
185 /* More than one parent? */
186 if (parents
&& parents
->next
) {
187 if (opt
->ignore_merges
)
189 else if (opt
->combine_merges
)
190 return do_diff_combined(opt
, commit
);
192 /* If we show individual diffs, show the parent info */
193 log
->parent
= parents
->item
;
198 struct commit
*parent
= parents
->item
;
200 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
201 log_tree_diff_flush(opt
);
203 showed_log
|= !opt
->loginfo
;
205 /* Set up the log info for the next parent, if any.. */
206 parents
= parents
->next
;
209 log
->parent
= parents
->item
;
215 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
224 shown
= log_tree_diff(opt
, commit
, &log
);
225 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
227 show_log(opt
, opt
->loginfo
, "");