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 <bca...@nvidia.com>
---


A slight tweak.  And I promise, no more are coming.

-Brandon


 sequencer.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 3364faa..084573b 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1127,8 +1127,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,
-- 
1.8.1.1.252.gdb33759

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to