Skip to content

Commit 7b1c6aa

Browse files
Linus Arvergitster
authored andcommitted
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 <[email protected]> Helped-by: Christian Couder <[email protected]> Signed-off-by: Linus Arver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a082e28 commit 7b1c6aa

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

builtin/interpret-trailers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
132132
if (argc) {
133133
int i;
134134
for (i = 0; i < argc; i++)
135-
process_trailers(argv[i], &opts, &trailers);
135+
interpret_trailers(&opts, &trailers, argv[i]);
136136
} else {
137137
if (opts.in_place)
138138
die(_("no input file given for in-place editing"));
139-
process_trailers(NULL, &opts, &trailers);
139+
interpret_trailers(&opts, &trailers, NULL);
140140
}
141141

142142
new_trailers_clear(&trailers);

trailer.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val)
163163
fprintf(outfile, "%s%c %s\n", tok, separators[0], val);
164164
}
165165

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)
168168
{
169169
struct list_head *pos;
170170
struct trailer_item *item;
171-
list_for_each(pos, head) {
171+
list_for_each(pos, trailers) {
172172
item = list_entry(pos, struct trailer_item, list);
173173
if ((!opts->trim_empty || strlen(item->value) > 0) &&
174174
(!opts->only_trailers || item->token))
@@ -589,7 +589,7 @@ static int git_trailer_config(const char *conf_key, const char *value,
589589
return 0;
590590
}
591591

592-
static void ensure_configured(void)
592+
static void trailer_config_init(void)
593593
{
594594
if (configured)
595595
return;
@@ -1035,10 +1035,10 @@ static void parse_trailers(struct trailer_info *info,
10351035
}
10361036
}
10371037

1038-
static void free_all(struct list_head *head)
1038+
static void free_trailers(struct list_head *trailers)
10391039
{
10401040
struct list_head *pos, *p;
1041-
list_for_each_safe(pos, p, head) {
1041+
list_for_each_safe(pos, p, trailers) {
10421042
list_del(pos);
10431043
free_trailer_item(list_entry(pos, struct trailer_item, list));
10441044
}
@@ -1075,16 +1075,16 @@ static FILE *create_in_place_tempfile(const char *file)
10751075
return outfile;
10761076
}
10771077

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)
10811081
{
10821082
LIST_HEAD(head);
10831083
struct strbuf sb = STRBUF_INIT;
10841084
struct trailer_info info;
10851085
FILE *outfile = stdout;
10861086

1087-
ensure_configured();
1087+
trailer_config_init();
10881088

10891089
read_input_file(&sb, file);
10901090

@@ -1110,8 +1110,8 @@ void process_trailers(const char *file,
11101110
process_trailers_lists(&head, &arg_head);
11111111
}
11121112

1113-
print_all(outfile, &head, opts);
1114-
free_all(&head);
1113+
format_trailers(opts, &head, outfile);
1114+
free_trailers(&head);
11151115

11161116
/* Print the lines after the trailers as is */
11171117
if (!opts->only_trailers)
@@ -1134,7 +1134,7 @@ void trailer_info_get(struct trailer_info *info, const char *str,
11341134
size_t nr = 0, alloc = 0;
11351135
char **last = NULL;
11361136

1137-
ensure_configured();
1137+
trailer_config_init();
11381138

11391139
end_of_log_message = find_end_of_log_message(str, opts->no_divider);
11401140
trailer_block_start = find_trailer_block_start(str, end_of_log_message);

trailer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ struct process_trailer_options {
8181

8282
#define PROCESS_TRAILER_OPTIONS_INIT {0}
8383

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);
8787

8888
void trailer_info_get(struct trailer_info *info, const char *str,
8989
const struct process_trailer_options *opts);

0 commit comments

Comments
 (0)