[PATCH v2 07/10] sequencer.c: teach append_signoff to avoid adding a duplicate newline
- From
Brandon Casey <drafnel@gmail.com>
- Date
- Jan 21, 2013, 08:40 UTC
- Message-ID
- <1358757627-16682-8-git-send-email-drafnel@gmail.com>
- In-Reply-To
- <1358757627-16682-1-git-send-email-drafnel@gmail.com>
Teach append_signoff to detect whether a blank line exists at the position that the signed-off-by line will be added, and avoid adding an additional one if one already exists. This is necessary to allow format-patch to add a s-o-b to a patch with no commit message without adding an extra newline. A following patch will make format-patch use this function rather than the append_signoff implementation inside log-tree.c.
Signed-off-by: Brandon Casey <bcasey@nvidia.com> --- sequencer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/sequencer.c b/sequencer.c index d4a2ece..d51e6f2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1114,11 +1114,15 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, int no_dup_sob) for (i = msgbuf->len - 1 - ignore_footer; i > 0 && msgbuf->buf[i - 1] != '\n'; i--) ; /* do nothing */ - if (i) - has_footer = has_conforming_footer(msgbuf, &sob, ignore_footer); - - if (!has_footer) - strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, "\n", 1); + if (msgbuf->buf[i] != '\n') { + if (i) + 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 != 3 && (!no_dup_sob || has_footer != 2)) strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
-- 1.8.1.1.252.gdb33759