]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit, tag: parse --trailer with OPT_STRVEC
authorLi Chen <me@linux.beauty>
Fri, 6 Mar 2026 14:53:31 +0000 (14:53 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Mar 2026 21:02:20 +0000 (13:02 -0800)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c
builtin/tag.c
trailer.c
trailer.h

index eb9013995c95d404dccffc8923ff669fec4b3846..3d25c1856ced5e0c483bec8182cd0fcc80eea3aa 100644 (file)
@@ -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")),
index 68b581a9c26671ea3c4a5b2d28a4eef3f06a2c6c..e0f05f94fdbe3efa0f3689a4745c5a5d69ff3189 100644 (file)
@@ -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),
index 5eab4fa549d6e7ce411237fe4fc6a5457dd01b23..ca8abd18826bf28f34c94dfd53c2256c83b75165 100644 (file)
--- 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;
 }
index 3c5d9a6e199248f78e79c6fd1382e5ad3376eab5..b49338858c482abb0adc1517d3afabcf021cb242 100644 (file)
--- 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.
  */