Export some email and pretty-printing functions
These will be used for generating the cover letter in addition to the patch emails. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Daniel Barkalow committed
Feb 18, 2008 at 22:56 UTC
b02bd65f679024ce25afeddf7e96d6d7aea5fca6
4 files changed
+102
-75
commit.h
+15
@@ -71,6 +71,21 @@ extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,
71
int abbrev, const char *subject,
72
const char *after_subject, enum date_mode,
73
int non_ascii_present);
74
+void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
75
+ const char *line, enum date_mode dmode,
76
+ const char *encoding);
77
+void pp_title_line(enum cmit_fmt fmt,
78
+ const char **msg_p,
79
+ struct strbuf *sb,
80
+ const char *subject,
81
+ const char *after_subject,
82
+ const char *encoding,
83
+ int plain_non_ascii);
84
+void pp_remainder(enum cmit_fmt fmt,
85
+ const char **msg_p,
86
+ struct strbuf *sb,
87
+ int indent);
88
+
89
90
/** Removes the first commit from a list sorted by date, and adds all
91
* of its parents.
log-tree.c
+68
-58
@@ -137,6 +137,72 @@ static int has_non_ascii(const char *s)
137
return 0;
138
}
139
140
+void log_write_email_headers(struct rev_info *opt, const char *name,
141
+ const char **subject_p, const char **extra_headers_p)
142
+{
143
+ const char *subject = NULL;
144
+ const char *extra_headers = opt->extra_headers;
145
+ if (opt->total > 0) {
146
+ static char buffer[64];
147
+ snprintf(buffer, sizeof(buffer),
148
+ "Subject: [%s %0*d/%d] ",
149
+ opt->subject_prefix,
150
+ digits_in_number(opt->total),
151
+ opt->nr, opt->total);
152
+ subject = buffer;
153
+ } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
154
+ static char buffer[256];
155
+ snprintf(buffer, sizeof(buffer),
156
+ "Subject: [%s] ",
157
+ opt->subject_prefix);
158
+ subject = buffer;
159
+ } else {
160
+ subject = "Subject: ";
161
+ }
162
+
163
+ printf("From %s Mon Sep 17 00:00:00 2001\n", name);
164
+ if (opt->message_id)
165
+ printf("Message-Id: <%s>\n", opt->message_id);
166
+ if (opt->ref_message_id)
167
+ printf("In-Reply-To: <%s>\nReferences: <%s>\n",
168
+ opt->ref_message_id, opt->ref_message_id);
169
+ if (opt->mime_boundary) {
170
+ static char subject_buffer[1024];
171
+ static char buffer[1024];
172
+ snprintf(subject_buffer, sizeof(subject_buffer) - 1,
173
+ "%s"
174
+ "MIME-Version: 1.0\n"
175
+ "Content-Type: multipart/mixed;"
176
+ " boundary=\"%s%s\"\n"
177
+ "\n"
178
+ "This is a multi-part message in MIME "
179
+ "format.\n"
180
+ "--%s%s\n"
181
+ "Content-Type: text/plain; "
182
+ "charset=UTF-8; format=fixed\n"
183
+ "Content-Transfer-Encoding: 8bit\n\n",
184
+ extra_headers ? extra_headers : "",
185
+ mime_boundary_leader, opt->mime_boundary,
186
+ mime_boundary_leader, opt->mime_boundary);
187
+ extra_headers = subject_buffer;
188
+
189
+ snprintf(buffer, sizeof(buffer) - 1,
190
+ "--%s%s\n"
191
+ "Content-Type: text/x-patch;"
192
+ " name=\"%s.diff\"\n"
193
+ "Content-Transfer-Encoding: 8bit\n"
194
+ "Content-Disposition: %s;"
195
+ " filename=\"%s.diff\"\n\n",
196
+ mime_boundary_leader, opt->mime_boundary,
197
+ name,
198
+ opt->no_inline ? "attachment" : "inline",
199
+ name);
200
+ opt->diffopt.stat_sep = buffer;
201
+ }
202
+ *subject_p = subject;
203
+ *extra_headers_p = extra_headers;
204
+}
205
+
206
void show_log(struct rev_info *opt, const char *sep)
207
{
208
struct strbuf msgbuf;
@@ -186,64 +252,8 @@ void show_log(struct rev_info *opt, const char *sep)
252
*/
253
254
if (opt->commit_format == CMIT_FMT_EMAIL) {
189
- char *sha1 = sha1_to_hex(commit->object.sha1);
190
- if (opt->total > 0) {
191
- static char buffer[64];
192
- snprintf(buffer, sizeof(buffer),
193
- "Subject: [%s %0*d/%d] ",
194
- opt->subject_prefix,
195
- digits_in_number(opt->total),
196
- opt->nr, opt->total);
197
- subject = buffer;
198
- } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
199
- static char buffer[256];
200
- snprintf(buffer, sizeof(buffer),
201
- "Subject: [%s] ",
202
- opt->subject_prefix);
203
- subject = buffer;
204
- } else {
205
- subject = "Subject: ";
206
- }
207
-
208
- printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
209
- if (opt->message_id)
210
- printf("Message-Id: <%s>\n", opt->message_id);
211
- if (opt->ref_message_id)
212
- printf("In-Reply-To: <%s>\nReferences: <%s>\n",
213
- opt->ref_message_id, opt->ref_message_id);
214
- if (opt->mime_boundary) {
215
- static char subject_buffer[1024];
216
- static char buffer[1024];
217
- snprintf(subject_buffer, sizeof(subject_buffer) - 1,
218
- "%s"
219
- "MIME-Version: 1.0\n"
220
- "Content-Type: multipart/mixed;"
221
- " boundary=\"%s%s\"\n"
222
- "\n"
223
- "This is a multi-part message in MIME "
224
- "format.\n"
225
- "--%s%s\n"
226
- "Content-Type: text/plain; "
227
- "charset=UTF-8; format=fixed\n"
228
- "Content-Transfer-Encoding: 8bit\n\n",
229
- extra_headers ? extra_headers : "",
230
- mime_boundary_leader, opt->mime_boundary,
231
- mime_boundary_leader, opt->mime_boundary);
232
- extra_headers = subject_buffer;
233
-
234
- snprintf(buffer, sizeof(buffer) - 1,
235
- "--%s%s\n"
236
- "Content-Type: text/x-patch;"
237
- " name=\"%s.diff\"\n"
238
- "Content-Transfer-Encoding: 8bit\n"
239
- "Content-Disposition: %s;"
240
- " filename=\"%s.diff\"\n\n",
241
- mime_boundary_leader, opt->mime_boundary,
242
- sha1,
243
- opt->no_inline ? "attachment" : "inline",
244
- sha1);
245
- opt->diffopt.stat_sep = buffer;
246
- }
255
+ log_write_email_headers(opt, sha1_to_hex(commit->object.sha1),
256
+ &subject, &extra_headers);
257
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
258
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
259
if (opt->commit_format != CMIT_FMT_ONELINE)
log-tree.h
+2
@@ -13,5 +13,7 @@ int log_tree_commit(struct rev_info *, struct commit *);
13
int log_tree_opt_parse(struct rev_info *, const char **, int);
14
void show_log(struct rev_info *opt, const char *sep);
15
void show_decorations(struct commit *commit);
16
+void log_write_email_headers(struct rev_info *opt, const char *name,
17
+ const char **subject_p, const char **extra_headers_p);
18
19
#endif
pretty.c
+17
-17
@@ -110,9 +110,9 @@ needquote:
110
strbuf_addstr(sb, "?=");
111
}
112
113
-static void add_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
114
- const char *line, enum date_mode dmode,
115
- const char *encoding)
113
+void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
114
+ const char *line, enum date_mode dmode,
115
+ const char *encoding)
116
{
117
char *date;
118
int namelen;
@@ -295,7 +295,7 @@ static void format_person_part(struct strbuf *sb, char part,
295
/*
296
* If it does not even have a '<' and '>', that is
297
* quite a bogus commit author and we discard it;
298
- * this is in line with add_user_info() that is used
298
+ * this is in line with pp_user_info() that is used
299
* in the normal codepath. When end points at the '<'
300
* that we found, it should have matching '>' later,
301
* which means start (beginning of email address) must
@@ -643,23 +643,23 @@ static void pp_header(enum cmit_fmt fmt,
643
*/
644
if (!memcmp(line, "author ", 7)) {
645
strbuf_grow(sb, linelen + 80);
646
- add_user_info("Author", fmt, sb, line + 7, dmode, encoding);
646
+ pp_user_info("Author", fmt, sb, line + 7, dmode, encoding);
647
}
648
if (!memcmp(line, "committer ", 10) &&
649
(fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {
650
strbuf_grow(sb, linelen + 80);
651
- add_user_info("Commit", fmt, sb, line + 10, dmode, encoding);
651
+ pp_user_info("Commit", fmt, sb, line + 10, dmode, encoding);
652
}
653
}
654
}
655
656
-static void pp_title_line(enum cmit_fmt fmt,
657
- const char **msg_p,
658
- struct strbuf *sb,
659
- const char *subject,
660
- const char *after_subject,
661
- const char *encoding,
662
- int plain_non_ascii)
656
+void pp_title_line(enum cmit_fmt fmt,
657
+ const char **msg_p,
658
+ struct strbuf *sb,
659
+ const char *subject,
660
+ const char *after_subject,
661
+ const char *encoding,
662
+ int plain_non_ascii)
663
{
664
struct strbuf title;
665
@@ -708,10 +708,10 @@ static void pp_title_line(enum cmit_fmt fmt,
708
strbuf_release(&title);
709
}
710
711
-static void pp_remainder(enum cmit_fmt fmt,
712
- const char **msg_p,
713
- struct strbuf *sb,
714
- int indent)
711
+void pp_remainder(enum cmit_fmt fmt,
712
+ const char **msg_p,
713
+ struct strbuf *sb,
714
+ int indent)
715
{
716
int first = 1;
717
for (;;) {