[PATCH v5 14/29] rebase: die on invalid trailer args

Li Chen
2025-10-22T05:42:41Z

This can simplify the error handle in
validate_trailer_args_after_config and
its caller.

Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
---
builtin/rebase.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 3ac1eda61b..872945a897 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1124,29 +1124,22 @@ static int check_exec_cmd(const char *cmd)
return 0;
}

-static int validate_trailer_args_after_config(const struct strvec *cli_args,
- struct strbuf *err)
+static void validate_trailer_args_after_config(const struct strvec *cli_args)
{
for (size_t i = 0; i < cli_args->nr; i++) {
const char *txt = cli_args->v[i]; // Key[:=]Val
const char *sep;

- if (!*txt) {
- strbuf_addstr(err, _("empty --trailer argument"));
- return -1;
- }
+ if (!*txt)
+ die(_("empty --trailer argument"));

sep = strpbrk(txt, ":=");

/* there must be key bfore seperator */
- if (sep && sep == txt) {
- strbuf_addf(err,
- _("invalid trailer '%s': missing key before separator"),
- txt);
- return -1;
- }
+ if (sep && sep == txt)
+ die(_("invalid trailer '%s': missing key before separator"),
+ txt);
}
- return 0;
}

int cmd_rebase(int argc,
@@ -1353,13 +1346,8 @@ int cmd_rebase(int argc,
builtin_rebase_usage, 0);

if (options.trailer_args.nr) {
- struct strbuf err = STRBUF_INIT;
-
- if (validate_trailer_args_after_config(&options.trailer_args, &err))
- die("%s", err.buf);
-
+ validate_trailer_args_after_config(&options.trailer_args);
options.flags |= REBASE_FORCE;
- strbuf_release(&err);
}

if (preserve_merges_selected)
--
2.51.0