trailer: split process_command_line_args into separate functions
Previously, process_command_line_args did two things: (1) parse trailers from the configuration, and (2) parse trailers defined on the command line. Separate (1) outside to a new function, parse_trailers_from_config. Rename the remaining logic to parse_trailers_from_command_line_args. Signed-off-by: Linus Arver <linusa@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Arver committed
Sep 9, 2023 at 06:16 UTC
94430d03df639ef49f178f1339ed48a31d84061f
1 file changed
+21
-13
trailer.c
+21
-13
@@ -711,30 +711,35 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val,
711
list_add_tail(&new_item->list, arg_head);
712
}
713
714
-static void process_command_line_args(struct list_head *arg_head,
715
- struct list_head *new_trailer_head)
714
+static void parse_trailers_from_config(struct list_head *config_head)
715
{
716
struct arg_item *item;
718
- struct strbuf tok = STRBUF_INIT;
719
- struct strbuf val = STRBUF_INIT;
720
- const struct conf_info *conf;
717
struct list_head *pos;
718
723
- /*
724
- * In command-line arguments, '=' is accepted (in addition to the
725
- * separators that are defined).
726
- */
727
- char *cl_separators = xstrfmt("=%s", separators);
728
-
719
/* Add an arg item for each configured trailer with a command */
720
list_for_each(pos, &conf_head) {
721
item = list_entry(pos, struct arg_item, list);
722
if (item->conf.command)
733
- add_arg_item(arg_head,
723
+ add_arg_item(config_head,
724
xstrdup(token_from_item(item, NULL)),
725
xstrdup(""),
726
&item->conf, NULL);
727
}
728
+}
729
+
730
+static void parse_trailers_from_command_line_args(struct list_head *arg_head,
731
+ struct list_head *new_trailer_head)
732
+{
733
+ struct strbuf tok = STRBUF_INIT;
734
+ struct strbuf val = STRBUF_INIT;
735
+ const struct conf_info *conf;
736
+ struct list_head *pos;
737
+
738
+ /*
739
+ * In command-line arguments, '=' is accepted (in addition to the
740
+ * separators that are defined).
741
+ */
742
+ char *cl_separators = xstrfmt("=%s", separators);
743
744
/* Add an arg item for each trailer on the command line */
745
list_for_each(pos, new_trailer_head) {
@@ -1069,8 +1074,11 @@ void process_trailers(const char *file,
1074
1075
1076
if (!opts->only_input) {
1077
+ LIST_HEAD(config_head);
1078
LIST_HEAD(arg_head);
1073
- process_command_line_args(&arg_head, new_trailer_head);
1079
+ parse_trailers_from_config(&config_head);
1080
+ parse_trailers_from_command_line_args(&arg_head, new_trailer_head);
1081
+ list_splice(&config_head, &arg_head);
1082
process_trailers_lists(&head, &arg_head);
1083
}
1084