OSDN Git Service

trailer: display a trailer without its trailing newline
authorChristian Couder <chriscool@tuxfamily.org>
Sun, 9 Nov 2014 09:23:40 +0000 (10:23 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Nov 2014 17:43:59 +0000 (09:43 -0800)
Trailers passed to the parse_trailer() function often have
a trailing newline. When erroring out, we should display
the invalid trailer properly, that means without any
trailing newline.

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
trailer.c

index 761b763..219a5a2 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -583,8 +583,12 @@ static int parse_trailer(struct strbuf *tok, struct strbuf *val, const char *tra
        strbuf_addch(&seps, '=');
        len = strcspn(trailer, seps.buf);
        strbuf_release(&seps);
-       if (len == 0)
-               return error(_("empty trailer token in trailer '%s'"), trailer);
+       if (len == 0) {
+               int l = strlen(trailer);
+               while (l > 0 && isspace(trailer[l - 1]))
+                       l--;
+               return error(_("empty trailer token in trailer '%.*s'"), l, trailer);
+       }
        if (len < strlen(trailer)) {
                strbuf_add(tok, trailer, len);
                strbuf_trim(tok);