6 #include "string-list.h"
11 static char *user_format
;
13 void get_commit_format(const char *arg
, struct rev_info
*rev
)
16 static struct cmt_fmt_map
{
21 { "raw", 1, CMIT_FMT_RAW
},
22 { "medium", 1, CMIT_FMT_MEDIUM
},
23 { "short", 1, CMIT_FMT_SHORT
},
24 { "email", 1, CMIT_FMT_EMAIL
},
25 { "full", 5, CMIT_FMT_FULL
},
26 { "fuller", 5, CMIT_FMT_FULLER
},
27 { "oneline", 1, CMIT_FMT_ONELINE
},
30 rev
->use_terminator
= 0;
32 rev
->commit_format
= CMIT_FMT_DEFAULT
;
35 if (!prefixcmp(arg
, "format:") || !prefixcmp(arg
, "tformat:")) {
36 const char *cp
= strchr(arg
, ':') + 1;
38 user_format
= xstrdup(cp
);
40 rev
->use_terminator
= 1;
41 rev
->commit_format
= CMIT_FMT_USERFORMAT
;
44 for (i
= 0; i
< ARRAY_SIZE(cmt_fmts
); i
++) {
45 if (!strncmp(arg
, cmt_fmts
[i
].n
, cmt_fmts
[i
].cmp_len
) &&
46 !strncmp(arg
, cmt_fmts
[i
].n
, strlen(arg
))) {
47 if (cmt_fmts
[i
].v
== CMIT_FMT_ONELINE
)
48 rev
->use_terminator
= 1;
49 rev
->commit_format
= cmt_fmts
[i
].v
;
54 die("invalid --pretty format: %s", arg
);
58 * Generic support for pretty-printing the header
60 static int get_one_line(const char *msg
)
75 /* High bit set, or ISO-2022-INT */
78 return !isascii(ch
) || ch
== '\033';
81 static int is_rfc2047_special(char ch
)
83 return (non_ascii(ch
) || (ch
== '=') || (ch
== '?') || (ch
== '_'));
86 static void add_rfc2047(struct strbuf
*sb
, const char *line
, int len
,
91 for (i
= 0; i
< len
; i
++) {
95 if ((i
+ 1 < len
) && (ch
== '=' && line
[i
+1] == '?'))
98 strbuf_add(sb
, line
, len
);
102 strbuf_grow(sb
, len
* 3 + strlen(encoding
) + 100);
103 strbuf_addf(sb
, "=?%s?q?", encoding
);
104 for (i
= last
= 0; i
< len
; i
++) {
105 unsigned ch
= line
[i
] & 0xFF;
107 * We encode ' ' using '=20' even though rfc2047
108 * allows using '_' for readability. Unfortunately,
109 * many programs do not understand this and just
110 * leave the underscore in place.
112 if (is_rfc2047_special(ch
) || ch
== ' ') {
113 strbuf_add(sb
, line
+ last
, i
- last
);
114 strbuf_addf(sb
, "=%02X", ch
);
118 strbuf_add(sb
, line
+ last
, len
- last
);
119 strbuf_addstr(sb
, "?=");
122 void pp_user_info(const char *what
, enum cmit_fmt fmt
, struct strbuf
*sb
,
123 const char *line
, enum date_mode dmode
,
124 const char *encoding
)
130 const char *filler
= " ";
132 if (fmt
== CMIT_FMT_ONELINE
)
134 date
= strchr(line
, '>');
137 namelen
= ++date
- line
;
138 time
= strtoul(date
, &date
, 10);
139 tz
= strtol(date
, NULL
, 10);
141 if (fmt
== CMIT_FMT_EMAIL
) {
142 char *name_tail
= strchr(line
, '<');
143 int display_name_length
;
146 while (line
< name_tail
&& isspace(name_tail
[-1]))
148 display_name_length
= name_tail
- line
;
150 strbuf_addstr(sb
, "From: ");
151 add_rfc2047(sb
, line
, display_name_length
, encoding
);
152 strbuf_add(sb
, name_tail
, namelen
- display_name_length
);
153 strbuf_addch(sb
, '\n');
155 strbuf_addf(sb
, "%s: %.*s%.*s\n", what
,
156 (fmt
== CMIT_FMT_FULLER
) ? 4 : 0,
157 filler
, namelen
, line
);
160 case CMIT_FMT_MEDIUM
:
161 strbuf_addf(sb
, "Date: %s\n", show_date(time
, tz
, dmode
));
164 strbuf_addf(sb
, "Date: %s\n", show_date(time
, tz
, DATE_RFC2822
));
166 case CMIT_FMT_FULLER
:
167 strbuf_addf(sb
, "%sDate: %s\n", what
, show_date(time
, tz
, dmode
));
175 static int is_empty_line(const char *line
, int *len_p
)
178 while (len
&& isspace(line
[len
-1]))
184 static const char *skip_empty_lines(const char *msg
)
187 int linelen
= get_one_line(msg
);
191 if (!is_empty_line(msg
, &ll
))
198 static void add_merge_info(enum cmit_fmt fmt
, struct strbuf
*sb
,
199 const struct commit
*commit
, int abbrev
)
201 struct commit_list
*parent
= commit
->parents
;
203 if ((fmt
== CMIT_FMT_ONELINE
) || (fmt
== CMIT_FMT_EMAIL
) ||
204 !parent
|| !parent
->next
)
207 strbuf_addstr(sb
, "Merge:");
210 struct commit
*p
= parent
->item
;
211 const char *hex
= NULL
;
213 hex
= find_unique_abbrev(p
->object
.sha1
, abbrev
);
215 hex
= sha1_to_hex(p
->object
.sha1
);
216 parent
= parent
->next
;
218 strbuf_addf(sb
, " %s", hex
);
220 strbuf_addch(sb
, '\n');
223 static char *get_header(const struct commit
*commit
, const char *key
)
225 int key_len
= strlen(key
);
226 const char *line
= commit
->buffer
;
229 const char *eol
= strchr(line
, '\n'), *next
;
234 eol
= line
+ strlen(line
);
238 if (eol
- line
> key_len
&&
239 !strncmp(line
, key
, key_len
) &&
240 line
[key_len
] == ' ') {
241 return xmemdupz(line
+ key_len
+ 1, eol
- line
- key_len
- 1);
247 static char *replace_encoding_header(char *buf
, const char *encoding
)
249 struct strbuf tmp
= STRBUF_INIT
;
253 /* guess if there is an encoding header before a \n\n */
254 while (strncmp(cp
, "encoding ", strlen("encoding "))) {
255 cp
= strchr(cp
, '\n');
256 if (!cp
|| *++cp
== '\n')
260 cp
= strchr(cp
, '\n');
262 return buf
; /* should not happen but be defensive */
263 len
= cp
+ 1 - (buf
+ start
);
265 strbuf_attach(&tmp
, buf
, strlen(buf
), strlen(buf
) + 1);
266 if (is_encoding_utf8(encoding
)) {
267 /* we have re-coded to UTF-8; drop the header */
268 strbuf_remove(&tmp
, start
, len
);
270 /* just replaces XXXX in 'encoding XXXX\n' */
271 strbuf_splice(&tmp
, start
+ strlen("encoding "),
272 len
- strlen("encoding \n"),
273 encoding
, strlen(encoding
));
275 return strbuf_detach(&tmp
, NULL
);
278 static char *logmsg_reencode(const struct commit
*commit
,
279 const char *output_encoding
)
281 static const char *utf8
= "utf-8";
282 const char *use_encoding
;
286 if (!*output_encoding
)
288 encoding
= get_header(commit
, "encoding");
289 use_encoding
= encoding
? encoding
: utf8
;
290 if (!strcmp(use_encoding
, output_encoding
))
291 if (encoding
) /* we'll strip encoding header later */
292 out
= xstrdup(commit
->buffer
);
294 return NULL
; /* nothing to do */
296 out
= reencode_string(commit
->buffer
,
297 output_encoding
, use_encoding
);
299 out
= replace_encoding_header(out
, output_encoding
);
305 static int mailmap_name(char *email
, int email_len
, char *name
, int name_len
)
307 static struct string_list
*mail_map
;
309 mail_map
= xcalloc(1, sizeof(*mail_map
));
310 read_mailmap(mail_map
, NULL
);
312 return mail_map
->nr
&& map_user(mail_map
, email
, email_len
, name
, name_len
);
315 static size_t format_person_part(struct strbuf
*sb
, char part
,
316 const char *msg
, int len
, enum date_mode dmode
)
318 /* currently all placeholders have same length */
319 const int placeholder_len
= 2;
320 int start
, end
, tz
= 0;
321 unsigned long date
= 0;
323 const char *name_start
, *name_end
, *mail_start
, *mail_end
, *msg_end
= msg
+len
;
324 char person_name
[1024];
325 char person_mail
[1024];
327 /* advance 'end' to point to email start delimiter */
328 for (end
= 0; end
< len
&& msg
[end
] != '<'; end
++)
332 * When end points at the '<' that we found, it should have
333 * matching '>' later, which means 'end' must be strictly
339 /* Seek for both name and email part */
342 while (name_end
> name_start
&& isspace(*(name_end
-1)))
344 mail_start
= msg
+end
+1;
345 mail_end
= mail_start
;
346 while (mail_end
< msg_end
&& *mail_end
!= '>')
348 if (mail_end
== msg_end
)
352 if (part
== 'N' || part
== 'E') { /* mailmap lookup */
353 strlcpy(person_name
, name_start
, name_end
-name_start
+1);
354 strlcpy(person_mail
, mail_start
, mail_end
-mail_start
+1);
355 mailmap_name(person_mail
, sizeof(person_mail
), person_name
, sizeof(person_name
));
356 name_start
= person_name
;
357 name_end
= name_start
+ strlen(person_name
);
358 mail_start
= person_mail
;
359 mail_end
= mail_start
+ strlen(person_mail
);
361 if (part
== 'n' || part
== 'N') { /* name */
362 strbuf_add(sb
, name_start
, name_end
-name_start
);
363 return placeholder_len
;
365 if (part
== 'e' || part
== 'E') { /* email */
366 strbuf_add(sb
, mail_start
, mail_end
-mail_start
);
367 return placeholder_len
;
370 /* advance 'start' to point to date start delimiter */
371 for (start
= end
+ 1; start
< len
&& isspace(msg
[start
]); start
++)
375 date
= strtoul(msg
+ start
, &ep
, 10);
376 if (msg
+ start
== ep
)
379 if (part
== 't') { /* date, UNIX timestamp */
380 strbuf_add(sb
, msg
+ start
, ep
- (msg
+ start
));
381 return placeholder_len
;
385 for (start
= ep
- msg
+ 1; start
< len
&& isspace(msg
[start
]); start
++)
387 if (start
+ 1 < len
) {
388 tz
= strtoul(msg
+ start
+ 1, NULL
, 10);
389 if (msg
[start
] == '-')
395 strbuf_addstr(sb
, show_date(date
, tz
, dmode
));
396 return placeholder_len
;
397 case 'D': /* date, RFC2822 style */
398 strbuf_addstr(sb
, show_date(date
, tz
, DATE_RFC2822
));
399 return placeholder_len
;
400 case 'r': /* date, relative */
401 strbuf_addstr(sb
, show_date(date
, tz
, DATE_RELATIVE
));
402 return placeholder_len
;
403 case 'i': /* date, ISO 8601 */
404 strbuf_addstr(sb
, show_date(date
, tz
, DATE_ISO8601
));
405 return placeholder_len
;
410 * bogus commit, 'sb' cannot be updated, but we still need to
411 * compute a valid return value.
413 if (part
== 'n' || part
== 'e' || part
== 't' || part
== 'd'
414 || part
== 'D' || part
== 'r' || part
== 'i')
415 return placeholder_len
;
417 return 0; /* unknown placeholder */
425 struct format_commit_context
{
426 const struct commit
*commit
;
427 enum date_mode dmode
;
428 unsigned commit_header_parsed
:1;
429 unsigned commit_message_parsed
:1;
431 /* These offsets are relative to the start of the commit message. */
433 struct chunk committer
;
434 struct chunk encoding
;
439 /* The following ones are relative to the result struct strbuf. */
440 struct chunk abbrev_commit_hash
;
441 struct chunk abbrev_tree_hash
;
442 struct chunk abbrev_parent_hashes
;
445 static int add_again(struct strbuf
*sb
, struct chunk
*chunk
)
448 strbuf_adddup(sb
, chunk
->off
, chunk
->len
);
453 * We haven't seen this chunk before. Our caller is surely
454 * going to add it the hard way now. Remember the most likely
455 * start of the to-be-added chunk: the current end of the
458 chunk
->off
= sb
->len
;
462 static void parse_commit_header(struct format_commit_context
*context
)
464 const char *msg
= context
->commit
->buffer
;
467 for (i
= 0; msg
[i
]; i
++) {
469 for (eol
= i
; msg
[eol
] && msg
[eol
] != '\n'; eol
++)
474 } else if (!prefixcmp(msg
+ i
, "author ")) {
475 context
->author
.off
= i
+ 7;
476 context
->author
.len
= eol
- i
- 7;
477 } else if (!prefixcmp(msg
+ i
, "committer ")) {
478 context
->committer
.off
= i
+ 10;
479 context
->committer
.len
= eol
- i
- 10;
480 } else if (!prefixcmp(msg
+ i
, "encoding ")) {
481 context
->encoding
.off
= i
+ 9;
482 context
->encoding
.len
= eol
- i
- 9;
486 context
->message_off
= i
;
487 context
->commit_header_parsed
= 1;
490 const char *format_subject(struct strbuf
*sb
, const char *msg
,
491 const char *line_separator
)
496 const char *line
= msg
;
497 int linelen
= get_one_line(line
);
500 if (!linelen
|| is_empty_line(line
, &linelen
))
505 strbuf_grow(sb
, linelen
+ 2);
507 strbuf_addstr(sb
, line_separator
);
508 strbuf_add(sb
, line
, linelen
);
514 static void parse_commit_message(struct format_commit_context
*c
)
516 const char *msg
= c
->commit
->buffer
+ c
->message_off
;
517 const char *start
= c
->commit
->buffer
;
519 msg
= skip_empty_lines(msg
);
520 c
->subject_off
= msg
- start
;
522 msg
= format_subject(NULL
, msg
, NULL
);
523 msg
= skip_empty_lines(msg
);
524 c
->body_off
= msg
- start
;
526 c
->commit_message_parsed
= 1;
529 static void format_decoration(struct strbuf
*sb
, const struct commit
*commit
)
531 struct name_decoration
*d
;
532 const char *prefix
= " (";
534 load_ref_decorations();
535 d
= lookup_decoration(&name_decoration
, &commit
->object
);
537 strbuf_addstr(sb
, prefix
);
539 strbuf_addstr(sb
, d
->name
);
542 if (prefix
[0] == ',')
543 strbuf_addch(sb
, ')');
546 static size_t format_commit_item(struct strbuf
*sb
, const char *placeholder
,
549 struct format_commit_context
*c
= context
;
550 const struct commit
*commit
= c
->commit
;
551 const char *msg
= commit
->buffer
;
552 struct commit_list
*p
;
555 /* these are independent of the commit */
556 switch (placeholder
[0]) {
558 if (placeholder
[1] == '(') {
559 const char *end
= strchr(placeholder
+ 2, ')');
560 char color
[COLOR_MAXLEN
];
563 color_parse_mem(placeholder
+ 2,
564 end
- (placeholder
+ 2),
565 "--pretty format", color
);
566 strbuf_addstr(sb
, color
);
567 return end
- placeholder
+ 1;
569 if (!prefixcmp(placeholder
+ 1, "red")) {
570 strbuf_addstr(sb
, "\033[31m");
572 } else if (!prefixcmp(placeholder
+ 1, "green")) {
573 strbuf_addstr(sb
, "\033[32m");
575 } else if (!prefixcmp(placeholder
+ 1, "blue")) {
576 strbuf_addstr(sb
, "\033[34m");
578 } else if (!prefixcmp(placeholder
+ 1, "reset")) {
579 strbuf_addstr(sb
, "\033[m");
583 case 'n': /* newline */
584 strbuf_addch(sb
, '\n');
587 /* %x00 == NUL, %x0a == LF, etc. */
588 if (0 <= (h1
= hexval_table
[0xff & placeholder
[1]]) &&
590 0 <= (h2
= hexval_table
[0xff & placeholder
[2]]) &&
592 strbuf_addch(sb
, (h1
<<4)|h2
);
598 /* these depend on the commit */
599 if (!commit
->object
.parsed
)
600 parse_object(commit
->object
.sha1
);
602 switch (placeholder
[0]) {
603 case 'H': /* commit hash */
604 strbuf_addstr(sb
, sha1_to_hex(commit
->object
.sha1
));
606 case 'h': /* abbreviated commit hash */
607 if (add_again(sb
, &c
->abbrev_commit_hash
))
609 strbuf_addstr(sb
, find_unique_abbrev(commit
->object
.sha1
,
611 c
->abbrev_commit_hash
.len
= sb
->len
- c
->abbrev_commit_hash
.off
;
613 case 'T': /* tree hash */
614 strbuf_addstr(sb
, sha1_to_hex(commit
->tree
->object
.sha1
));
616 case 't': /* abbreviated tree hash */
617 if (add_again(sb
, &c
->abbrev_tree_hash
))
619 strbuf_addstr(sb
, find_unique_abbrev(commit
->tree
->object
.sha1
,
621 c
->abbrev_tree_hash
.len
= sb
->len
- c
->abbrev_tree_hash
.off
;
623 case 'P': /* parent hashes */
624 for (p
= commit
->parents
; p
; p
= p
->next
) {
625 if (p
!= commit
->parents
)
626 strbuf_addch(sb
, ' ');
627 strbuf_addstr(sb
, sha1_to_hex(p
->item
->object
.sha1
));
630 case 'p': /* abbreviated parent hashes */
631 if (add_again(sb
, &c
->abbrev_parent_hashes
))
633 for (p
= commit
->parents
; p
; p
= p
->next
) {
634 if (p
!= commit
->parents
)
635 strbuf_addch(sb
, ' ');
636 strbuf_addstr(sb
, find_unique_abbrev(
637 p
->item
->object
.sha1
, DEFAULT_ABBREV
));
639 c
->abbrev_parent_hashes
.len
= sb
->len
-
640 c
->abbrev_parent_hashes
.off
;
642 case 'm': /* left/right/bottom */
643 strbuf_addch(sb
, (commit
->object
.flags
& BOUNDARY
)
645 : (commit
->object
.flags
& SYMMETRIC_LEFT
)
650 format_decoration(sb
, commit
);
654 /* For the rest we have to parse the commit header. */
655 if (!c
->commit_header_parsed
)
656 parse_commit_header(c
);
658 switch (placeholder
[0]) {
659 case 'a': /* author ... */
660 return format_person_part(sb
, placeholder
[1],
661 msg
+ c
->author
.off
, c
->author
.len
,
663 case 'c': /* committer ... */
664 return format_person_part(sb
, placeholder
[1],
665 msg
+ c
->committer
.off
, c
->committer
.len
,
667 case 'e': /* encoding */
668 strbuf_add(sb
, msg
+ c
->encoding
.off
, c
->encoding
.len
);
672 /* Now we need to parse the commit message. */
673 if (!c
->commit_message_parsed
)
674 parse_commit_message(c
);
676 switch (placeholder
[0]) {
677 case 's': /* subject */
678 format_subject(sb
, msg
+ c
->subject_off
, " ");
681 strbuf_addstr(sb
, msg
+ c
->body_off
);
684 return 0; /* unknown placeholder */
687 void format_commit_message(const struct commit
*commit
,
688 const void *format
, struct strbuf
*sb
,
689 enum date_mode dmode
)
691 struct format_commit_context context
;
693 memset(&context
, 0, sizeof(context
));
694 context
.commit
= commit
;
695 context
.dmode
= dmode
;
696 strbuf_expand(sb
, format
, format_commit_item
, &context
);
699 static void pp_header(enum cmit_fmt fmt
,
701 enum date_mode dmode
,
702 const char *encoding
,
703 const struct commit
*commit
,
707 int parents_shown
= 0;
710 const char *line
= *msg_p
;
711 int linelen
= get_one_line(*msg_p
);
721 if (fmt
== CMIT_FMT_RAW
) {
722 strbuf_add(sb
, line
, linelen
);
726 if (!memcmp(line
, "parent ", 7)) {
728 die("bad parent line in commit");
732 if (!parents_shown
) {
733 struct commit_list
*parent
;
735 for (parent
= commit
->parents
, num
= 0;
737 parent
= parent
->next
, num
++)
739 /* with enough slop */
740 strbuf_grow(sb
, num
* 50 + 20);
741 add_merge_info(fmt
, sb
, commit
, abbrev
);
746 * MEDIUM == DEFAULT shows only author with dates.
747 * FULL shows both authors but not dates.
748 * FULLER shows both authors and dates.
750 if (!memcmp(line
, "author ", 7)) {
751 strbuf_grow(sb
, linelen
+ 80);
752 pp_user_info("Author", fmt
, sb
, line
+ 7, dmode
, encoding
);
754 if (!memcmp(line
, "committer ", 10) &&
755 (fmt
== CMIT_FMT_FULL
|| fmt
== CMIT_FMT_FULLER
)) {
756 strbuf_grow(sb
, linelen
+ 80);
757 pp_user_info("Commit", fmt
, sb
, line
+ 10, dmode
, encoding
);
762 void pp_title_line(enum cmit_fmt fmt
,
766 const char *after_subject
,
767 const char *encoding
,
770 const char *line_separator
= (fmt
== CMIT_FMT_EMAIL
) ? "\n " : " ";
773 strbuf_init(&title
, 80);
774 *msg_p
= format_subject(&title
, *msg_p
, line_separator
);
776 strbuf_grow(sb
, title
.len
+ 1024);
778 strbuf_addstr(sb
, subject
);
779 add_rfc2047(sb
, title
.buf
, title
.len
, encoding
);
781 strbuf_addbuf(sb
, &title
);
783 strbuf_addch(sb
, '\n');
785 if (need_8bit_cte
> 0) {
786 const char *header_fmt
=
787 "MIME-Version: 1.0\n"
788 "Content-Type: text/plain; charset=%s\n"
789 "Content-Transfer-Encoding: 8bit\n";
790 strbuf_addf(sb
, header_fmt
, encoding
);
793 strbuf_addstr(sb
, after_subject
);
795 if (fmt
== CMIT_FMT_EMAIL
) {
796 strbuf_addch(sb
, '\n');
798 strbuf_release(&title
);
801 void pp_remainder(enum cmit_fmt fmt
,
808 const char *line
= *msg_p
;
809 int linelen
= get_one_line(line
);
815 if (is_empty_line(line
, &linelen
)) {
818 if (fmt
== CMIT_FMT_SHORT
)
823 strbuf_grow(sb
, linelen
+ indent
+ 20);
825 memset(sb
->buf
+ sb
->len
, ' ', indent
);
826 strbuf_setlen(sb
, sb
->len
+ indent
);
828 strbuf_add(sb
, line
, linelen
);
829 strbuf_addch(sb
, '\n');
833 char *reencode_commit_message(const struct commit
*commit
, const char **encoding_p
)
835 const char *encoding
;
837 encoding
= (git_log_output_encoding
838 ? git_log_output_encoding
839 : git_commit_encoding
);
843 *encoding_p
= encoding
;
844 return logmsg_reencode(commit
, encoding
);
847 void pretty_print_commit(enum cmit_fmt fmt
, const struct commit
*commit
,
848 struct strbuf
*sb
, int abbrev
,
849 const char *subject
, const char *after_subject
,
850 enum date_mode dmode
, int need_8bit_cte
)
852 unsigned long beginning_of_body
;
854 const char *msg
= commit
->buffer
;
856 const char *encoding
;
858 if (fmt
== CMIT_FMT_USERFORMAT
) {
859 format_commit_message(commit
, user_format
, sb
, dmode
);
863 reencoded
= reencode_commit_message(commit
, &encoding
);
868 if (fmt
== CMIT_FMT_ONELINE
|| fmt
== CMIT_FMT_EMAIL
)
872 * We need to check and emit Content-type: to mark it
873 * as 8-bit if we haven't done so.
875 if (fmt
== CMIT_FMT_EMAIL
&& need_8bit_cte
== 0) {
878 for (in_body
= i
= 0; (ch
= msg
[i
]); i
++) {
880 /* author could be non 7-bit ASCII but
881 * the log may be so; skip over the
884 if (ch
== '\n' && msg
[i
+1] == '\n')
887 else if (non_ascii(ch
)) {
894 pp_header(fmt
, abbrev
, dmode
, encoding
, commit
, &msg
, sb
);
895 if (fmt
!= CMIT_FMT_ONELINE
&& !subject
) {
896 strbuf_addch(sb
, '\n');
899 /* Skip excess blank lines at the beginning of body, if any... */
900 msg
= skip_empty_lines(msg
);
902 /* These formats treat the title line specially. */
903 if (fmt
== CMIT_FMT_ONELINE
|| fmt
== CMIT_FMT_EMAIL
)
904 pp_title_line(fmt
, &msg
, sb
, subject
,
905 after_subject
, encoding
, need_8bit_cte
);
907 beginning_of_body
= sb
->len
;
908 if (fmt
!= CMIT_FMT_ONELINE
)
909 pp_remainder(fmt
, &msg
, sb
, indent
);
912 /* Make sure there is an EOLN for the non-oneline case */
913 if (fmt
!= CMIT_FMT_ONELINE
)
914 strbuf_addch(sb
, '\n');
917 * The caller may append additional body text in e-mail
918 * format. Make sure we did not strip the blank line
919 * between the header and the body.
921 if (fmt
== CMIT_FMT_EMAIL
&& sb
->len
<= beginning_of_body
)
922 strbuf_addch(sb
, '\n');