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
+ 2)
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 strcpy(buf
+ at
, signed_off_by
);
38 at
+= strlen(signed_off_by
);
39 strcpy(buf
+ at
, signoff
);
46 void show_log(struct rev_info
*opt
, const char *sep
)
48 static char this_header
[16384];
49 struct log_info
*log
= opt
->loginfo
;
50 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
51 int abbrev
= opt
->diffopt
.abbrev
;
52 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
55 const char *subject
= NULL
, *extra_headers
= opt
->extra_headers
;
58 if (!opt
->verbose_header
) {
59 fputs(diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
61 show_parents(commit
, abbrev_commit
);
67 * The "oneline" format has several special cases:
68 * - The pretty-printed commit lacks a newline at the end
69 * of the buffer, but we do want to make sure that we
70 * have a newline there. If the separator isn't already
71 * a newline, add an extra one.
72 * - unlike other log messages, the one-line format does
73 * not have an empty line between entries.
76 if (*sep
!= '\n' && opt
->commit_format
== CMIT_FMT_ONELINE
)
78 if (opt
->shown_one
&& opt
->commit_format
!= CMIT_FMT_ONELINE
)
83 * Print header line of header..
86 if (opt
->commit_format
== CMIT_FMT_EMAIL
) {
87 char *sha1
= sha1_to_hex(commit
->object
.sha1
);
89 static char buffer
[64];
90 snprintf(buffer
, sizeof(buffer
),
91 "Subject: [PATCH %d/%d] ",
94 } else if (opt
->total
== 0)
95 subject
= "Subject: [PATCH] ";
97 subject
= "Subject: ";
99 printf("From %s Mon Sep 17 00:00:00 2001\n", sha1
);
101 printf("Message-Id: <%s>\n", opt
->message_id
);
102 if (opt
->ref_message_id
)
103 printf("In-Reply-To: <%s>\nReferences: <%s>\n",
104 opt
->ref_message_id
, opt
->ref_message_id
);
105 if (opt
->mime_boundary
) {
106 static char subject_buffer
[1024];
107 static char buffer
[1024];
108 snprintf(subject_buffer
, sizeof(subject_buffer
) - 1,
110 "MIME-Version: 1.0\n"
111 "Content-Type: multipart/mixed;\n"
112 " boundary=\"%s%s\"\n"
114 "This is a multi-part message in MIME "
117 "Content-Type: text/plain; "
118 "charset=UTF-8; format=fixed\n"
119 "Content-Transfer-Encoding: 8bit\n\n",
120 extra_headers
? extra_headers
: "",
121 mime_boundary_leader
, opt
->mime_boundary
,
122 mime_boundary_leader
, opt
->mime_boundary
);
123 extra_headers
= subject_buffer
;
125 snprintf(buffer
, sizeof(buffer
) - 1,
127 "Content-Type: text/x-patch;\n"
128 " name=\"%s.diff\"\n"
129 "Content-Transfer-Encoding: 8bit\n"
130 "Content-Disposition: inline;\n"
131 " filename=\"%s.diff\"\n\n",
132 mime_boundary_leader
, opt
->mime_boundary
,
134 opt
->diffopt
.stat_sep
= buffer
;
138 diff_get_color(opt
->diffopt
.color_diff
, DIFF_COMMIT
),
139 opt
->commit_format
== CMIT_FMT_ONELINE
? "" : "commit ",
140 diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
));
142 show_parents(commit
, abbrev_commit
);
145 diff_unique_abbrev(parent
->object
.sha1
,
148 diff_get_color(opt
->diffopt
.color_diff
, DIFF_RESET
));
149 putchar(opt
->commit_format
== CMIT_FMT_ONELINE
? ' ' : '\n');
153 * And then the pretty-printed message itself
155 len
= pretty_print_commit(opt
->commit_format
, commit
, ~0u, this_header
, sizeof(this_header
), abbrev
, subject
, extra_headers
);
157 if (opt
->add_signoff
)
158 len
= append_signoff(this_header
, sizeof(this_header
), len
,
160 printf("%s%s%s", this_header
, extra
, sep
);
163 int log_tree_diff_flush(struct rev_info
*opt
)
165 diffcore_std(&opt
->diffopt
);
167 if (diff_queue_is_empty()) {
168 int saved_fmt
= opt
->diffopt
.output_format
;
169 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
170 diff_flush(&opt
->diffopt
);
171 opt
->diffopt
.output_format
= saved_fmt
;
175 if (opt
->loginfo
&& !opt
->no_commit_id
) {
176 /* When showing a verbose header (i.e. log message),
177 * and not in --pretty=oneline format, we would want
178 * an extra newline between the end of log and the
179 * output for readability.
181 show_log(opt
, opt
->diffopt
.msg_sep
);
182 if (opt
->verbose_header
&&
183 opt
->commit_format
!= CMIT_FMT_ONELINE
) {
184 int pch
= DIFF_FORMAT_DIFFSTAT
| DIFF_FORMAT_PATCH
;
185 if ((pch
& opt
->diffopt
.output_format
) == pch
)
186 printf("---%c", opt
->diffopt
.line_termination
);
188 putchar(opt
->diffopt
.line_termination
);
191 diff_flush(&opt
->diffopt
);
195 static int diff_root_tree(struct rev_info
*opt
,
196 const unsigned char *new, const char *base
)
200 struct tree_desc empty
, real
;
202 tree
= read_object_with_reference(new, tree_type
, &real
.size
, NULL
);
204 die("unable to read root tree (%s)", sha1_to_hex(new));
209 retval
= diff_tree(&empty
, &real
, base
, &opt
->diffopt
);
211 log_tree_diff_flush(opt
);
215 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
217 unsigned const char *sha1
= commit
->object
.sha1
;
219 diff_tree_combined_merge(sha1
, opt
->dense_combined_merges
, opt
);
220 return !opt
->loginfo
;
224 * Show the diff of a commit.
226 * Return true if we printed any log info messages
228 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
231 struct commit_list
*parents
;
232 unsigned const char *sha1
= commit
->object
.sha1
;
238 parents
= commit
->parents
;
240 if (opt
->show_root_diff
)
241 diff_root_tree(opt
, sha1
, "");
242 return !opt
->loginfo
;
245 /* More than one parent? */
246 if (parents
&& parents
->next
) {
247 if (opt
->ignore_merges
)
249 else if (opt
->combine_merges
)
250 return do_diff_combined(opt
, commit
);
252 /* If we show individual diffs, show the parent info */
253 log
->parent
= parents
->item
;
258 struct commit
*parent
= parents
->item
;
260 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
261 log_tree_diff_flush(opt
);
263 showed_log
|= !opt
->loginfo
;
265 /* Set up the log info for the next parent, if any.. */
266 parents
= parents
->next
;
269 log
->parent
= parents
->item
;
275 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
284 shown
= log_tree_diff(opt
, commit
, &log
);
285 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {