From 2887103b35b3b40025ca5060713dfb1e1c8c3b20 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 9 Nov 2014 10:23:39 +0100 Subject: [PATCH 1/2] trailer: ignore comment lines inside the trailers Otherwise trailers that are commented out might be processed. We would also error out if the comment line char is also a separator. This means that comments inside a trailer block will disappear, but that was already the case anyway. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- trailer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/trailer.c b/trailer.c index 8514566564..761b763d4d 100644 --- a/trailer.c +++ b/trailer.c @@ -804,8 +804,10 @@ static int process_input_file(struct strbuf **lines, /* Parse trailer lines */ for (i = trailer_start; i < patch_start; i++) { - struct trailer_item *new = create_trailer_item(lines[i]->buf); - add_trailer_item(in_tok_first, in_tok_last, new); + if (lines[i]->buf[0] != comment_line_char) { + struct trailer_item *new = create_trailer_item(lines[i]->buf); + add_trailer_item(in_tok_first, in_tok_last, new); + } } return patch_start; From d52adf1f328162a9513940913ced044d24c0212f Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 9 Nov 2014 10:23:40 +0100 Subject: [PATCH 2/2] trailer: display a trailer without its trailing newline 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 Helped-by: Jeff King Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- trailer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/trailer.c b/trailer.c index 761b763d4d..219a5a2dad 100644 --- 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);