sequencer.c: require a conforming footer to be preceded by a blank line

Currently, append_signoff() performs a search for the last line of the commit buffer by searching back from the end until it hits a newline. If it reaches the beginning of the buffer without finding a newline, that means either the commit message was empty, or there was only one line in it. In this case, append_signoff will skip the call to has_conforming_footer since it already knows that it is necessary to append a newline before appending the sob. Let's perform this function inside of has_conforming_footer where it appropriately belongs and generalize it so that we require that the footer paragraph be an actual distinct paragraph separated by a blank line. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Feb 12, 2013 at 02:17 UTC 2cdccad1600171e3c53e2e9c22e1675389a9d61a
1 file changed +5 -1
sequencer.c
+5 -1
@@ -1061,6 +1061,10 @@ static int has_conforming_footer(struct strbuf *sb, int ignore_footer)
1061 prev = ch;
1062 }
1063
1064 + /* require at least one blank line */
1065 + if (prev != '\n' || buf[i] != '\n')
1066 + return 0;
1067 +
1068 /* advance to start of last paragraph */
1069 while (i < len - 1 && buf[i] == '\n')
1070 i++;
@@ -1089,7 +1093,7 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer)
1093 for (i = msgbuf->len - 1 - ignore_footer; i > 0 && msgbuf->buf[i - 1] != '\n'; i--)
1094 ; /* do nothing */
1095 if (prefixcmp(msgbuf->buf + i, sob.buf)) {
1092 - if (!i || !has_conforming_footer(msgbuf, ignore_footer))
1096 + if (!has_conforming_footer(msgbuf, ignore_footer))
1097 strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, "\n", 1);
1098 strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, sob.buf, sob.len);
1099 }