6 #include "string-list.h"
11 static char *user_format
;
13 static void save_user_format(struct rev_info
*rev
, const char *cp
, int is_tformat
)
16 user_format
= xstrdup(cp
);
18 rev
->use_terminator
= 1;
19 rev
->commit_format
= CMIT_FMT_USERFORMAT
;
22 void get_commit_format(const char *arg
, struct rev_info
*rev
)
25 static struct cmt_fmt_map
{
30 { "raw", 1, CMIT_FMT_RAW
},
31 { "medium", 1, CMIT_FMT_MEDIUM
},
32 { "short", 1, CMIT_FMT_SHORT
},
33 { "email", 1, CMIT_FMT_EMAIL
},
34 { "full", 5, CMIT_FMT_FULL
},
35 { "fuller", 5, CMIT_FMT_FULLER
},
36 { "oneline", 1, CMIT_FMT_ONELINE
},
39 rev
->use_terminator
= 0;
41 rev
->commit_format
= CMIT_FMT_DEFAULT
;
44 if (!prefixcmp(arg
, "format:") || !prefixcmp(arg
, "tformat:")) {
45 save_user_format(rev
, strchr(arg
, ':') + 1, arg
[0] == 't');
48 for (i
= 0; i
< ARRAY_SIZE(cmt_fmts
); i
++) {
49 if (!strncmp(arg
, cmt_fmts
[i
].n
, cmt_fmts
[i
].cmp_len
) &&
50 !strncmp(arg
, cmt_fmts
[i
].n
, strlen(arg
))) {
51 if (cmt_fmts
[i
].v
== CMIT_FMT_ONELINE
)
52 rev
->use_terminator
= 1;
53 rev
->commit_format
= cmt_fmts
[i
].v
;
57 if (strchr(arg
, '%')) {
58 save_user_format(rev
, arg
, 1);
62 die("invalid --pretty format: %s", arg
);
66 * Generic support for pretty-printing the header
68 static int get_one_line(const char *msg
)
83 /* High bit set, or ISO-2022-INT */
86 return !isascii(ch
) || ch
== '\033';
89 static int is_rfc2047_special(char ch
)
91 return (non_ascii(ch
) || (ch
== '=') || (ch
== '?') || (ch
== '_'));
94 static void add_rfc2047(struct strbuf
*sb
, const char *line
, int len
,
99 for (i
= 0; i
< len
; i
++) {
103 if ((i
+ 1 < len
) && (ch
== '=' && line
[i
+1] == '?'))
106 strbuf_add(sb
, line
, len
);
110 strbuf_grow(sb
, len
* 3 + strlen(encoding
) + 100);
111 strbuf_addf(sb
, "=?%s?q?", encoding
);
112 for (i
= last
= 0; i
< len
; i
++) {
113 unsigned ch
= line
[i
] & 0xFF;
115 * We encode ' ' using '=20' even though rfc2047
116 * allows using '_' for readability. Unfortunately,
117 * many programs do not understand this and just
118 * leave the underscore in place.
120 if (is_rfc2047_special(ch
) || ch
== ' ') {
121 strbuf_add(sb
, line
+ last
, i
- last
);
122 strbuf_addf(sb
, "=%02X", ch
);
126 strbuf_add(sb
, line
+ last
, len
- last
);
127 strbuf_addstr(sb
, "?=");
130 void pp_user_info(const char *what
, enum cmit_fmt fmt
, struct strbuf
*sb
,
131 const char *line
, enum date_mode dmode
,
132 const char *encoding
)
139 if (fmt
== CMIT_FMT_ONELINE
)
141 date
= strchr(line
, '>');
144 namelen
= ++date
- line
;
145 time
= strtoul(date
, &date
, 10);
146 tz
= strtol(date
, NULL
, 10);
148 if (fmt
== CMIT_FMT_EMAIL
) {
149 char *name_tail
= strchr(line
, '<');
150 int display_name_length
;
153 while (line
< name_tail
&& isspace(name_tail
[-1]))
155 display_name_length
= name_tail
- line
;
156 strbuf_addstr(sb
, "From: ");
157 add_rfc2047(sb
, line
, display_name_length
, encoding
);
158 strbuf_add(sb
, name_tail
, namelen
- display_name_length
);
159 strbuf_addch(sb
, '\n');
161 strbuf_addf(sb
, "%s: %.*s%.*s\n", what
,
162 (fmt
== CMIT_FMT_FULLER
) ? 4 : 0,
166 case CMIT_FMT_MEDIUM
:
167 strbuf_addf(sb
, "Date: %s\n", show_date(time
, tz
, dmode
));
170 strbuf_addf(sb
, "Date: %s\n", show_date(time
, tz
, DATE_RFC2822
));
172 case CMIT_FMT_FULLER
:
173 strbuf_addf(sb
, "%sDate: %s\n", what
, show_date(time
, tz
, dmode
));
181 static int is_empty_line(const char *line
, int *len_p
)
184 while (len
&& isspace(line
[len
-1]))
190 static const char *skip_empty_lines(const char *msg
)
193 int linelen
= get_one_line(msg
);
197 if (!is_empty_line(msg
, &ll
))
204 static void add_merge_info(enum cmit_fmt fmt
, struct strbuf
*sb
,
205 const struct commit
*commit
, int abbrev
)
207 struct commit_list
*parent
= commit
->parents
;
209 if ((fmt
== CMIT_FMT_ONELINE
) || (fmt
== CMIT_FMT_EMAIL
) ||
210 !parent
|| !parent
->next
)
213 strbuf_addstr(sb
, "Merge:");
216 struct commit
*p
= parent
->item
;
217 const char *hex
= NULL
;
219 hex
= find_unique_abbrev(p
->object
.sha1
, abbrev
);
221 hex
= sha1_to_hex(p
->object
.sha1
);
222 parent
= parent
->next
;
224 strbuf_addf(sb
, " %s", hex
);
226 strbuf_addch(sb
, '\n');
229 static char *get_header(const struct commit
*commit
, const char *key
)
231 int key_len
= strlen(key
);
232 const char *line
= commit
->buffer
;
235 const char *eol
= strchr(line
, '\n'), *next
;
240 eol
= line
+ strlen(line
);
244 if (eol
- line
> key_len
&&
245 !strncmp(line
, key
, key_len
) &&
246 line
[key_len
] == ' ') {
247 return xmemdupz(line
+ key_len
+ 1, eol
- line
- key_len
- 1);
253 static char *replace_encoding_header(char *buf
, const char *encoding
)
255 struct strbuf tmp
= STRBUF_INIT
;
259 /* guess if there is an encoding header before a \n\n */
260 while (strncmp(cp
, "encoding ", strlen("encoding "))) {
261 cp
= strchr(cp
, '\n');
262 if (!cp
|| *++cp
== '\n')
266 cp
= strchr(cp
, '\n');
268 return buf
; /* should not happen but be defensive */
269 len
= cp
+ 1 - (buf
+ start
);
271 strbuf_attach(&tmp
, buf
, strlen(buf
), strlen(buf
) + 1);
272 if (is_encoding_utf8(encoding
)) {
273 /* we have re-coded to UTF-8; drop the header */
274 strbuf_remove(&tmp
, start
, len
);
276 /* just replaces XXXX in 'encoding XXXX\n' */
277 strbuf_splice(&tmp
, start
+ strlen("encoding "),
278 len
- strlen("encoding \n"),
279 encoding
, strlen(encoding
));
281 return strbuf_detach(&tmp
, NULL
);
284 static char *logmsg_reencode(const struct commit
*commit
,
285 const char *output_encoding
)
287 static const char *utf8
= "utf-8";
288 const char *use_encoding
;
292 if (!*output_encoding
)
294 encoding
= get_header(commit
, "encoding");
295 use_encoding
= encoding
? encoding
: utf8
;
296 if (!strcmp(use_encoding
, output_encoding
))
297 if (encoding
) /* we'll strip encoding header later */
298 out
= xstrdup(commit
->buffer
);
300 return NULL
; /* nothing to do */
302 out
= reencode_string(commit
->buffer
,
303 output_encoding
, use_encoding
);
305 out
= replace_encoding_header(out
, output_encoding
);
311 static int mailmap_name(char *email
, int email_len
, char *name
, int name_len
)
313 static struct string_list
*mail_map
;
315 mail_map
= xcalloc(1, sizeof(*mail_map
));
316 read_mailmap(mail_map
, NULL
);
318 return mail_map
->nr
&& map_user(mail_map
, email
, email_len
, name
, name_len
);
321 static size_t format_person_part(struct strbuf
*sb
, char part
,
322 const char *msg
, int len
, enum date_mode dmode
)
324 /* currently all placeholders have same length */
325 const int placeholder_len
= 2;
326 int start
, end
, tz
= 0;
327 unsigned long date
= 0;
329 const char *name_start
, *name_end
, *mail_start
, *mail_end
, *msg_end
= msg
+len
;
330 char person_name
[1024];
331 char person_mail
[1024];
333 /* advance 'end' to point to email start delimiter */
334 for (end
= 0; end
< len
&& msg
[end
] != '<'; end
++)
338 * When end points at the '<' that we found, it should have
339 * matching '>' later, which means 'end' must be strictly
345 /* Seek for both name and email part */
348 while (name_end
> name_start
&& isspace(*(name_end
-1)))
350 mail_start
= msg
+end
+1;
351 mail_end
= mail_start
;
352 while (mail_end
< msg_end
&& *mail_end
!= '>')
354 if (mail_end
== msg_end
)
358 if (part
== 'N' || part
== 'E') { /* mailmap lookup */
359 strlcpy(person_name
, name_start
, name_end
-name_start
+1);
360 strlcpy(person_mail
, mail_start
, mail_end
-mail_start
+1);
361 mailmap_name(person_mail
, sizeof(person_mail
), person_name
, sizeof(person_name
));
362 name_start
= person_name
;
363 name_end
= name_start
+ strlen(person_name
);
364 mail_start
= person_mail
;
365 mail_end
= mail_start
+ strlen(person_mail
);
367 if (part
== 'n' || part
== 'N') { /* name */
368 strbuf_add(sb
, name_start
, name_end
-name_start
);
369 return placeholder_len
;
371 if (part
== 'e' || part
== 'E') { /* email */
372 strbuf_add(sb
, mail_start
, mail_end
-mail_start
);
373 return placeholder_len
;
376 /* advance 'start' to point to date start delimiter */
377 for (start
= end
+ 1; start
< len
&& isspace(msg
[start
]); start
++)
381 date
= strtoul(msg
+ start
, &ep
, 10);
382 if (msg
+ start
== ep
)
385 if (part
== 't') { /* date, UNIX timestamp */
386 strbuf_add(sb
, msg
+ start
, ep
- (msg
+ start
));
387 return placeholder_len
;
391 for (start
= ep
- msg
+ 1; start
< len
&& isspace(msg
[start
]); start
++)
393 if (start
+ 1 < len
) {
394 tz
= strtoul(msg
+ start
+ 1, NULL
, 10);
395 if (msg
[start
] == '-')
401 strbuf_addstr(sb
, show_date(date
, tz
, dmode
));
402 return placeholder_len
;
403 case 'D': /* date, RFC2822 style */
404 strbuf_addstr(sb
, show_date(date
, tz
, DATE_RFC2822
));
405 return placeholder_len
;
406 case 'r': /* date, relative */
407 strbuf_addstr(sb
, show_date(date
, tz
, DATE_RELATIVE
));
408 return placeholder_len
;
409 case 'i': /* date, ISO 8601 */
410 strbuf_addstr(sb
, show_date(date
, tz
, DATE_ISO8601
));
411 return placeholder_len
;
416 * bogus commit, 'sb' cannot be updated, but we still need to
417 * compute a valid return value.
419 if (part
== 'n' || part
== 'e' || part
== 't' || part
== 'd'
420 || part
== 'D' || part
== 'r' || part
== 'i')
421 return placeholder_len
;
423 return 0; /* unknown placeholder */
431 struct format_commit_context
{
432 const struct commit
*commit
;
433 enum date_mode dmode
;
434 unsigned commit_header_parsed
:1;
435 unsigned commit_message_parsed
:1;
437 /* These offsets are relative to the start of the commit message. */
439 struct chunk committer
;
440 struct chunk encoding
;
445 /* The following ones are relative to the result struct strbuf. */
446 struct chunk abbrev_commit_hash
;
447 struct chunk abbrev_tree_hash
;
448 struct chunk abbrev_parent_hashes
;
451 static int add_again(struct strbuf
*sb
, struct chunk
*chunk
)
454 strbuf_adddup(sb
, chunk
->off
, chunk
->len
);
459 * We haven't seen this chunk before. Our caller is surely
460 * going to add it the hard way now. Remember the most likely
461 * start of the to-be-added chunk: the current end of the
464 chunk
->off
= sb
->len
;
468 static void parse_commit_header(struct format_commit_context
*context
)
470 const char *msg
= context
->commit
->buffer
;
473 for (i
= 0; msg
[i
]; i
++) {
475 for (eol
= i
; msg
[eol
] && msg
[eol
] != '\n'; eol
++)
480 } else if (!prefixcmp(msg
+ i
, "author ")) {
481 context
->author
.off
= i
+ 7;
482 context
->author
.len
= eol
- i
- 7;
483 } else if (!prefixcmp(msg
+ i
, "committer ")) {
484 context
->committer
.off
= i
+ 10;
485 context
->committer
.len
= eol
- i
- 10;
486 } else if (!prefixcmp(msg
+ i
, "encoding ")) {
487 context
->encoding
.off
= i
+ 9;
488 context
->encoding
.len
= eol
- i
- 9;
492 context
->message_off
= i
;
493 context
->commit_header_parsed
= 1;
496 const char *format_subject(struct strbuf
*sb
, const char *msg
,
497 const char *line_separator
)
502 const char *line
= msg
;
503 int linelen
= get_one_line(line
);
506 if (!linelen
|| is_empty_line(line
, &linelen
))
511 strbuf_grow(sb
, linelen
+ 2);
513 strbuf_addstr(sb
, line_separator
);
514 strbuf_add(sb
, line
, linelen
);
520 static void parse_commit_message(struct format_commit_context
*c
)
522 const char *msg
= c
->commit
->buffer
+ c
->message_off
;
523 const char *start
= c
->commit
->buffer
;
525 msg
= skip_empty_lines(msg
);
526 c
->subject_off
= msg
- start
;
528 msg
= format_subject(NULL
, msg
, NULL
);
529 msg
= skip_empty_lines(msg
);
530 c
->body_off
= msg
- start
;
532 c
->commit_message_parsed
= 1;
535 static void format_decoration(struct strbuf
*sb
, const struct commit
*commit
)
537 struct name_decoration
*d
;
538 const char *prefix
= " (";
540 load_ref_decorations();
541 d
= lookup_decoration(&name_decoration
, &commit
->object
);
543 strbuf_addstr(sb
, prefix
);
545 strbuf_addstr(sb
, d
->name
);
548 if (prefix
[0] == ',')
549 strbuf_addch(sb
, ')');
552 static size_t format_commit_item(struct strbuf
*sb
, const char *placeholder
,
555 struct format_commit_context
*c
= context
;
556 const struct commit
*commit
= c
->commit
;
557 const char *msg
= commit
->buffer
;
558 struct commit_list
*p
;
561 /* these are independent of the commit */
562 switch (placeholder
[0]) {
564 if (placeholder
[1] == '(') {
565 const char *end
= strchr(placeholder
+ 2, ')');
566 char color
[COLOR_MAXLEN
];
569 color_parse_mem(placeholder
+ 2,
570 end
- (placeholder
+ 2),
571 "--pretty format", color
);
572 strbuf_addstr(sb
, color
);
573 return end
- placeholder
+ 1;
575 if (!prefixcmp(placeholder
+ 1, "red")) {
576 strbuf_addstr(sb
, GIT_COLOR_RED
);
578 } else if (!prefixcmp(placeholder
+ 1, "green")) {
579 strbuf_addstr(sb
, GIT_COLOR_GREEN
);
581 } else if (!prefixcmp(placeholder
+ 1, "blue")) {
582 strbuf_addstr(sb
, GIT_COLOR_BLUE
);
584 } else if (!prefixcmp(placeholder
+ 1, "reset")) {
585 strbuf_addstr(sb
, GIT_COLOR_RESET
);
589 case 'n': /* newline */
590 strbuf_addch(sb
, '\n');
593 /* %x00 == NUL, %x0a == LF, etc. */
594 if (0 <= (h1
= hexval_table
[0xff & placeholder
[1]]) &&
596 0 <= (h2
= hexval_table
[0xff & placeholder
[2]]) &&
598 strbuf_addch(sb
, (h1
<<4)|h2
);
604 /* these depend on the commit */
605 if (!commit
->object
.parsed
)
606 parse_object(commit
->object
.sha1
);
608 switch (placeholder
[0]) {
609 case 'H': /* commit hash */
610 strbuf_addstr(sb
, sha1_to_hex(commit
->object
.sha1
));
612 case 'h': /* abbreviated commit hash */
613 if (add_again(sb
, &c
->abbrev_commit_hash
))
615 strbuf_addstr(sb
, find_unique_abbrev(commit
->object
.sha1
,
617 c
->abbrev_commit_hash
.len
= sb
->len
- c
->abbrev_commit_hash
.off
;
619 case 'T': /* tree hash */
620 strbuf_addstr(sb
, sha1_to_hex(commit
->tree
->object
.sha1
));
622 case 't': /* abbreviated tree hash */
623 if (add_again(sb
, &c
->abbrev_tree_hash
))
625 strbuf_addstr(sb
, find_unique_abbrev(commit
->tree
->object
.sha1
,
627 c
->abbrev_tree_hash
.len
= sb
->len
- c
->abbrev_tree_hash
.off
;
629 case 'P': /* parent hashes */
630 for (p
= commit
->parents
; p
; p
= p
->next
) {
631 if (p
!= commit
->parents
)
632 strbuf_addch(sb
, ' ');
633 strbuf_addstr(sb
, sha1_to_hex(p
->item
->object
.sha1
));
636 case 'p': /* abbreviated parent hashes */
637 if (add_again(sb
, &c
->abbrev_parent_hashes
))
639 for (p
= commit
->parents
; p
; p
= p
->next
) {
640 if (p
!= commit
->parents
)
641 strbuf_addch(sb
, ' ');
642 strbuf_addstr(sb
, find_unique_abbrev(
643 p
->item
->object
.sha1
, DEFAULT_ABBREV
));
645 c
->abbrev_parent_hashes
.len
= sb
->len
-
646 c
->abbrev_parent_hashes
.off
;
648 case 'm': /* left/right/bottom */
649 strbuf_addch(sb
, (commit
->object
.flags
& BOUNDARY
)
651 : (commit
->object
.flags
& SYMMETRIC_LEFT
)
656 format_decoration(sb
, commit
);
660 /* For the rest we have to parse the commit header. */
661 if (!c
->commit_header_parsed
)
662 parse_commit_header(c
);
664 switch (placeholder
[0]) {
665 case 'a': /* author ... */
666 return format_person_part(sb
, placeholder
[1],
667 msg
+ c
->author
.off
, c
->author
.len
,
669 case 'c': /* committer ... */
670 return format_person_part(sb
, placeholder
[1],
671 msg
+ c
->committer
.off
, c
->committer
.len
,
673 case 'e': /* encoding */
674 strbuf_add(sb
, msg
+ c
->encoding
.off
, c
->encoding
.len
);
678 /* Now we need to parse the commit message. */
679 if (!c
->commit_message_parsed
)
680 parse_commit_message(c
);
682 switch (placeholder
[0]) {
683 case 's': /* subject */
684 format_subject(sb
, msg
+ c
->subject_off
, " ");
687 strbuf_addstr(sb
, msg
+ c
->body_off
);
690 return 0; /* unknown placeholder */
693 void format_commit_message(const struct commit
*commit
,
694 const void *format
, struct strbuf
*sb
,
695 enum date_mode dmode
)
697 struct format_commit_context context
;
699 memset(&context
, 0, sizeof(context
));
700 context
.commit
= commit
;
701 context
.dmode
= dmode
;
702 strbuf_expand(sb
, format
, format_commit_item
, &context
);
705 static void pp_header(enum cmit_fmt fmt
,
707 enum date_mode dmode
,
708 const char *encoding
,
709 const struct commit
*commit
,
713 int parents_shown
= 0;
716 const char *line
= *msg_p
;
717 int linelen
= get_one_line(*msg_p
);
727 if (fmt
== CMIT_FMT_RAW
) {
728 strbuf_add(sb
, line
, linelen
);
732 if (!memcmp(line
, "parent ", 7)) {
734 die("bad parent line in commit");
738 if (!parents_shown
) {
739 struct commit_list
*parent
;
741 for (parent
= commit
->parents
, num
= 0;
743 parent
= parent
->next
, num
++)
745 /* with enough slop */
746 strbuf_grow(sb
, num
* 50 + 20);
747 add_merge_info(fmt
, sb
, commit
, abbrev
);
752 * MEDIUM == DEFAULT shows only author with dates.
753 * FULL shows both authors but not dates.
754 * FULLER shows both authors and dates.
756 if (!memcmp(line
, "author ", 7)) {
757 strbuf_grow(sb
, linelen
+ 80);
758 pp_user_info("Author", fmt
, sb
, line
+ 7, dmode
, encoding
);
760 if (!memcmp(line
, "committer ", 10) &&
761 (fmt
== CMIT_FMT_FULL
|| fmt
== CMIT_FMT_FULLER
)) {
762 strbuf_grow(sb
, linelen
+ 80);
763 pp_user_info("Commit", fmt
, sb
, line
+ 10, dmode
, encoding
);
768 void pp_title_line(enum cmit_fmt fmt
,
772 const char *after_subject
,
773 const char *encoding
,
776 const char *line_separator
= (fmt
== CMIT_FMT_EMAIL
) ? "\n " : " ";
779 strbuf_init(&title
, 80);
780 *msg_p
= format_subject(&title
, *msg_p
, line_separator
);
782 strbuf_grow(sb
, title
.len
+ 1024);
784 strbuf_addstr(sb
, subject
);
785 add_rfc2047(sb
, title
.buf
, title
.len
, encoding
);
787 strbuf_addbuf(sb
, &title
);
789 strbuf_addch(sb
, '\n');
791 if (need_8bit_cte
> 0) {
792 const char *header_fmt
=
793 "MIME-Version: 1.0\n"
794 "Content-Type: text/plain; charset=%s\n"
795 "Content-Transfer-Encoding: 8bit\n";
796 strbuf_addf(sb
, header_fmt
, encoding
);
799 strbuf_addstr(sb
, after_subject
);
801 if (fmt
== CMIT_FMT_EMAIL
) {
802 strbuf_addch(sb
, '\n');
804 strbuf_release(&title
);
807 void pp_remainder(enum cmit_fmt fmt
,
814 const char *line
= *msg_p
;
815 int linelen
= get_one_line(line
);
821 if (is_empty_line(line
, &linelen
)) {
824 if (fmt
== CMIT_FMT_SHORT
)
829 strbuf_grow(sb
, linelen
+ indent
+ 20);
831 memset(sb
->buf
+ sb
->len
, ' ', indent
);
832 strbuf_setlen(sb
, sb
->len
+ indent
);
834 strbuf_add(sb
, line
, linelen
);
835 strbuf_addch(sb
, '\n');
839 char *reencode_commit_message(const struct commit
*commit
, const char **encoding_p
)
841 const char *encoding
;
843 encoding
= (git_log_output_encoding
844 ? git_log_output_encoding
845 : git_commit_encoding
);
849 *encoding_p
= encoding
;
850 return logmsg_reencode(commit
, encoding
);
853 void pretty_print_commit(enum cmit_fmt fmt
, const struct commit
*commit
,
854 struct strbuf
*sb
, int abbrev
,
855 const char *subject
, const char *after_subject
,
856 enum date_mode dmode
, int need_8bit_cte
)
858 unsigned long beginning_of_body
;
860 const char *msg
= commit
->buffer
;
862 const char *encoding
;
864 if (fmt
== CMIT_FMT_USERFORMAT
) {
865 format_commit_message(commit
, user_format
, sb
, dmode
);
869 reencoded
= reencode_commit_message(commit
, &encoding
);
874 if (fmt
== CMIT_FMT_ONELINE
|| fmt
== CMIT_FMT_EMAIL
)
878 * We need to check and emit Content-type: to mark it
879 * as 8-bit if we haven't done so.
881 if (fmt
== CMIT_FMT_EMAIL
&& need_8bit_cte
== 0) {
884 for (in_body
= i
= 0; (ch
= msg
[i
]); i
++) {
886 /* author could be non 7-bit ASCII but
887 * the log may be so; skip over the
890 if (ch
== '\n' && msg
[i
+1] == '\n')
893 else if (non_ascii(ch
)) {
900 pp_header(fmt
, abbrev
, dmode
, encoding
, commit
, &msg
, sb
);
901 if (fmt
!= CMIT_FMT_ONELINE
&& !subject
) {
902 strbuf_addch(sb
, '\n');
905 /* Skip excess blank lines at the beginning of body, if any... */
906 msg
= skip_empty_lines(msg
);
908 /* These formats treat the title line specially. */
909 if (fmt
== CMIT_FMT_ONELINE
|| fmt
== CMIT_FMT_EMAIL
)
910 pp_title_line(fmt
, &msg
, sb
, subject
,
911 after_subject
, encoding
, need_8bit_cte
);
913 beginning_of_body
= sb
->len
;
914 if (fmt
!= CMIT_FMT_ONELINE
)
915 pp_remainder(fmt
, &msg
, sb
, indent
);
918 /* Make sure there is an EOLN for the non-oneline case */
919 if (fmt
!= CMIT_FMT_ONELINE
)
920 strbuf_addch(sb
, '\n');
923 * The caller may append additional body text in e-mail
924 * format. Make sure we did not strip the blank line
925 * between the header and the body.
927 if (fmt
== CMIT_FMT_EMAIL
&& sb
->len
<= beginning_of_body
)
928 strbuf_addch(sb
, '\n');