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 static int append_signoff(char *buf
, int buf_sz
, int at
, const char *signoff
)
17 int signoff_len
= strlen(signoff
);
18 static const char signed_off_by
[] = "Signed-off-by: ";
21 /* Do we have enough space to add it? */
22 if (buf_sz
- at
<= strlen(signed_off_by
) + signoff_len
+ 3)
25 /* First see if we already have the sign-off by the signer */
27 cp
= strstr(cp
, signed_off_by
);
30 cp
+= strlen(signed_off_by
);
31 if ((cp
+ signoff_len
< buf
+ at
) &&
32 !strncmp(cp
, signoff
, signoff_len
) &&
33 isspace(cp
[signoff_len
]))
34 return at
; /* we already have him */
37 /* Does the last line already end with "^[-A-Za-z]+: [^@]+@"?
38 * If not, add a blank line to separate the message from
39 * the run of Signed-off-by: and Acked-by: lines.
43 int seen_colon
, seen_at
, seen_name
, seen_head
, not_signoff
;
50 while (buf
<= --cp
&& (ch
= *cp
) == '\n')
52 while (!not_signoff
&& buf
<= cp
&& (ch
= *cp
--) != '\n') {
67 if (('A' <= ch
&& ch
<= 'Z') ||
68 ('a' <= ch
&& ch
<= 'z') ||
75 if (not_signoff
|| !seen_head
|| !seen_name
)
79 strcpy(buf
+ at
, signed_off_by
);
80 at
+= strlen(signed_off_by
);
81 strcpy(buf
+ at
, signoff
);
88 void show_log(struct rev_info
*opt
, const char *sep
)
90 static char this_header
[16384];
91 struct log_info
*log
= opt
->loginfo
;
92 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
93 int abbrev
= opt
->diffopt
.abbrev
;
94 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
97 const char *subject
= NULL
, *extra_headers
= opt
->extra_headers
;
100 if (!opt
->verbose_header
) {
101 fputs(diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
103 show_parents(commit
, abbrev_commit
);
104 putchar(opt
->diffopt
.line_termination
);
109 * The "oneline" format has several special cases:
110 * - The pretty-printed commit lacks a newline at the end
111 * of the buffer, but we do want to make sure that we
112 * have a newline there. If the separator isn't already
113 * a newline, add an extra one.
114 * - unlike other log messages, the one-line format does
115 * not have an empty line between entries.
118 if (*sep
!= '\n' && opt
->commit_format
== CMIT_FMT_ONELINE
)
120 if (opt
->shown_one
&& opt
->commit_format
!= CMIT_FMT_ONELINE
)
125 * Print header line of header..
128 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
129 char *sha1
= sha1_to_hex(commit
->object
.sha1
);
130 if (opt
->total
> 0) {
131 static char buffer
[64];
132 snprintf(buffer
, sizeof(buffer
),
133 "Subject: [PATCH %d/%d] ",
134 opt
->nr
, opt
->total
);
136 } else if (opt
->total
== 0)
137 subject
= "Subject: [PATCH] ";
139 subject
= "Subject: ";
141 printf("From %s Mon Sep 17 00:00:00 2001\n", sha1
);
143 printf("Message-Id: <%s>\n", opt
->message_id
);
144 if (opt
->ref_message_id
)
145 printf("In-Reply-To: <%s>\nReferences: <%s>\n",
146 opt
->ref_message_id
, opt
->ref_message_id
);
147 if (opt
->mime_boundary
) {
148 static char subject_buffer
[1024];
149 static char buffer
[1024];
150 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
152 "MIME-Version: 1.0\n"
153 "Content-Type: multipart/mixed;\n"
154 " boundary=\"%s%s\"\n"
156 "This is a multi-part message in MIME "
159 "Content-Type: text/plain; "
160 "charset=UTF-8; format=fixed\n"
161 "Content-Transfer-Encoding: 8bit\n\n",
162 extra_headers
? extra_headers
: "",
163 mime_boundary_leader
, opt
->mime_boundary
,
164 mime_boundary_leader
, opt
->mime_boundary
);
165 extra_headers
= subject_buffer
;
167 snprintf(buffer
, sizeof(buffer
) - 1,
169 "Content-Type: text/x-patch;\n"
170 " name=\"%s.diff\"\n"
171 "Content-Transfer-Encoding: 8bit\n"
172 "Content-Disposition: inline;\n"
173 " filename=\"%s.diff\"\n\n",
174 mime_boundary_leader
, opt
->mime_boundary
,
176 opt
->diffopt
.stat_sep
= buffer
;
180 diff_get_color(opt
->diffopt
.color_diff
, DIFF_COMMIT
),
181 opt
->commit_format
== CMIT_FMT_ONELINE
? "" : "commit ",
182 diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
));
184 show_parents(commit
, abbrev_commit
);
187 diff_unique_abbrev(parent
->object
.sha1
,
190 diff_get_color(opt
->diffopt
.color_diff
, DIFF_RESET
));
191 putchar(opt
->commit_format
== CMIT_FMT_ONELINE
? ' ' : '\n');
195 * And then the pretty-printed message itself
197 len
= pretty_print_commit(opt
->commit_format
, commit
, ~0u, this_header
,
198 sizeof(this_header
), abbrev
, subject
,
199 extra_headers
, opt
->relative_date
);
201 if (opt
->add_signoff
)
202 len
= append_signoff(this_header
, sizeof(this_header
), len
,
204 printf("%s%s%s", this_header
, extra
, sep
);
207 int log_tree_diff_flush(struct rev_info
*opt
)
209 diffcore_std(&opt
->diffopt
);
211 if (diff_queue_is_empty()) {
212 int saved_fmt
= opt
->diffopt
.output_format
;
213 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
214 diff_flush(&opt
->diffopt
);
215 opt
->diffopt
.output_format
= saved_fmt
;
219 if (opt
->loginfo
&& !opt
->no_commit_id
) {
220 /* When showing a verbose header (i.e. log message),
221 * and not in --pretty=oneline format, we would want
222 * an extra newline between the end of log and the
223 * output for readability.
225 show_log(opt
, opt
->diffopt
.msg_sep
);
226 if (opt
->verbose_header
&&
227 opt
->commit_format
!= CMIT_FMT_ONELINE
) {
228 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
229 if ((pch
& opt
->diffopt
.output_format
) == pch
)
230 printf("---%c", opt
->diffopt
.line_termination
);
232 putchar(opt
->diffopt
.line_termination
);
235 diff_flush(&opt
->diffopt
);
239 static int diff_root_tree(struct rev_info
*opt
,
240 const unsigned char *new, const char *base
)
244 struct tree_desc empty
, real
;
246 tree
= read_object_with_reference(new, tree_type
, &real
.size
, NULL
);
248 die("unable to read root tree (%s)", sha1_to_hex(new));
253 retval
= diff_tree(&empty
, &real
, base
, &opt
->diffopt
);
255 log_tree_diff_flush(opt
);
259 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
261 unsigned const char *sha1
= commit
->object
.sha1
;
263 diff_tree_combined_merge(sha1
, opt
->dense_combined_merges
, opt
);
264 return !opt
->loginfo
;
268 * Show the diff of a commit.
270 * Return true if we printed any log info messages
272 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
275 struct commit_list
*parents
;
276 unsigned const char *sha1
= commit
->object
.sha1
;
282 parents
= commit
->parents
;
284 if (opt
->show_root_diff
)
285 diff_root_tree(opt
, sha1
, "");
286 return !opt
->loginfo
;
289 /* More than one parent? */
290 if (parents
&& parents
->next
) {
291 if (opt
->ignore_merges
)
293 else if (opt
->combine_merges
)
294 return do_diff_combined(opt
, commit
);
296 /* If we show individual diffs, show the parent info */
297 log
->parent
= parents
->item
;
302 struct commit
*parent
= parents
->item
;
304 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
305 log_tree_diff_flush(opt
);
307 showed_log
|= !opt
->loginfo
;
309 /* Set up the log info for the next parent, if any.. */
310 parents
= parents
->next
;
313 log
->parent
= parents
->item
;
319 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
328 shown
= log_tree_diff(opt
, commit
, &log
);
329 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {