[PATCH v5 15/29] rebase: validate trailers with configured separators

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

Moved validate_trailer_args_after_config() into
trailer.c so trailer argument validation reuses
find_separator() and respects configured separators.

Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
---
builtin/rebase.c | 18 ------------------
trailer.c | 25 +++++++++++++++++++++++++
trailer.h | 2 ++
3 files changed, 27 insertions(+), 18 deletions(-)

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

-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)
- die(_("empty --trailer argument"));
-
- sep = strpbrk(txt, ":=");
-
- /* there must be key bfore seperator */
- if (sep && sep == txt)
- die(_("invalid trailer '%s': missing key before separator"),
- txt);
- }
-}
-
int cmd_rebase(int argc,
const char **argv,
const char *prefix,
diff --git a/trailer.c b/trailer.c
index 1f317f4d37..85e42859ca 100644
--- a/trailer.c
+++ b/trailer.c
@@ -7,6 +7,7 @@
#include "string-list.h"
#include "run-command.h"
#include "commit.h"
+#include "strvec.h"
#include "trailer.h"
#include "list.h"
#include "wrapper.h"
@@ -773,6 +774,30 @@ void parse_trailers_from_command_line_args(struct list_head *arg_head,
free(cl_separators);
}

+void validate_trailer_args_after_config(const struct strvec *cli_args)
+{
+ char *cl_separators;
+
+ trailer_config_init();
+
+ cl_separators = xstrfmt("=%s", separators);
+
+ for (size_t i = 0; i < cli_args->nr; i++) {
+ const char *txt = cli_args->v[i];
+ ssize_t separator_pos;
+
+ if (!*txt)
+ die(_("empty --trailer argument"));
+
+ separator_pos = find_separator(txt, cl_separators);
+ if (separator_pos == 0)
+ die(_("invalid trailer '%s': missing key before separator"),
+ txt);
+ }
+
+ free(cl_separators);
+}
+
static const char *next_line(const char *str)
{
const char *nl = strchrnul(str, '\n');
diff --git a/trailer.h b/trailer.h
index b4f28bfd65..4654ff9c96 100644
--- a/trailer.h
+++ b/trailer.h
@@ -68,6 +68,8 @@ void parse_trailers_from_config(struct list_head *config_head);
void parse_trailers_from_command_line_args(struct list_head *arg_head,
struct list_head *new_trailer_head);

+void validate_trailer_args_after_config(const struct strvec *cli_args);
+
void process_trailers_lists(struct list_head *head,
struct list_head *arg_head);

--
2.51.0