Skip to content

Commit 5e14869

Browse files
FirstLoveLifegitster
authored andcommitted
commit, tag: parse --trailer with OPT_STRVEC
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>
1 parent 6b2243f commit 5e14869

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

builtin/commit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,8 @@ int cmd_commit(int argc,
17201720
OPT_STRING(0, "fixup", &fixup_message, N_("[(amend|reword):]commit"), N_("use autosquash formatted message to fixup or amend/reword specified commit")),
17211721
OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")),
17221722
OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")),
1723-
OPT_PASSTHRU_ARGV(0, "trailer", &trailer_args, N_("trailer"), N_("add custom trailer(s)"), PARSE_OPT_NONEG),
1723+
OPT_STRVEC(0, "trailer", &trailer_args, N_("trailer"),
1724+
N_("add custom trailer(s)")),
17241725
OPT_BOOL('s', "signoff", &signoff, N_("add a Signed-off-by trailer")),
17251726
OPT_FILENAME('t', "template", &template_file, N_("use specified template file")),
17261727
OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),

builtin/tag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ int cmd_tag(int argc,
499499
OPT_CALLBACK_F('m', "message", &msg, N_("message"),
500500
N_("tag message"), PARSE_OPT_NONEG, parse_msg_arg),
501501
OPT_FILENAME('F', "file", &msgfile, N_("read message from file")),
502-
OPT_PASSTHRU_ARGV(0, "trailer", &trailer_args, N_("trailer"),
503-
N_("add custom trailer(s)"), PARSE_OPT_NONEG),
502+
OPT_STRVEC(0, "trailer", &trailer_args, N_("trailer"),
503+
N_("add custom trailer(s)")),
504504
OPT_BOOL('e', "edit", &edit_flag, N_("force edit of tag message")),
505505
OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
506506
OPT_CLEANUP(&cleanup_arg),

trailer.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,46 +1341,25 @@ int amend_file_with_trailers(const char *path,
13411341
const struct strvec *trailer_args)
13421342
{
13431343
struct strbuf buf = STRBUF_INIT;
1344-
struct strvec stripped_trailer_args = STRVEC_INIT;
13451344
int ret = 0;
1346-
size_t i;
13471345

13481346
if (!trailer_args)
13491347
BUG("amend_file_with_trailers called with NULL trailer_args");
13501348
if (!trailer_args->nr)
13511349
return 0;
13521350

1353-
for (i = 0; i < trailer_args->nr; i++) {
1354-
const char *txt = trailer_args->v[i];
1355-
1356-
/*
1357-
* Historically amend_file_with_trailers() passed its arguments
1358-
* to "git interpret-trailers", which expected argv entries in
1359-
* "--trailer=<trailer>" form. Continue to accept those for
1360-
* existing callers, but pass only the value portion to the
1361-
* in-process implementation.
1362-
*/
1363-
skip_prefix(txt, "--trailer=", &txt);
1364-
if (!*txt) {
1365-
ret = error(_("empty --trailer argument"));
1366-
goto out;
1367-
}
1368-
strvec_push(&stripped_trailer_args, txt);
1369-
}
1370-
1371-
if (validate_trailer_args(&stripped_trailer_args)) {
1351+
if (validate_trailer_args(trailer_args)) {
13721352
ret = -1;
13731353
goto out;
13741354
}
13751355
if (strbuf_read_file(&buf, path, 0) < 0)
13761356
ret = error_errno(_("could not read '%s'"), path);
13771357
else
1378-
amend_strbuf_with_trailers(&buf, &stripped_trailer_args);
1358+
amend_strbuf_with_trailers(&buf, trailer_args);
13791359

13801360
if (!ret)
13811361
ret = write_file_in_place(path, &buf);
13821362
out:
1383-
strvec_clear(&stripped_trailer_args);
13841363
strbuf_release(&buf);
13851364
return ret;
13861365
}

trailer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ int amend_strbuf_with_trailers(struct strbuf *buf,
209209
/*
210210
* Augment a file by appending trailers specified in trailer_args.
211211
*
212-
* Each element of trailer_args should be an argv-style --trailer=<trailer>
213-
* option (i.e., including the --trailer= prefix).
212+
* Each element of trailer_args should be in the same format as the value
213+
* accepted by --trailer=<trailer> (i.e., without the --trailer= prefix).
214214
*
215215
* Returns 0 on success or a non-zero error code on failure.
216216
*/

0 commit comments

Comments
 (0)