Skip to content

Commit

Permalink
sequencer.c: teach append_signoff to avoid adding a duplicate newline
Browse files Browse the repository at this point in the history
Teach append_signoff to detect whether a blank line exists at the position
that the signed-off-by line will be added, and refrain from adding an
additional one if one already exists.  Or, add an additional line if one
is needed to make sure the new footer is separated from the message body
by a blank line.

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Brandon Casey authored and Junio C Hamano committed Feb 12, 2013
1 parent bab4d10 commit 33f2f9a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,19 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
else
has_footer = has_conforming_footer(msgbuf, &sob, ignore_footer);

if (!has_footer)
strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, "\n", 1);
if (!has_footer) {
const char *append_newlines = NULL;
size_t len = msgbuf->len - ignore_footer;

if (len && msgbuf->buf[len - 1] != '\n')
append_newlines = "\n\n";
else if (len > 1 && msgbuf->buf[len - 2] != '\n')
append_newlines = "\n";

if (append_newlines)
strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
append_newlines, strlen(append_newlines));
}

if (has_footer != 3 && (!no_dup_sob || has_footer != 2))
strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
Expand Down

0 comments on commit 33f2f9a

Please sign in to comment.