git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/5] trailer: display a trailer without its trailing newline

From
Christian Couder <chriscool@tuxfamily.org>
Date
Nov 9, 2014, 09:23 UTC
Message-ID
<20141109092344.4864.55173.chriscool@tuxfamily.org>
In-Reply-To
<20141109092313.4864.54933.chriscool@tuxfamily.org>

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>
---
 trailer.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/trailer.c b/trailer.c
index 761b763..219a5a2 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);
-- 
2.1.2.555.gfbecd99
Previous: Christian CouderNext: Christian Couder
Message 3 of 9 in “Small "git interpret-trailers" fixes”
  1. 0/5 Small "git interpret-trailers" fixesChristian Couder, Nov 9, 2014
  2. 1/5 trailer: ignore comment lines inside the trailersChristian Couder, Nov 9, 2014
  3. 2/5 trailer: display a trailer without its trailing newlineChristian Couder, Nov 9, 2014
  4. 3/5 commit: make ignore_non_trailer() non staticChristian Couder, Nov 9, 2014
  5. 4/5 trailer: reuse ignore_non_trailer() to ignore conflict linesChristian Couder, Nov 9, 2014
  6. Junio C HamanoNov 10, 2014
  7. Christian CouderNov 10, 2014
  8. Junio C HamanoNov 10, 2014
  9. 5/5 trailer: add test with an old style conflict blockChristian Couder, Nov 9, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.