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
, sizeof(this_header
), abbrev
, subject
, extra_headers
);
199 if (opt
->add_signoff
)
200 len
= append_signoff(this_header
, sizeof(this_header
), len
,
202 printf("%s%s%s", this_header
, extra
, sep
);
205 int log_tree_diff_flush(struct rev_info
*opt
)
207 diffcore_std(&opt
->diffopt
);
209 if (diff_queue_is_empty()) {
210 int saved_fmt
= opt
->diffopt
.output_format
;
211 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
212 diff_flush(&opt
->diffopt
);
213 opt
->diffopt
.output_format
= saved_fmt
;
217 if (opt
->loginfo
&& !opt
->no_commit_id
) {
218 /* When showing a verbose header (i.e. log message),
219 * and not in --pretty=oneline format, we would want
220 * an extra newline between the end of log and the
221 * output for readability.
223 show_log(opt
, opt
->diffopt
.msg_sep
);
224 if (opt
->verbose_header
&&
225 opt
->commit_format
!= CMIT_FMT_ONELINE
) {
226 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
227 if ((pch
& opt
->diffopt
.output_format
) == pch
)
228 printf("---%c", opt
->diffopt
.line_termination
);
230 putchar(opt
->diffopt
.line_termination
);
233 diff_flush(&opt
->diffopt
);
237 static int diff_root_tree(struct rev_info
*opt
,
238 const unsigned char *new, const char *base
)
242 struct tree_desc empty
, real
;
244 tree
= read_object_with_reference(new, tree_type
, &real
.size
, NULL
);
246 die("unable to read root tree (%s)", sha1_to_hex(new));
251 retval
= diff_tree(&empty
, &real
, base
, &opt
->diffopt
);
253 log_tree_diff_flush(opt
);
257 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
259 unsigned const char *sha1
= commit
->object
.sha1
;
261 diff_tree_combined_merge(sha1
, opt
->dense_combined_merges
, opt
);
262 return !opt
->loginfo
;
266 * Show the diff of a commit.
268 * Return true if we printed any log info messages
270 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
273 struct commit_list
*parents
;
274 unsigned const char *sha1
= commit
->object
.sha1
;
280 parents
= commit
->parents
;
282 if (opt
->show_root_diff
)
283 diff_root_tree(opt
, sha1
, "");
284 return !opt
->loginfo
;
287 /* More than one parent? */
288 if (parents
&& parents
->next
) {
289 if (opt
->ignore_merges
)
291 else if (opt
->combine_merges
)
292 return do_diff_combined(opt
, commit
);
294 /* If we show individual diffs, show the parent info */
295 log
->parent
= parents
->item
;
300 struct commit
*parent
= parents
->item
;
302 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
303 log_tree_diff_flush(opt
);
305 showed_log
|= !opt
->loginfo
;
307 /* Set up the log info for the next parent, if any.. */
308 parents
= parents
->next
;
311 log
->parent
= parents
->item
;
317 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
326 shown
= log_tree_diff(opt
, commit
, &log
);
327 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {