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

[PATCH v8 5/6] commit, tag: parse --trailer with OPT_STRVEC

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Mar 6, 2026, 14:53 UTC
Message-ID
<3c1fa9e85791953fd30176f6afaae80c2de8cef2.1772808594.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<cover.1772808594.git.phillip.wood@dunelm.org.uk>
From: Li Chen <me@linux.beauty>

Now that amend_file_with_trailers() expects raw trailer lines, do not store argv-style "--trailer=<trailer>" strings in git commit and git tag.

Parse --trailer using OPT_STRVEC so trailer_args contains only the trailer value, and drop the temporary prefix stripping in amend_file_with_trailers().

Signed-off-by: Li Chen <me@linux.beauty>
---
 builtin/commit.c |  3 ++-
 builtin/tag.c    |  4 ++--
 trailer.c        | 25 ++-----------------------
 trailer.h        |  4 ++--
 4 files changed, 8 insertions(+), 28 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index eb9013995c9..3d25c1856ce 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1720,7 +1720,8 @@ int cmd_commit(int argc,
 		OPT_STRING(0, "fixup", &fixup_message, N_("[(amend|reword):]commit"), N_("use autosquash formatted message to fixup or amend/reword specified commit")),
 		OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")),
 		OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")),
-		OPT_PASSTHRU_ARGV(0, "trailer", &trailer_args, N_("trailer"), N_("add custom trailer(s)"), PARSE_OPT_NONEG),
+		OPT_STRVEC(0, "trailer", &trailer_args, N_("trailer"),
+			   N_("add custom trailer(s)")),
 		OPT_BOOL('s', "signoff", &signoff, N_("add a Signed-off-by trailer")),
 		OPT_FILENAME('t', "template", &template_file, N_("use specified template file")),
 		OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),
diff --git a/builtin/tag.c b/builtin/tag.c
index 68b581a9c26..e0f05f94fdb 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -499,8 +499,8 @@ int cmd_tag(int argc,
 		OPT_CALLBACK_F('m', "message", &msg, N_("message"),
 			       N_("tag message"), PARSE_OPT_NONEG, parse_msg_arg),
 		OPT_FILENAME('F', "file", &msgfile, N_("read message from file")),
-		OPT_PASSTHRU_ARGV(0, "trailer", &trailer_args, N_("trailer"),
-				  N_("add custom trailer(s)"), PARSE_OPT_NONEG),
+		OPT_STRVEC(0, "trailer", &trailer_args, N_("trailer"),
+			   N_("add custom trailer(s)")),
 		OPT_BOOL('e', "edit", &edit_flag, N_("force edit of tag message")),
 		OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
 		OPT_CLEANUP(&cleanup_arg),
diff --git a/trailer.c b/trailer.c
index 5eab4fa549d..ca8abd18826 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1341,46 +1341,25 @@ int amend_file_with_trailers(const char *path,
 			     const struct strvec *trailer_args)
 {
 	struct strbuf buf = STRBUF_INIT;
-	struct strvec stripped_trailer_args = STRVEC_INIT;
 	int ret = 0;
-	size_t i;
 
 	if (!trailer_args)
 		BUG("amend_file_with_trailers called with NULL trailer_args");
 	if (!trailer_args->nr)
 		return 0;
 
-	for (i = 0; i < trailer_args->nr; i++) {
-		const char *txt = trailer_args->v[i];
-
-		/*
-		 * Historically amend_file_with_trailers() passed its arguments
-		 * to "git interpret-trailers", which expected argv entries in
-		 * "--trailer=<trailer>" form. Continue to accept those for
-		 * existing callers, but pass only the value portion to the
-		 * in-process implementation.
-		 */
-		skip_prefix(txt, "--trailer=", &txt);
-		if (!*txt) {
-			ret = error(_("empty --trailer argument"));
-			goto out;
-		}
-		strvec_push(&stripped_trailer_args, txt);
-	}
-
-	if (validate_trailer_args(&stripped_trailer_args)) {
+	if (validate_trailer_args(trailer_args)) {
 		ret = -1;
 		goto out;
 	}
 	if (strbuf_read_file(&buf, path, 0) < 0)
 		ret = error_errno(_("could not read '%s'"), path);
 	else
-		amend_strbuf_with_trailers(&buf, &stripped_trailer_args);
+		amend_strbuf_with_trailers(&buf, trailer_args);
 
 	if (!ret)
 		ret = write_file_in_place(path, &buf);
 out:
-	strvec_clear(&stripped_trailer_args);
 	strbuf_release(&buf);
 	return ret;
 }
diff --git a/trailer.h b/trailer.h
index 3c5d9a6e199..b49338858c4 100644
--- a/trailer.h
+++ b/trailer.h
@@ -209,8 +209,8 @@ int amend_strbuf_with_trailers(struct strbuf *buf,
 /*
  * Augment a file by appending trailers specified in trailer_args.
  *
- * Each element of trailer_args should be an argv-style --trailer=<trailer>
- * option (i.e., including the --trailer= prefix).
+ * Each element of trailer_args should be in the same format as the value
+ * accepted by --trailer=<trailer> (i.e., without the --trailer= prefix).
  *
  * Returns 0 on success or a non-zero error code on failure.
  */
-- 
2.52.0.362.g884e03848a9
Previous: Phillip WoodNext: Phillip Wood
Message 31 of 32 in “rebase: support --trailer”
  1. 0/5 rebase: support --trailerLi Chen, Feb 24, 2026
  2. 1/5 interpret-trailers: factor trailer rewritingLi Chen, Feb 24, 2026
  3. Phillip WoodMar 2, 2026
  4. Li ChenMar 2, 2026
  5. 2/5 trailer: move process_trailers to trailer.hLi Chen, Feb 24, 2026
  6. phillip.wood123@gmail.comMar 2, 2026
  7. 3/5 trailer: append trailers without fork/execLi Chen, Feb 24, 2026
  8. Phillip WoodMar 2, 2026
  9. 4/5 commit, tag: parse --trailer with OPT_STRVECLi Chen, Feb 24, 2026
  10. Phillip WoodMar 2, 2026
  11. 5/5 rebase: support --trailerLi Chen, Feb 24, 2026
  12. Phillip WoodMar 3, 2026
  13. Kristoffer HaugsbakkMar 3, 2026
  14. Junio C HamanoMar 3, 2026
  15. Phillip WoodMar 4, 2026
  16. Junio C HamanoMar 4, 2026
  17. Junio C HamanoFeb 26, 2026
  18. Phillip WoodFeb 26, 2026
  19. Kristoffer HaugsbakkFeb 26, 2026
  20. Phillip WoodMar 4, 2026
  21. Li ChenMar 5, 2026
  22. Phillip WoodMar 6, 2026
  23. 0/6 rebase: support --trailerPhillip Wood, Mar 6, 2026
  24. 1/6 interpret-trailers: factor trailer rewritingPhillip Wood, Mar 6, 2026
  25. Junio C HamanoMar 6, 2026
  26. Phillip WoodMar 9, 2026
  27. 2/6 interpret-trailers: refactor create_in_place_tempfile()Phillip Wood, Mar 6, 2026
  28. Junio C HamanoMar 6, 2026
  29. 3/6 trailer: libify a couple of functionsPhillip Wood, Mar 6, 2026
  30. 4/6 trailer: append trailers without fork/execPhillip Wood, Mar 6, 2026
  31. 5/6 commit, tag: parse --trailer with OPT_STRVECPhillip Wood, Mar 6, 2026
  32. 6/6 rebase: support --trailerPhillip Wood, Mar 6, 2026

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.