@matheusbsbs / matheus-bagliano / commits / 88c44735ab
Fork 0

pretty: factor out format_subject()

The next patch will use it. In the version that was factored out, we can't rely on the len of the struct strbuf to find out if a line separator needs to be added, as it might already contain something. Add a guard variable ("first") instead. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 27, 2008 at 01:39 UTC 88c44735ab24aea3e669501c4491f7c9ca745ca3
1 file changed +24 -18
pretty.c
+24 -18
@@ -495,6 +495,28 @@ static void parse_commit_header(struct format_commit_context *context)
495 context->commit_header_parsed = 1;
496 }
497
498 +static const char *format_subject(struct strbuf *sb, const char *msg,
499 + const char *line_separator)
500 +{
501 + int first = 1;
502 +
503 + for (;;) {
504 + const char *line = msg;
505 + int linelen = get_one_line(line);
506 +
507 + msg += linelen;
508 + if (!linelen || is_empty_line(line, &linelen))
509 + break;
510 +
511 + strbuf_grow(sb, linelen + 2);
512 + if (!first)
513 + strbuf_addstr(sb, line_separator);
514 + strbuf_add(sb, line, linelen);
515 + first = 0;
516 + }
517 + return msg;
518 +}
519 +
520 static void format_decoration(struct strbuf *sb, const struct commit *commit)
521 {
522 struct name_decoration *d;
@@ -718,27 +740,11 @@ void pp_title_line(enum cmit_fmt fmt,
740 const char *encoding,
741 int need_8bit_cte)
742 {
743 + const char *line_separator = (fmt == CMIT_FMT_EMAIL) ? "\n " : " ";
744 struct strbuf title;
745
746 strbuf_init(&title, 80);
724 -
725 - for (;;) {
726 - const char *line = *msg_p;
727 - int linelen = get_one_line(line);
728 -
729 - *msg_p += linelen;
730 - if (!linelen || is_empty_line(line, &linelen))
731 - break;
732 -
733 - strbuf_grow(&title, linelen + 2);
734 - if (title.len) {
735 - if (fmt == CMIT_FMT_EMAIL) {
736 - strbuf_addch(&title, '\n');
737 - }
738 - strbuf_addch(&title, ' ');
739 - }
740 - strbuf_add(&title, line, linelen);
741 - }
747 + *msg_p = format_subject(&title, *msg_p, line_separator);
748
749 strbuf_grow(sb, title.len + 1024);
750 if (subject) {