5 #include "reflog-walk.h"
7 static void show_parents(struct commit
*commit
, int abbrev
)
10 for (p
= commit
->parents
; p
; p
= p
->next
) {
11 struct commit
*parent
= p
->item
;
12 printf(" %s", diff_unique_abbrev(parent
->object
.sha1
, abbrev
));
17 * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
18 * Signed-off-by: and Acked-by: lines.
20 static int detect_any_signoff(char *letter
, int size
)
29 while (letter
<= --cp
&& (ch
= *cp
) == '\n')
32 while (letter
<= cp
) {
51 if (('A' <= ch
&& ch
<= 'Z') ||
52 ('a' <= ch
&& ch
<= 'z') ||
57 /* no empty last line doesn't match */
60 return seen_head
&& seen_name
;
63 static int append_signoff(char *buf
, int buf_sz
, int at
, const char *signoff
)
65 static const char signed_off_by
[] = "Signed-off-by: ";
66 int signoff_len
= strlen(signoff
);
70 /* Do we have enough space to add it? */
71 if (buf_sz
- at
<= strlen(signed_off_by
) + signoff_len
+ 3)
74 /* First see if we already have the sign-off by the signer */
75 while ((cp
= strstr(cp
, signed_off_by
))) {
79 cp
+= strlen(signed_off_by
);
80 if (cp
+ signoff_len
>= buf
+ at
)
82 if (strncmp(cp
, signoff
, signoff_len
))
84 if (!isspace(cp
[signoff_len
]))
86 /* we already have him */
91 has_signoff
= detect_any_signoff(buf
, at
);
96 strcpy(buf
+ at
, signed_off_by
);
97 at
+= strlen(signed_off_by
);
98 strcpy(buf
+ at
, signoff
);
105 void show_log(struct rev_info
*opt
, const char *sep
)
107 static char this_header
[16384];
108 struct log_info
*log
= opt
->loginfo
;
109 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
110 int abbrev
= opt
->diffopt
.abbrev
;
111 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
114 const char *subject
= NULL
, *extra_headers
= opt
->extra_headers
;
117 if (!opt
->verbose_header
) {
118 if (opt
->left_right
) {
119 if (commit
->object
.flags
& BOUNDARY
)
121 else if (commit
->object
.flags
& SYMMETRIC_LEFT
)
126 fputs(diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
128 show_parents(commit
, abbrev_commit
);
129 putchar(opt
->diffopt
.line_termination
);
134 * The "oneline" format has several special cases:
135 * - The pretty-printed commit lacks a newline at the end
136 * of the buffer, but we do want to make sure that we
137 * have a newline there. If the separator isn't already
138 * a newline, add an extra one.
139 * - unlike other log messages, the one-line format does
140 * not have an empty line between entries.
143 if (*sep
!= '\n' && opt
->commit_format
== CMIT_FMT_ONELINE
)
145 if (opt
->shown_one
&& opt
->commit_format
!= CMIT_FMT_ONELINE
)
150 * Print header line of header..
153 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
154 char *sha1
= sha1_to_hex(commit
->object
.sha1
);
155 if (opt
->total
> 0) {
156 static char buffer
[64];
157 snprintf(buffer
, sizeof(buffer
),
158 "Subject: [PATCH %d/%d] ",
159 opt
->nr
, opt
->total
);
161 } else if (opt
->total
== 0)
162 subject
= "Subject: [PATCH] ";
164 subject
= "Subject: ";
166 printf("From %s Mon Sep 17 00:00:00 2001\n", sha1
);
168 printf("Message-Id: <%s>\n", opt
->message_id
);
169 if (opt
->ref_message_id
)
170 printf("In-Reply-To: <%s>\nReferences: <%s>\n",
171 opt
->ref_message_id
, opt
->ref_message_id
);
172 if (opt
->mime_boundary
) {
173 static char subject_buffer
[1024];
174 static char buffer
[1024];
175 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
177 "MIME-Version: 1.0\n"
178 "Content-Type: multipart/mixed;\n"
179 " boundary=\"%s%s\"\n"
181 "This is a multi-part message in MIME "
184 "Content-Type: text/plain; "
185 "charset=UTF-8; format=fixed\n"
186 "Content-Transfer-Encoding: 8bit\n\n",
187 extra_headers
? extra_headers
: "",
188 mime_boundary_leader
, opt
->mime_boundary
,
189 mime_boundary_leader
, opt
->mime_boundary
);
190 extra_headers
= subject_buffer
;
192 snprintf(buffer
, sizeof(buffer
) - 1,
194 "Content-Type: text/x-patch;\n"
195 " name=\"%s.diff\"\n"
196 "Content-Transfer-Encoding: 8bit\n"
197 "Content-Disposition: inline;\n"
198 " filename=\"%s.diff\"\n\n",
199 mime_boundary_leader
, opt
->mime_boundary
,
201 opt
->diffopt
.stat_sep
= buffer
;
204 fputs(diff_get_color(opt
->diffopt
.color_diff
, DIFF_COMMIT
),
206 if (opt
->commit_format
!= CMIT_FMT_ONELINE
)
207 fputs("commit ", stdout
);
208 if (opt
->left_right
) {
209 if (commit
->object
.flags
& BOUNDARY
)
211 else if (commit
->object
.flags
& SYMMETRIC_LEFT
)
216 fputs(diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
),
219 show_parents(commit
, abbrev_commit
);
222 diff_unique_abbrev(parent
->object
.sha1
,
225 diff_get_color(opt
->diffopt
.color_diff
, DIFF_RESET
));
226 putchar(opt
->commit_format
== CMIT_FMT_ONELINE
? ' ' : '\n');
227 if (opt
->reflog_info
)
228 show_reflog_message(opt
->reflog_info
);
232 * And then the pretty-printed message itself
234 len
= pretty_print_commit(opt
->commit_format
, commit
, ~0u, this_header
,
235 sizeof(this_header
), abbrev
, subject
,
236 extra_headers
, opt
->relative_date
);
238 if (opt
->add_signoff
)
239 len
= append_signoff(this_header
, sizeof(this_header
), len
,
241 printf("%s%s%s", this_header
, extra
, sep
);
244 int log_tree_diff_flush(struct rev_info
*opt
)
246 diffcore_std(&opt
->diffopt
);
248 if (diff_queue_is_empty()) {
249 int saved_fmt
= opt
->diffopt
.output_format
;
250 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
251 diff_flush(&opt
->diffopt
);
252 opt
->diffopt
.output_format
= saved_fmt
;
256 if (opt
->loginfo
&& !opt
->no_commit_id
) {
257 /* When showing a verbose header (i.e. log message),
258 * and not in --pretty=oneline format, we would want
259 * an extra newline between the end of log and the
260 * output for readability.
262 show_log(opt
, opt
->diffopt
.msg_sep
);
263 if (opt
->verbose_header
&&
264 opt
->commit_format
!= CMIT_FMT_ONELINE
) {
265 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
266 if ((pch
& opt
->diffopt
.output_format
) == pch
)
267 printf("---%c", opt
->diffopt
.line_termination
);
269 putchar(opt
->diffopt
.line_termination
);
272 diff_flush(&opt
->diffopt
);
276 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
278 unsigned const char *sha1
= commit
->object
.sha1
;
280 diff_tree_combined_merge(sha1
, opt
->dense_combined_merges
, opt
);
281 return !opt
->loginfo
;
285 * Show the diff of a commit.
287 * Return true if we printed any log info messages
289 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
292 struct commit_list
*parents
;
293 unsigned const char *sha1
= commit
->object
.sha1
;
299 parents
= commit
->parents
;
301 if (opt
->show_root_diff
) {
302 diff_root_tree_sha1(sha1
, "", &opt
->diffopt
);
303 log_tree_diff_flush(opt
);
305 return !opt
->loginfo
;
308 /* More than one parent? */
309 if (parents
&& parents
->next
) {
310 if (opt
->ignore_merges
)
312 else if (opt
->combine_merges
)
313 return do_diff_combined(opt
, commit
);
315 /* If we show individual diffs, show the parent info */
316 log
->parent
= parents
->item
;
321 struct commit
*parent
= parents
->item
;
323 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
324 log_tree_diff_flush(opt
);
326 showed_log
|= !opt
->loginfo
;
328 /* Set up the log info for the next parent, if any.. */
329 parents
= parents
->next
;
332 log
->parent
= parents
->item
;
338 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
347 shown
= log_tree_diff(opt
, commit
, &log
);
348 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {