]> git.ipfire.org Git - thirdparty/git.git/blame - pretty.c
clean up calling conventions for pretty.c functions
[thirdparty/git.git] / pretty.c
CommitLineData
93fc05eb
JS
1#include "cache.h"
2#include "commit.h"
93fc05eb
JS
3#include "utf8.h"
4#include "diff.h"
5#include "revision.h"
c455c87c 6#include "string-list.h"
e0cbc397 7#include "mailmap.h"
3b3d443f 8#include "log-tree.h"
a97a7468 9#include "notes.h"
c002922a 10#include "color.h"
8f8f5476 11#include "reflog-walk.h"
93fc05eb 12
93fc05eb 13static char *user_format;
40957891
WP
14static struct cmt_fmt_map {
15 const char *name;
16 enum cmit_fmt format;
17 int is_tformat;
2d7671ef
WP
18 int is_alias;
19 const char *user_format;
40957891 20} *commit_formats;
8028184e 21static size_t builtin_formats_len;
40957891 22static size_t commit_formats_len;
8028184e 23static size_t commit_formats_alloc;
40957891 24static struct cmt_fmt_map *find_commit_format(const char *sought);
93fc05eb 25
36407548
NS
26static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)
27{
28 free(user_format);
29 user_format = xstrdup(cp);
30 if (is_tformat)
31 rev->use_terminator = 1;
32 rev->commit_format = CMIT_FMT_USERFORMAT;
33}
34
8028184e 35static int git_pretty_formats_config(const char *var, const char *value, void *cb)
93fc05eb 36{
8028184e
WP
37 struct cmt_fmt_map *commit_format = NULL;
38 const char *name;
39 const char *fmt;
93fc05eb 40 int i;
8028184e
WP
41
42 if (prefixcmp(var, "pretty."))
43 return 0;
44
45 name = var + strlen("pretty.");
46 for (i = 0; i < builtin_formats_len; i++) {
47 if (!strcmp(commit_formats[i].name, name))
48 return 0;
49 }
50
51 for (i = builtin_formats_len; i < commit_formats_len; i++) {
52 if (!strcmp(commit_formats[i].name, name)) {
53 commit_format = &commit_formats[i];
54 break;
55 }
56 }
57
58 if (!commit_format) {
59 ALLOC_GROW(commit_formats, commit_formats_len+1,
60 commit_formats_alloc);
61 commit_format = &commit_formats[commit_formats_len];
95a2618f 62 memset(commit_format, 0, sizeof(*commit_format));
8028184e
WP
63 commit_formats_len++;
64 }
65
66 commit_format->name = xstrdup(name);
67 commit_format->format = CMIT_FMT_USERFORMAT;
68 git_config_string(&fmt, var, value);
69 if (!prefixcmp(fmt, "format:") || !prefixcmp(fmt, "tformat:")) {
70 commit_format->is_tformat = fmt[0] == 't';
71 fmt = strchr(fmt, ':') + 1;
72 } else if (strchr(fmt, '%'))
73 commit_format->is_tformat = 1;
74 else
75 commit_format->is_alias = 1;
76 commit_format->user_format = fmt;
77
78 return 0;
79}
80
40957891 81static void setup_commit_formats(void)
93fc05eb 82{
40957891
WP
83 struct cmt_fmt_map builtin_formats[] = {
84 { "raw", CMIT_FMT_RAW, 0 },
85 { "medium", CMIT_FMT_MEDIUM, 0 },
86 { "short", CMIT_FMT_SHORT, 0 },
87 { "email", CMIT_FMT_EMAIL, 0 },
88 { "fuller", CMIT_FMT_FULLER, 0 },
89 { "full", CMIT_FMT_FULL, 0 },
90 { "oneline", CMIT_FMT_ONELINE, 1 }
4da45bef 91 };
40957891 92 commit_formats_len = ARRAY_SIZE(builtin_formats);
8028184e
WP
93 builtin_formats_len = commit_formats_len;
94 ALLOC_GROW(commit_formats, commit_formats_len, commit_formats_alloc);
40957891
WP
95 memcpy(commit_formats, builtin_formats,
96 sizeof(*builtin_formats)*ARRAY_SIZE(builtin_formats));
8028184e
WP
97
98 git_config(git_pretty_formats_config, NULL);
40957891
WP
99}
100
2d7671ef
WP
101static struct cmt_fmt_map *find_commit_format_recursive(const char *sought,
102 const char *original,
103 int num_redirections)
40957891
WP
104{
105 struct cmt_fmt_map *found = NULL;
106 size_t found_match_len = 0;
107 int i;
108
2d7671ef
WP
109 if (num_redirections >= commit_formats_len)
110 die("invalid --pretty format: "
111 "'%s' references an alias which points to itself",
112 original);
40957891
WP
113
114 for (i = 0; i < commit_formats_len; i++) {
115 size_t match_len;
116
117 if (prefixcmp(commit_formats[i].name, sought))
118 continue;
119
120 match_len = strlen(commit_formats[i].name);
121 if (found == NULL || found_match_len > match_len) {
122 found = &commit_formats[i];
123 found_match_len = match_len;
124 }
125 }
2d7671ef
WP
126
127 if (found && found->is_alias) {
128 found = find_commit_format_recursive(found->user_format,
129 original,
130 num_redirections+1);
131 }
132
40957891
WP
133 return found;
134}
135
2d7671ef
WP
136static struct cmt_fmt_map *find_commit_format(const char *sought)
137{
138 if (!commit_formats)
139 setup_commit_formats();
140
141 return find_commit_format_recursive(sought, sought, 0);
142}
143
40957891
WP
144void get_commit_format(const char *arg, struct rev_info *rev)
145{
146 struct cmt_fmt_map *commit_format;
93fc05eb 147
4da45bef
JH
148 rev->use_terminator = 0;
149 if (!arg || !*arg) {
150 rev->commit_format = CMIT_FMT_DEFAULT;
151 return;
152 }
4da45bef 153 if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) {
36407548 154 save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
4da45bef 155 return;
93fc05eb 156 }
40957891 157
36407548
NS
158 if (strchr(arg, '%')) {
159 save_user_format(rev, arg, 1);
160 return;
161 }
93fc05eb 162
40957891
WP
163 commit_format = find_commit_format(arg);
164 if (!commit_format)
165 die("invalid --pretty format: %s", arg);
166
167 rev->commit_format = commit_format->format;
168 rev->use_terminator = commit_format->is_tformat;
8028184e
WP
169 if (commit_format->format == CMIT_FMT_USERFORMAT) {
170 save_user_format(rev, commit_format->user_format,
171 commit_format->is_tformat);
172 }
93fc05eb
JS
173}
174
175/*
176 * Generic support for pretty-printing the header
177 */
178static int get_one_line(const char *msg)
179{
180 int ret = 0;
181
182 for (;;) {
183 char c = *msg++;
184 if (!c)
185 break;
186 ret++;
187 if (c == '\n')
188 break;
189 }
190 return ret;
191}
192
193/* High bit set, or ISO-2022-INT */
cc571142 194static int non_ascii(int ch)
93fc05eb 195{
c2e9364a 196 return !isascii(ch) || ch == '\033';
93fc05eb
JS
197}
198
28e9cf65
JS
199int has_non_ascii(const char *s)
200{
201 int ch;
202 if (!s)
203 return 0;
204 while ((ch = *s++) != '\0') {
205 if (non_ascii(ch))
206 return 1;
207 }
208 return 0;
209}
210
93fc05eb
JS
211static int is_rfc2047_special(char ch)
212{
213 return (non_ascii(ch) || (ch == '=') || (ch == '?') || (ch == '_'));
214}
215
216static void add_rfc2047(struct strbuf *sb, const char *line, int len,
217 const char *encoding)
218{
a1f6baa5
JK
219 static const int max_length = 78; /* per rfc2822 */
220 int i;
221 int line_len;
222
223 /* How many bytes are already used on the current line? */
224 for (i = sb->len - 1; i >= 0; i--)
225 if (sb->buf[i] == '\n')
226 break;
227 line_len = sb->len - (i+1);
93fc05eb
JS
228
229 for (i = 0; i < len; i++) {
230 int ch = line[i];
c22e7de3 231 if (non_ascii(ch) || ch == '\n')
93fc05eb
JS
232 goto needquote;
233 if ((i + 1 < len) && (ch == '=' && line[i+1] == '?'))
234 goto needquote;
235 }
a1f6baa5 236 strbuf_add_wrapped_bytes(sb, line, len, 0, 1, max_length - line_len);
93fc05eb
JS
237 return;
238
239needquote:
240 strbuf_grow(sb, len * 3 + strlen(encoding) + 100);
241 strbuf_addf(sb, "=?%s?q?", encoding);
a1f6baa5
JK
242 line_len += strlen(encoding) + 5; /* 5 for =??q? */
243 for (i = 0; i < len; i++) {
93fc05eb 244 unsigned ch = line[i] & 0xFF;
a1f6baa5
JK
245
246 if (line_len >= max_length - 2) {
247 strbuf_addf(sb, "?=\n =?%s?q?", encoding);
248 line_len = strlen(encoding) + 5 + 1; /* =??q? plus SP */
249 }
250
93fc05eb
JS
251 /*
252 * We encode ' ' using '=20' even though rfc2047
253 * allows using '_' for readability. Unfortunately,
254 * many programs do not understand this and just
255 * leave the underscore in place.
256 */
c22e7de3 257 if (is_rfc2047_special(ch) || ch == ' ' || ch == '\n') {
93fc05eb 258 strbuf_addf(sb, "=%02X", ch);
a1f6baa5
JK
259 line_len += 3;
260 }
261 else {
262 strbuf_addch(sb, ch);
263 line_len++;
93fc05eb
JS
264 }
265 }
93fc05eb
JS
266 strbuf_addstr(sb, "?=");
267}
268
6bf13944
JK
269void pp_user_info(const struct pretty_print_context *pp,
270 const char *what, struct strbuf *sb,
271 const char *line, const char *encoding)
93fc05eb
JS
272{
273 char *date;
274 int namelen;
275 unsigned long time;
276 int tz;
93fc05eb 277
6bf13944 278 if (pp->fmt == CMIT_FMT_ONELINE)
93fc05eb
JS
279 return;
280 date = strchr(line, '>');
281 if (!date)
282 return;
283 namelen = ++date - line;
284 time = strtoul(date, &date, 10);
285 tz = strtol(date, NULL, 10);
286
6bf13944 287 if (pp->fmt == CMIT_FMT_EMAIL) {
93fc05eb
JS
288 char *name_tail = strchr(line, '<');
289 int display_name_length;
990f6e30 290 int final_line;
93fc05eb
JS
291 if (!name_tail)
292 return;
293 while (line < name_tail && isspace(name_tail[-1]))
294 name_tail--;
295 display_name_length = name_tail - line;
93fc05eb
JS
296 strbuf_addstr(sb, "From: ");
297 add_rfc2047(sb, line, display_name_length, encoding);
990f6e30
JK
298 for (final_line = 0; final_line < sb->len; final_line++)
299 if (sb->buf[sb->len - final_line - 1] == '\n')
300 break;
301 if (namelen - display_name_length + final_line > 78) {
302 strbuf_addch(sb, '\n');
303 if (!isspace(name_tail[0]))
304 strbuf_addch(sb, ' ');
305 }
93fc05eb
JS
306 strbuf_add(sb, name_tail, namelen - display_name_length);
307 strbuf_addch(sb, '\n');
308 } else {
309 strbuf_addf(sb, "%s: %.*s%.*s\n", what,
6bf13944 310 (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
8e76bf3f 311 " ", namelen, line);
93fc05eb 312 }
6bf13944 313 switch (pp->fmt) {
93fc05eb 314 case CMIT_FMT_MEDIUM:
6bf13944 315 strbuf_addf(sb, "Date: %s\n", show_date(time, tz, pp->date_mode));
93fc05eb
JS
316 break;
317 case CMIT_FMT_EMAIL:
318 strbuf_addf(sb, "Date: %s\n", show_date(time, tz, DATE_RFC2822));
319 break;
320 case CMIT_FMT_FULLER:
6bf13944 321 strbuf_addf(sb, "%sDate: %s\n", what, show_date(time, tz, pp->date_mode));
93fc05eb
JS
322 break;
323 default:
324 /* notin' */
325 break;
326 }
327}
328
329static int is_empty_line(const char *line, int *len_p)
330{
331 int len = *len_p;
332 while (len && isspace(line[len-1]))
333 len--;
334 *len_p = len;
335 return !len;
336}
337
a0109668
RS
338static const char *skip_empty_lines(const char *msg)
339{
340 for (;;) {
341 int linelen = get_one_line(msg);
342 int ll = linelen;
343 if (!linelen)
344 break;
345 if (!is_empty_line(msg, &ll))
346 break;
347 msg += linelen;
348 }
349 return msg;
350}
351
6bf13944
JK
352static void add_merge_info(const struct pretty_print_context *pp,
353 struct strbuf *sb, const struct commit *commit)
93fc05eb
JS
354{
355 struct commit_list *parent = commit->parents;
356
6bf13944 357 if ((pp->fmt == CMIT_FMT_ONELINE) || (pp->fmt == CMIT_FMT_EMAIL) ||
93fc05eb
JS
358 !parent || !parent->next)
359 return;
360
361 strbuf_addstr(sb, "Merge:");
362
363 while (parent) {
364 struct commit *p = parent->item;
365 const char *hex = NULL;
6bf13944
JK
366 if (pp->abbrev)
367 hex = find_unique_abbrev(p->object.sha1, pp->abbrev);
93fc05eb
JS
368 if (!hex)
369 hex = sha1_to_hex(p->object.sha1);
93fc05eb
JS
370 parent = parent->next;
371
7fcda920 372 strbuf_addf(sb, " %s", hex);
93fc05eb
JS
373 }
374 strbuf_addch(sb, '\n');
375}
376
377static char *get_header(const struct commit *commit, const char *key)
378{
379 int key_len = strlen(key);
380 const char *line = commit->buffer;
381
382 for (;;) {
383 const char *eol = strchr(line, '\n'), *next;
384
385 if (line == eol)
386 return NULL;
387 if (!eol) {
388 eol = line + strlen(line);
389 next = NULL;
390 } else
391 next = eol + 1;
392 if (eol - line > key_len &&
393 !strncmp(line, key, key_len) &&
394 line[key_len] == ' ') {
395 return xmemdupz(line + key_len + 1, eol - line - key_len - 1);
396 }
397 line = next;
398 }
399}
400
401static char *replace_encoding_header(char *buf, const char *encoding)
402{
f285a2d7 403 struct strbuf tmp = STRBUF_INIT;
93fc05eb
JS
404 size_t start, len;
405 char *cp = buf;
406
407 /* guess if there is an encoding header before a \n\n */
408 while (strncmp(cp, "encoding ", strlen("encoding "))) {
409 cp = strchr(cp, '\n');
410 if (!cp || *++cp == '\n')
411 return buf;
412 }
413 start = cp - buf;
414 cp = strchr(cp, '\n');
415 if (!cp)
416 return buf; /* should not happen but be defensive */
417 len = cp + 1 - (buf + start);
418
93fc05eb
JS
419 strbuf_attach(&tmp, buf, strlen(buf), strlen(buf) + 1);
420 if (is_encoding_utf8(encoding)) {
421 /* we have re-coded to UTF-8; drop the header */
422 strbuf_remove(&tmp, start, len);
423 } else {
424 /* just replaces XXXX in 'encoding XXXX\n' */
425 strbuf_splice(&tmp, start + strlen("encoding "),
426 len - strlen("encoding \n"),
427 encoding, strlen(encoding));
428 }
429 return strbuf_detach(&tmp, NULL);
430}
431
177b29dc
PN
432char *logmsg_reencode(const struct commit *commit,
433 const char *output_encoding)
93fc05eb 434{
330db18c 435 static const char *utf8 = "UTF-8";
93fc05eb
JS
436 const char *use_encoding;
437 char *encoding;
438 char *out;
439
440 if (!*output_encoding)
441 return NULL;
442 encoding = get_header(commit, "encoding");
443 use_encoding = encoding ? encoding : utf8;
444 if (!strcmp(use_encoding, output_encoding))
445 if (encoding) /* we'll strip encoding header later */
446 out = xstrdup(commit->buffer);
447 else
448 return NULL; /* nothing to do */
449 else
450 out = reencode_string(commit->buffer,
451 output_encoding, use_encoding);
452 if (out)
453 out = replace_encoding_header(out, output_encoding);
454
455 free(encoding);
456 return out;
457}
458
d20d654f 459static int mailmap_name(char *email, int email_len, char *name, int name_len)
e0cbc397 460{
c455c87c 461 static struct string_list *mail_map;
e0cbc397
JS
462 if (!mail_map) {
463 mail_map = xcalloc(1, sizeof(*mail_map));
d551a488 464 read_mailmap(mail_map, NULL);
e0cbc397 465 }
d20d654f 466 return mail_map->nr && map_user(mail_map, email, email_len, name, name_len);
e0cbc397
JS
467}
468
c3a670de 469static size_t format_person_part(struct strbuf *sb, char part,
d36f8679 470 const char *msg, int len, enum date_mode dmode)
93fc05eb 471{
c3a670de
MC
472 /* currently all placeholders have same length */
473 const int placeholder_len = 2;
93fc05eb 474 int start, end, tz = 0;
c3a670de 475 unsigned long date = 0;
93fc05eb 476 char *ep;
d20d654f
MSO
477 const char *name_start, *name_end, *mail_start, *mail_end, *msg_end = msg+len;
478 char person_name[1024];
479 char person_mail[1024];
93fc05eb 480
c3a670de 481 /* advance 'end' to point to email start delimiter */
93fc05eb
JS
482 for (end = 0; end < len && msg[end] != '<'; end++)
483 ; /* do nothing */
c3a670de 484
f7ab5c79 485 /*
c3a670de
MC
486 * When end points at the '<' that we found, it should have
487 * matching '>' later, which means 'end' must be strictly
488 * below len - 1.
f7ab5c79 489 */
c3a670de
MC
490 if (end >= len - 2)
491 goto skip;
492
d20d654f
MSO
493 /* Seek for both name and email part */
494 name_start = msg;
495 name_end = msg+end;
496 while (name_end > name_start && isspace(*(name_end-1)))
497 name_end--;
498 mail_start = msg+end+1;
499 mail_end = mail_start;
500 while (mail_end < msg_end && *mail_end != '>')
501 mail_end++;
502 if (mail_end == msg_end)
503 goto skip;
504 end = mail_end-msg;
505
506 if (part == 'N' || part == 'E') { /* mailmap lookup */
507 strlcpy(person_name, name_start, name_end-name_start+1);
508 strlcpy(person_mail, mail_start, mail_end-mail_start+1);
509 mailmap_name(person_mail, sizeof(person_mail), person_name, sizeof(person_name));
510 name_start = person_name;
511 name_end = name_start + strlen(person_name);
512 mail_start = person_mail;
513 mail_end = mail_start + strlen(person_mail);
514 }
e0cbc397 515 if (part == 'n' || part == 'N') { /* name */
d20d654f 516 strbuf_add(sb, name_start, name_end-name_start);
c3a670de 517 return placeholder_len;
cde75e59 518 }
d20d654f
MSO
519 if (part == 'e' || part == 'E') { /* email */
520 strbuf_add(sb, mail_start, mail_end-mail_start);
c3a670de 521 return placeholder_len;
cde75e59 522 }
93fc05eb 523
c3a670de 524 /* advance 'start' to point to date start delimiter */
93fc05eb
JS
525 for (start = end + 1; start < len && isspace(msg[start]); start++)
526 ; /* do nothing */
527 if (start >= len)
c3a670de 528 goto skip;
93fc05eb
JS
529 date = strtoul(msg + start, &ep, 10);
530 if (msg + start == ep)
c3a670de 531 goto skip;
93fc05eb 532
cde75e59
RS
533 if (part == 't') { /* date, UNIX timestamp */
534 strbuf_add(sb, msg + start, ep - (msg + start));
c3a670de 535 return placeholder_len;
cde75e59 536 }
93fc05eb
JS
537
538 /* parse tz */
539 for (start = ep - msg + 1; start < len && isspace(msg[start]); start++)
540 ; /* do nothing */
541 if (start + 1 < len) {
542 tz = strtoul(msg + start + 1, NULL, 10);
543 if (msg[start] == '-')
544 tz = -tz;
545 }
546
cde75e59
RS
547 switch (part) {
548 case 'd': /* date */
d36f8679 549 strbuf_addstr(sb, show_date(date, tz, dmode));
c3a670de 550 return placeholder_len;
cde75e59
RS
551 case 'D': /* date, RFC2822 style */
552 strbuf_addstr(sb, show_date(date, tz, DATE_RFC2822));
c3a670de 553 return placeholder_len;
cde75e59
RS
554 case 'r': /* date, relative */
555 strbuf_addstr(sb, show_date(date, tz, DATE_RELATIVE));
c3a670de 556 return placeholder_len;
cde75e59
RS
557 case 'i': /* date, ISO 8601 */
558 strbuf_addstr(sb, show_date(date, tz, DATE_ISO8601));
c3a670de 559 return placeholder_len;
cde75e59 560 }
c3a670de
MC
561
562skip:
563 /*
564 * bogus commit, 'sb' cannot be updated, but we still need to
565 * compute a valid return value.
566 */
567 if (part == 'n' || part == 'e' || part == 't' || part == 'd'
568 || part == 'D' || part == 'r' || part == 'i')
569 return placeholder_len;
570
571 return 0; /* unknown placeholder */
93fc05eb
JS
572}
573
f29d5958
RS
574struct chunk {
575 size_t off;
576 size_t len;
577};
578
579struct format_commit_context {
580 const struct commit *commit;
dd2e794a 581 const struct pretty_print_context *pretty_ctx;
f53bd743
RS
582 unsigned commit_header_parsed:1;
583 unsigned commit_message_parsed:1;
177b29dc 584 char *message;
02edd56b 585 size_t width, indent1, indent2;
f29d5958
RS
586
587 /* These offsets are relative to the start of the commit message. */
f29d5958
RS
588 struct chunk author;
589 struct chunk committer;
590 struct chunk encoding;
f53bd743
RS
591 size_t message_off;
592 size_t subject_off;
f29d5958 593 size_t body_off;
b9c62321
RS
594
595 /* The following ones are relative to the result struct strbuf. */
596 struct chunk abbrev_commit_hash;
597 struct chunk abbrev_tree_hash;
598 struct chunk abbrev_parent_hashes;
02edd56b 599 size_t wrap_start;
f29d5958
RS
600};
601
b9c62321
RS
602static int add_again(struct strbuf *sb, struct chunk *chunk)
603{
604 if (chunk->len) {
605 strbuf_adddup(sb, chunk->off, chunk->len);
606 return 1;
607 }
608
609 /*
610 * We haven't seen this chunk before. Our caller is surely
611 * going to add it the hard way now. Remember the most likely
612 * start of the to-be-added chunk: the current end of the
613 * struct strbuf.
614 */
615 chunk->off = sb->len;
616 return 0;
617}
618
f29d5958 619static void parse_commit_header(struct format_commit_context *context)
93fc05eb 620{
177b29dc 621 const char *msg = context->message;
93fc05eb 622 int i;
f29d5958 623
f53bd743 624 for (i = 0; msg[i]; i++) {
f29d5958
RS
625 int eol;
626 for (eol = i; msg[eol] && msg[eol] != '\n'; eol++)
627 ; /* do nothing */
628
f29d5958 629 if (i == eol) {
f53bd743 630 break;
f29d5958
RS
631 } else if (!prefixcmp(msg + i, "author ")) {
632 context->author.off = i + 7;
633 context->author.len = eol - i - 7;
634 } else if (!prefixcmp(msg + i, "committer ")) {
635 context->committer.off = i + 10;
636 context->committer.len = eol - i - 10;
637 } else if (!prefixcmp(msg + i, "encoding ")) {
638 context->encoding.off = i + 9;
639 context->encoding.len = eol - i - 9;
640 }
641 i = eol;
642 }
f53bd743 643 context->message_off = i;
f29d5958
RS
644 context->commit_header_parsed = 1;
645}
646
46d164b0
SB
647static int istitlechar(char c)
648{
649 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
650 (c >= '0' && c <= '9') || c == '.' || c == '_';
651}
652
653static void format_sanitized_subject(struct strbuf *sb, const char *msg)
654{
655 size_t trimlen;
871d21d4 656 size_t start_len = sb->len;
46d164b0
SB
657 int space = 2;
658
659 for (; *msg && *msg != '\n'; msg++) {
660 if (istitlechar(*msg)) {
661 if (space == 1)
662 strbuf_addch(sb, '-');
663 space = 0;
664 strbuf_addch(sb, *msg);
665 if (*msg == '.')
666 while (*(msg+1) == '.')
667 msg++;
668 } else
669 space |= 1;
670 }
671
672 /* trim any trailing '.' or '-' characters */
673 trimlen = 0;
871d21d4
SB
674 while (sb->len - trimlen > start_len &&
675 (sb->buf[sb->len - 1 - trimlen] == '.'
676 || sb->buf[sb->len - 1 - trimlen] == '-'))
46d164b0
SB
677 trimlen++;
678 strbuf_remove(sb, sb->len - trimlen, trimlen);
679}
680
cec08717
RS
681const char *format_subject(struct strbuf *sb, const char *msg,
682 const char *line_separator)
88c44735
RS
683{
684 int first = 1;
685
686 for (;;) {
687 const char *line = msg;
688 int linelen = get_one_line(line);
689
690 msg += linelen;
691 if (!linelen || is_empty_line(line, &linelen))
692 break;
693
f53bd743
RS
694 if (!sb)
695 continue;
88c44735
RS
696 strbuf_grow(sb, linelen + 2);
697 if (!first)
698 strbuf_addstr(sb, line_separator);
699 strbuf_add(sb, line, linelen);
700 first = 0;
701 }
702 return msg;
703}
704
f53bd743
RS
705static void parse_commit_message(struct format_commit_context *c)
706{
177b29dc
PN
707 const char *msg = c->message + c->message_off;
708 const char *start = c->message;
f53bd743
RS
709
710 msg = skip_empty_lines(msg);
711 c->subject_off = msg - start;
712
713 msg = format_subject(NULL, msg, NULL);
714 msg = skip_empty_lines(msg);
715 c->body_off = msg - start;
716
717 c->commit_message_parsed = 1;
718}
719
3b3d443f
RS
720static void format_decoration(struct strbuf *sb, const struct commit *commit)
721{
722 struct name_decoration *d;
723 const char *prefix = " (";
724
33e7018c 725 load_ref_decorations(DECORATE_SHORT_REFS);
3b3d443f
RS
726 d = lookup_decoration(&name_decoration, &commit->object);
727 while (d) {
728 strbuf_addstr(sb, prefix);
729 prefix = ", ";
730 strbuf_addstr(sb, d->name);
731 d = d->next;
732 }
733 if (prefix[0] == ',')
734 strbuf_addch(sb, ')');
735}
736
02edd56b
RS
737static void strbuf_wrap(struct strbuf *sb, size_t pos,
738 size_t width, size_t indent1, size_t indent2)
739{
740 struct strbuf tmp = STRBUF_INIT;
741
742 if (pos)
743 strbuf_add(&tmp, sb->buf, pos);
744 strbuf_add_wrapped_text(&tmp, sb->buf + pos,
745 (int) indent1, (int) indent2, (int) width);
746 strbuf_swap(&tmp, sb);
747 strbuf_release(&tmp);
748}
749
750static void rewrap_message_tail(struct strbuf *sb,
751 struct format_commit_context *c,
752 size_t new_width, size_t new_indent1,
753 size_t new_indent2)
754{
755 if (c->width == new_width && c->indent1 == new_indent1 &&
756 c->indent2 == new_indent2)
757 return;
32ca4249 758 if (c->wrap_start < sb->len)
02edd56b
RS
759 strbuf_wrap(sb, c->wrap_start, c->width, c->indent1, c->indent2);
760 c->wrap_start = sb->len;
761 c->width = new_width;
762 c->indent1 = new_indent1;
763 c->indent2 = new_indent2;
764}
765
9fa708da
JH
766static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
767 void *context)
f29d5958
RS
768{
769 struct format_commit_context *c = context;
770 const struct commit *commit = c->commit;
177b29dc 771 const char *msg = c->message;
f29d5958 772 struct commit_list *p;
42c8c74c 773 int h1, h2;
93fc05eb 774
93fc05eb 775 /* these are independent of the commit */
cde75e59
RS
776 switch (placeholder[0]) {
777 case 'C':
c002922a
JK
778 if (placeholder[1] == '(') {
779 const char *end = strchr(placeholder + 2, ')');
780 char color[COLOR_MAXLEN];
781 if (!end)
782 return 0;
783 color_parse_mem(placeholder + 2,
784 end - (placeholder + 2),
785 "--pretty format", color);
786 strbuf_addstr(sb, color);
787 return end - placeholder + 1;
788 }
c3a670de 789 if (!prefixcmp(placeholder + 1, "red")) {
dc6ebd4c 790 strbuf_addstr(sb, GIT_COLOR_RED);
c3a670de
MC
791 return 4;
792 } else if (!prefixcmp(placeholder + 1, "green")) {
dc6ebd4c 793 strbuf_addstr(sb, GIT_COLOR_GREEN);
c3a670de
MC
794 return 6;
795 } else if (!prefixcmp(placeholder + 1, "blue")) {
dc6ebd4c 796 strbuf_addstr(sb, GIT_COLOR_BLUE);
c3a670de
MC
797 return 5;
798 } else if (!prefixcmp(placeholder + 1, "reset")) {
dc6ebd4c 799 strbuf_addstr(sb, GIT_COLOR_RESET);
c3a670de
MC
800 return 6;
801 } else
802 return 0;
cde75e59
RS
803 case 'n': /* newline */
804 strbuf_addch(sb, '\n');
c3a670de 805 return 1;
42c8c74c
GS
806 case 'x':
807 /* %x00 == NUL, %x0a == LF, etc. */
808 if (0 <= (h1 = hexval_table[0xff & placeholder[1]]) &&
809 h1 <= 16 &&
810 0 <= (h2 = hexval_table[0xff & placeholder[2]]) &&
811 h2 <= 16) {
812 strbuf_addch(sb, (h1<<4)|h2);
813 return 3;
814 } else
815 return 0;
02edd56b
RS
816 case 'w':
817 if (placeholder[1] == '(') {
818 unsigned long width = 0, indent1 = 0, indent2 = 0;
819 char *next;
820 const char *start = placeholder + 2;
821 const char *end = strchr(start, ')');
822 if (!end)
823 return 0;
824 if (end > start) {
825 width = strtoul(start, &next, 10);
826 if (*next == ',') {
827 indent1 = strtoul(next + 1, &next, 10);
828 if (*next == ',') {
829 indent2 = strtoul(next + 1,
830 &next, 10);
831 }
832 }
833 if (*next != ')')
834 return 0;
835 }
836 rewrap_message_tail(sb, c, width, indent1, indent2);
837 return end - placeholder + 1;
838 } else
839 return 0;
cde75e59 840 }
93fc05eb
JS
841
842 /* these depend on the commit */
843 if (!commit->object.parsed)
844 parse_object(commit->object.sha1);
93fc05eb 845
cde75e59
RS
846 switch (placeholder[0]) {
847 case 'H': /* commit hash */
848 strbuf_addstr(sb, sha1_to_hex(commit->object.sha1));
c3a670de 849 return 1;
cde75e59 850 case 'h': /* abbreviated commit hash */
b9c62321 851 if (add_again(sb, &c->abbrev_commit_hash))
c3a670de 852 return 1;
cde75e59 853 strbuf_addstr(sb, find_unique_abbrev(commit->object.sha1,
c1977021 854 c->pretty_ctx->abbrev));
b9c62321 855 c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
c3a670de 856 return 1;
cde75e59
RS
857 case 'T': /* tree hash */
858 strbuf_addstr(sb, sha1_to_hex(commit->tree->object.sha1));
c3a670de 859 return 1;
cde75e59 860 case 't': /* abbreviated tree hash */
b9c62321 861 if (add_again(sb, &c->abbrev_tree_hash))
c3a670de 862 return 1;
cde75e59 863 strbuf_addstr(sb, find_unique_abbrev(commit->tree->object.sha1,
c1977021 864 c->pretty_ctx->abbrev));
b9c62321 865 c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
c3a670de 866 return 1;
cde75e59
RS
867 case 'P': /* parent hashes */
868 for (p = commit->parents; p; p = p->next) {
869 if (p != commit->parents)
870 strbuf_addch(sb, ' ');
871 strbuf_addstr(sb, sha1_to_hex(p->item->object.sha1));
872 }
c3a670de 873 return 1;
cde75e59 874 case 'p': /* abbreviated parent hashes */
b9c62321 875 if (add_again(sb, &c->abbrev_parent_hashes))
c3a670de 876 return 1;
cde75e59
RS
877 for (p = commit->parents; p; p = p->next) {
878 if (p != commit->parents)
879 strbuf_addch(sb, ' ');
880 strbuf_addstr(sb, find_unique_abbrev(
c1977021
WP
881 p->item->object.sha1,
882 c->pretty_ctx->abbrev));
cde75e59 883 }
b9c62321
RS
884 c->abbrev_parent_hashes.len = sb->len -
885 c->abbrev_parent_hashes.off;
c3a670de 886 return 1;
cde75e59
RS
887 case 'm': /* left/right/bottom */
888 strbuf_addch(sb, (commit->object.flags & BOUNDARY)
889 ? '-'
890 : (commit->object.flags & SYMMETRIC_LEFT)
891 ? '<'
892 : '>');
c3a670de 893 return 1;
3b3d443f
RS
894 case 'd':
895 format_decoration(sb, commit);
896 return 1;
8f8f5476
TR
897 case 'g': /* reflog info */
898 switch(placeholder[1]) {
899 case 'd': /* reflog selector */
900 case 'D':
901 if (c->pretty_ctx->reflog_info)
902 get_reflog_selector(sb,
903 c->pretty_ctx->reflog_info,
904 c->pretty_ctx->date_mode,
905 (placeholder[1] == 'd'));
906 return 2;
907 case 's': /* reflog message */
908 if (c->pretty_ctx->reflog_info)
909 get_reflog_message(sb, c->pretty_ctx->reflog_info);
910 return 2;
911 }
912 return 0; /* unknown %g placeholder */
8b208f02 913 case 'N':
5b163603
JG
914 if (c->pretty_ctx->show_notes) {
915 format_display_notes(commit->object.sha1, sb,
a6fa5992 916 get_log_output_encoding(), 0);
5b163603
JG
917 return 1;
918 }
919 return 0;
cde75e59
RS
920 }
921
922 /* For the rest we have to parse the commit header. */
f29d5958
RS
923 if (!c->commit_header_parsed)
924 parse_commit_header(c);
93fc05eb 925
f29d5958 926 switch (placeholder[0]) {
c3a670de
MC
927 case 'a': /* author ... */
928 return format_person_part(sb, placeholder[1],
d36f8679 929 msg + c->author.off, c->author.len,
dd2e794a 930 c->pretty_ctx->date_mode);
c3a670de
MC
931 case 'c': /* committer ... */
932 return format_person_part(sb, placeholder[1],
d36f8679 933 msg + c->committer.off, c->committer.len,
dd2e794a 934 c->pretty_ctx->date_mode);
c3a670de 935 case 'e': /* encoding */
f29d5958 936 strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
c3a670de 937 return 1;
1367b12a
EB
938 case 'B': /* raw body */
939 /* message_off is always left at the initial newline */
940 strbuf_addstr(sb, msg + c->message_off + 1);
941 return 1;
f53bd743
RS
942 }
943
944 /* Now we need to parse the commit message. */
945 if (!c->commit_message_parsed)
946 parse_commit_message(c);
947
948 switch (placeholder[0]) {
949 case 's': /* subject */
950 format_subject(sb, msg + c->subject_off, " ");
951 return 1;
46d164b0
SB
952 case 'f': /* sanitized subject */
953 format_sanitized_subject(sb, msg + c->subject_off);
954 return 1;
c3a670de 955 case 'b': /* body */
f29d5958 956 strbuf_addstr(sb, msg + c->body_off);
c3a670de 957 return 1;
93fc05eb 958 }
c3a670de 959 return 0; /* unknown placeholder */
cde75e59
RS
960}
961
9fa708da
JH
962static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
963 void *context)
964{
965 int consumed;
966 size_t orig_len;
967 enum {
968 NO_MAGIC,
969 ADD_LF_BEFORE_NON_EMPTY,
970 DEL_LF_BEFORE_EMPTY,
223a923c 971 ADD_SP_BEFORE_NON_EMPTY
9fa708da
JH
972 } magic = NO_MAGIC;
973
974 switch (placeholder[0]) {
975 case '-':
976 magic = DEL_LF_BEFORE_EMPTY;
977 break;
978 case '+':
979 magic = ADD_LF_BEFORE_NON_EMPTY;
980 break;
7b88176e
MG
981 case ' ':
982 magic = ADD_SP_BEFORE_NON_EMPTY;
983 break;
9fa708da
JH
984 default:
985 break;
986 }
987 if (magic != NO_MAGIC)
988 placeholder++;
989
990 orig_len = sb->len;
991 consumed = format_commit_one(sb, placeholder, context);
992 if (magic == NO_MAGIC)
993 return consumed;
994
995 if ((orig_len == sb->len) && magic == DEL_LF_BEFORE_EMPTY) {
996 while (sb->len && sb->buf[sb->len - 1] == '\n')
997 strbuf_setlen(sb, sb->len - 1);
7b88176e
MG
998 } else if (orig_len != sb->len) {
999 if (magic == ADD_LF_BEFORE_NON_EMPTY)
1000 strbuf_insert(sb, orig_len, "\n", 1);
1001 else if (magic == ADD_SP_BEFORE_NON_EMPTY)
1002 strbuf_insert(sb, orig_len, " ", 1);
9fa708da
JH
1003 }
1004 return consumed + 1;
1005}
1006
5b163603
JG
1007static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
1008 void *context)
1009{
1010 struct userformat_want *w = context;
1011
7b88176e 1012 if (*placeholder == '+' || *placeholder == '-' || *placeholder == ' ')
5b163603
JG
1013 placeholder++;
1014
1015 switch (*placeholder) {
1016 case 'N':
1017 w->notes = 1;
1018 break;
1019 }
1020 return 0;
1021}
1022
1023void userformat_find_requirements(const char *fmt, struct userformat_want *w)
1024{
1025 struct strbuf dummy = STRBUF_INIT;
1026
1027 if (!fmt) {
1028 if (!user_format)
1029 return;
1030 fmt = user_format;
1031 }
1032 strbuf_expand(&dummy, user_format, userformat_want_item, w);
1033 strbuf_release(&dummy);
1034}
1035
cde75e59 1036void format_commit_message(const struct commit *commit,
7f98ebc8 1037 const char *format, struct strbuf *sb,
dd2e794a 1038 const struct pretty_print_context *pretty_ctx)
cde75e59 1039{
f29d5958 1040 struct format_commit_context context;
177b29dc
PN
1041 static const char utf8[] = "UTF-8";
1042 const char *enc;
1043 const char *output_enc = pretty_ctx->output_encoding;
f29d5958
RS
1044
1045 memset(&context, 0, sizeof(context));
1046 context.commit = commit;
dd2e794a 1047 context.pretty_ctx = pretty_ctx;
02edd56b 1048 context.wrap_start = sb->len;
177b29dc
PN
1049 context.message = commit->buffer;
1050 if (output_enc) {
1051 enc = get_header(commit, "encoding");
1052 enc = enc ? enc : utf8;
1053 if (strcmp(enc, output_enc))
1054 context.message = logmsg_reencode(commit, output_enc);
1055 }
1056
c3a670de 1057 strbuf_expand(sb, format, format_commit_item, &context);
02edd56b 1058 rewrap_message_tail(sb, &context, 0, 0, 0);
177b29dc
PN
1059
1060 if (context.message != commit->buffer)
1061 free(context.message);
93fc05eb
JS
1062}
1063
6bf13944 1064static void pp_header(const struct pretty_print_context *pp,
93fc05eb
JS
1065 const char *encoding,
1066 const struct commit *commit,
1067 const char **msg_p,
1068 struct strbuf *sb)
1069{
1070 int parents_shown = 0;
1071
1072 for (;;) {
1073 const char *line = *msg_p;
1074 int linelen = get_one_line(*msg_p);
1075
1076 if (!linelen)
1077 return;
1078 *msg_p += linelen;
1079
1080 if (linelen == 1)
1081 /* End of header */
1082 return;
1083
6bf13944 1084 if (pp->fmt == CMIT_FMT_RAW) {
93fc05eb
JS
1085 strbuf_add(sb, line, linelen);
1086 continue;
1087 }
1088
1089 if (!memcmp(line, "parent ", 7)) {
1090 if (linelen != 48)
1091 die("bad parent line in commit");
1092 continue;
1093 }
1094
1095 if (!parents_shown) {
1096 struct commit_list *parent;
1097 int num;
1098 for (parent = commit->parents, num = 0;
1099 parent;
1100 parent = parent->next, num++)
1101 ;
1102 /* with enough slop */
1103 strbuf_grow(sb, num * 50 + 20);
6bf13944 1104 add_merge_info(pp, sb, commit);
93fc05eb
JS
1105 parents_shown = 1;
1106 }
1107
1108 /*
1109 * MEDIUM == DEFAULT shows only author with dates.
1110 * FULL shows both authors but not dates.
1111 * FULLER shows both authors and dates.
1112 */
1113 if (!memcmp(line, "author ", 7)) {
1114 strbuf_grow(sb, linelen + 80);
6bf13944 1115 pp_user_info(pp, "Author", sb, line + 7, encoding);
93fc05eb
JS
1116 }
1117 if (!memcmp(line, "committer ", 10) &&
6bf13944 1118 (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
93fc05eb 1119 strbuf_grow(sb, linelen + 80);
6bf13944 1120 pp_user_info(pp, "Commit", sb, line + 10, encoding);
93fc05eb
JS
1121 }
1122 }
1123}
1124
6bf13944 1125void pp_title_line(const struct pretty_print_context *pp,
b02bd65f
DB
1126 const char **msg_p,
1127 struct strbuf *sb,
b02bd65f 1128 const char *encoding,
267123b4 1129 int need_8bit_cte)
93fc05eb
JS
1130{
1131 struct strbuf title;
1132
1133 strbuf_init(&title, 80);
a1f6baa5 1134 *msg_p = format_subject(&title, *msg_p, " ");
93fc05eb
JS
1135
1136 strbuf_grow(sb, title.len + 1024);
6bf13944
JK
1137 if (pp->subject) {
1138 strbuf_addstr(sb, pp->subject);
93fc05eb
JS
1139 add_rfc2047(sb, title.buf, title.len, encoding);
1140 } else {
1141 strbuf_addbuf(sb, &title);
1142 }
1143 strbuf_addch(sb, '\n');
1144
6bf4f1b4 1145 if (need_8bit_cte > 0) {
93fc05eb
JS
1146 const char *header_fmt =
1147 "MIME-Version: 1.0\n"
1148 "Content-Type: text/plain; charset=%s\n"
1149 "Content-Transfer-Encoding: 8bit\n";
1150 strbuf_addf(sb, header_fmt, encoding);
1151 }
6bf13944
JK
1152 if (pp->after_subject) {
1153 strbuf_addstr(sb, pp->after_subject);
93fc05eb 1154 }
6bf13944 1155 if (pp->fmt == CMIT_FMT_EMAIL) {
93fc05eb
JS
1156 strbuf_addch(sb, '\n');
1157 }
1158 strbuf_release(&title);
1159}
1160
6bf13944 1161void pp_remainder(const struct pretty_print_context *pp,
b02bd65f
DB
1162 const char **msg_p,
1163 struct strbuf *sb,
1164 int indent)
93fc05eb
JS
1165{
1166 int first = 1;
1167 for (;;) {
1168 const char *line = *msg_p;
1169 int linelen = get_one_line(line);
1170 *msg_p += linelen;
1171
1172 if (!linelen)
1173 break;
1174
1175 if (is_empty_line(line, &linelen)) {
1176 if (first)
1177 continue;
6bf13944 1178 if (pp->fmt == CMIT_FMT_SHORT)
93fc05eb
JS
1179 break;
1180 }
1181 first = 0;
1182
1183 strbuf_grow(sb, linelen + indent + 20);
1184 if (indent) {
1185 memset(sb->buf + sb->len, ' ', indent);
1186 strbuf_setlen(sb, sb->len + indent);
1187 }
1188 strbuf_add(sb, line, linelen);
1189 strbuf_addch(sb, '\n');
1190 }
1191}
1192
69cd8f63
AG
1193char *reencode_commit_message(const struct commit *commit, const char **encoding_p)
1194{
1195 const char *encoding;
1196
a6fa5992 1197 encoding = get_log_output_encoding();
69cd8f63
AG
1198 if (encoding_p)
1199 *encoding_p = encoding;
1200 return logmsg_reencode(commit, encoding);
1201}
1202
6bf13944
JK
1203void pretty_print_commit(const struct pretty_print_context *pp,
1204 const struct commit *commit,
1205 struct strbuf *sb)
93fc05eb
JS
1206{
1207 unsigned long beginning_of_body;
1208 int indent = 4;
1209 const char *msg = commit->buffer;
1210 char *reencoded;
1211 const char *encoding;
6bf13944 1212 int need_8bit_cte = pp->need_8bit_cte;
93fc05eb 1213
6bf13944
JK
1214 if (pp->fmt == CMIT_FMT_USERFORMAT) {
1215 format_commit_message(commit, user_format, sb, pp);
93fc05eb
JS
1216 return;
1217 }
1218
69cd8f63 1219 reencoded = reencode_commit_message(commit, &encoding);
93fc05eb
JS
1220 if (reencoded) {
1221 msg = reencoded;
1222 }
1223
6bf13944 1224 if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
93fc05eb
JS
1225 indent = 0;
1226
6bf4f1b4
JH
1227 /*
1228 * We need to check and emit Content-type: to mark it
1229 * as 8-bit if we haven't done so.
93fc05eb 1230 */
6bf13944 1231 if (pp->fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) {
93fc05eb
JS
1232 int i, ch, in_body;
1233
1234 for (in_body = i = 0; (ch = msg[i]); i++) {
1235 if (!in_body) {
1236 /* author could be non 7-bit ASCII but
1237 * the log may be so; skip over the
1238 * header part first.
1239 */
1240 if (ch == '\n' && msg[i+1] == '\n')
1241 in_body = 1;
1242 }
1243 else if (non_ascii(ch)) {
6bf4f1b4 1244 need_8bit_cte = 1;
93fc05eb
JS
1245 break;
1246 }
1247 }
1248 }
1249
6bf13944
JK
1250 pp_header(pp, encoding, commit, &msg, sb);
1251 if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) {
93fc05eb
JS
1252 strbuf_addch(sb, '\n');
1253 }
1254
1255 /* Skip excess blank lines at the beginning of body, if any... */
a0109668 1256 msg = skip_empty_lines(msg);
93fc05eb
JS
1257
1258 /* These formats treat the title line specially. */
6bf13944
JK
1259 if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
1260 pp_title_line(pp, &msg, sb, encoding, need_8bit_cte);
93fc05eb
JS
1261
1262 beginning_of_body = sb->len;
6bf13944
JK
1263 if (pp->fmt != CMIT_FMT_ONELINE)
1264 pp_remainder(pp, &msg, sb, indent);
93fc05eb
JS
1265 strbuf_rtrim(sb);
1266
1267 /* Make sure there is an EOLN for the non-oneline case */
6bf13944 1268 if (pp->fmt != CMIT_FMT_ONELINE)
93fc05eb
JS
1269 strbuf_addch(sb, '\n');
1270
1271 /*
1272 * The caller may append additional body text in e-mail
1273 * format. Make sure we did not strip the blank line
1274 * between the header and the body.
1275 */
6bf13944 1276 if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
93fc05eb 1277 strbuf_addch(sb, '\n');
a97a7468 1278
6bf13944 1279 if (pp->show_notes)
894a9d33
TR
1280 format_display_notes(commit->object.sha1, sb, encoding,
1281 NOTES_SHOW_HEADER | NOTES_INDENT);
a97a7468 1282
93fc05eb
JS
1283 free(reencoded);
1284}
8b8a5374
JK
1285
1286void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
1287 struct strbuf *sb)
1288{
1289 struct pretty_print_context pp = {0};
6bf13944
JK
1290 pp.fmt = fmt;
1291 pretty_print_commit(&pp, commit, sb);
8b8a5374 1292}