trailer: rename functions to use 'trailer'

Rename process_trailers() to interpret_trailers(), because it matches the name for the builtin command of the same name (git-interpret-trailers), which is the sole user of process_trailers(). In a following commit, we will move "interpret_trailers" from trailer.c to builtin/interpret-trailers.c. That move will necessitate the growth of the trailer.h API, forcing us to expose some additional functions in trailer.h. Rename relevant functions so that they include the term "trailer" in their name, so that clients of the API will be able to easily identify them by their "trailer" moniker, just like all the other functions already exposed by trailer.h. Rename `struct list_head *head` to `struct list_head *trailers` because "head" conveys no additional information beyond the "list_head" type. Reorder parameters for format_trailers_from_commit() to prefer const struct process_trailer_options *opts as the first parameter, because these options are intimately tied to formatting trailers. Parameters like `FILE *outfile` should be last because they are a kind of 'out' parameter, so put such parameters at the end. This will be the pattern going forward in this series. Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Linus Arver <linusa@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Arver committed Mar 1, 2024 at 00:14 UTC 7b1c6aa541cc94796e9148e5e49c4d2f787e953d
3 files changed +18 -18
builtin/interpret-trailers.c
+2 -2
@@ -132,11 +132,11 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
132 if (argc) {
133 int i;
134 for (i = 0; i < argc; i++)
135 - process_trailers(argv[i], &opts, &trailers);
135 + interpret_trailers(&opts, &trailers, argv[i]);
136 } else {
137 if (opts.in_place)
138 die(_("no input file given for in-place editing"));
139 - process_trailers(NULL, &opts, &trailers);
139 + interpret_trailers(&opts, &trailers, NULL);
140 }
141
142 new_trailers_clear(&trailers);
trailer.c
+13 -13
@@ -163,12 +163,12 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val)
163 fprintf(outfile, "%s%c %s\n", tok, separators[0], val);
164 }
165
166 -static void print_all(FILE *outfile, struct list_head *head,
167 - const struct process_trailer_options *opts)
166 +static void format_trailers(const struct process_trailer_options *opts,
167 + struct list_head *trailers, FILE *outfile)
168 {
169 struct list_head *pos;
170 struct trailer_item *item;
171 - list_for_each(pos, head) {
171 + list_for_each(pos, trailers) {
172 item = list_entry(pos, struct trailer_item, list);
173 if ((!opts->trim_empty || strlen(item->value) > 0) &&
174 (!opts->only_trailers || item->token))
@@ -589,7 +589,7 @@ static int git_trailer_config(const char *conf_key, const char *value,
589 return 0;
590 }
591
592 -static void ensure_configured(void)
592 +static void trailer_config_init(void)
593 {
594 if (configured)
595 return;
@@ -1035,10 +1035,10 @@ static void parse_trailers(struct trailer_info *info,
1035 }
1036 }
1037
1038 -static void free_all(struct list_head *head)
1038 +static void free_trailers(struct list_head *trailers)
1039 {
1040 struct list_head *pos, *p;
1041 - list_for_each_safe(pos, p, head) {
1041 + list_for_each_safe(pos, p, trailers) {
1042 list_del(pos);
1043 free_trailer_item(list_entry(pos, struct trailer_item, list));
1044 }
@@ -1075,16 +1075,16 @@ static FILE *create_in_place_tempfile(const char *file)
1075 return outfile;
1076 }
1077
1078 -void process_trailers(const char *file,
1079 - const struct process_trailer_options *opts,
1080 - struct list_head *new_trailer_head)
1078 +void interpret_trailers(const struct process_trailer_options *opts,
1079 + struct list_head *new_trailer_head,
1080 + const char *file)
1081 {
1082 LIST_HEAD(head);
1083 struct strbuf sb = STRBUF_INIT;
1084 struct trailer_info info;
1085 FILE *outfile = stdout;
1086
1087 - ensure_configured();
1087 + trailer_config_init();
1088
1089 read_input_file(&sb, file);
1090
@@ -1110,8 +1110,8 @@ void process_trailers(const char *file,
1110 process_trailers_lists(&head, &arg_head);
1111 }
1112
1113 - print_all(outfile, &head, opts);
1114 - free_all(&head);
1113 + format_trailers(opts, &head, outfile);
1114 + free_trailers(&head);
1115
1116 /* Print the lines after the trailers as is */
1117 if (!opts->only_trailers)
@@ -1134,7 +1134,7 @@ void trailer_info_get(struct trailer_info *info, const char *str,
1134 size_t nr = 0, alloc = 0;
1135 char **last = NULL;
1136
1137 - ensure_configured();
1137 + trailer_config_init();
1138
1139 end_of_log_message = find_end_of_log_message(str, opts->no_divider);
1140 trailer_block_start = find_trailer_block_start(str, end_of_log_message);
trailer.h
+3 -3
@@ -81,9 +81,9 @@ struct process_trailer_options {
81
82 #define PROCESS_TRAILER_OPTIONS_INIT {0}
83
84 -void process_trailers(const char *file,
85 - const struct process_trailer_options *opts,
86 - struct list_head *new_trailer_head);
84 +void interpret_trailers(const struct process_trailer_options *opts,
85 + struct list_head *new_trailer_head,
86 + const char *file);
87
88 void trailer_info_get(struct trailer_info *info, const char *str,
89 const struct process_trailer_options *opts);