]> git.ipfire.org Git - thirdparty/git.git/commitdiff
trailer: rename functions to use 'trailer'
authorLinus Arver <linusa@google.com>
Fri, 1 Mar 2024 00:14:40 +0000 (00:14 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Mar 2024 18:35:42 +0000 (10:35 -0800)
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>
builtin/interpret-trailers.c
trailer.c
trailer.h

index 033bd1556cf9f8d6e56c2730a3e868500388144e..85a3413baf5f0a2ec996a61cdf8f15d2fd4f1d51 100644 (file)
@@ -132,11 +132,11 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
        if (argc) {
                int i;
                for (i = 0; i < argc; i++)
-                       process_trailers(argv[i], &opts, &trailers);
+                       interpret_trailers(&opts, &trailers, argv[i]);
        } else {
                if (opts.in_place)
                        die(_("no input file given for in-place editing"));
-               process_trailers(NULL, &opts, &trailers);
+               interpret_trailers(&opts, &trailers, NULL);
        }
 
        new_trailers_clear(&trailers);
index f74915bd8cd649a065c16c4a4a1e8776e207eb24..916175707d86bd5405c539598684201a8a69f216 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -163,12 +163,12 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val)
                fprintf(outfile, "%s%c %s\n", tok, separators[0], val);
 }
 
-static void print_all(FILE *outfile, struct list_head *head,
-                     const struct process_trailer_options *opts)
+static void format_trailers(const struct process_trailer_options *opts,
+                           struct list_head *trailers, FILE *outfile)
 {
        struct list_head *pos;
        struct trailer_item *item;
-       list_for_each(pos, head) {
+       list_for_each(pos, trailers) {
                item = list_entry(pos, struct trailer_item, list);
                if ((!opts->trim_empty || strlen(item->value) > 0) &&
                    (!opts->only_trailers || item->token))
@@ -589,7 +589,7 @@ static int git_trailer_config(const char *conf_key, const char *value,
        return 0;
 }
 
-static void ensure_configured(void)
+static void trailer_config_init(void)
 {
        if (configured)
                return;
@@ -1035,10 +1035,10 @@ static void parse_trailers(struct trailer_info *info,
        }
 }
 
-static void free_all(struct list_head *head)
+static void free_trailers(struct list_head *trailers)
 {
        struct list_head *pos, *p;
-       list_for_each_safe(pos, p, head) {
+       list_for_each_safe(pos, p, trailers) {
                list_del(pos);
                free_trailer_item(list_entry(pos, struct trailer_item, list));
        }
@@ -1075,16 +1075,16 @@ static FILE *create_in_place_tempfile(const char *file)
        return outfile;
 }
 
-void process_trailers(const char *file,
-                     const struct process_trailer_options *opts,
-                     struct list_head *new_trailer_head)
+void interpret_trailers(const struct process_trailer_options *opts,
+                       struct list_head *new_trailer_head,
+                       const char *file)
 {
        LIST_HEAD(head);
        struct strbuf sb = STRBUF_INIT;
        struct trailer_info info;
        FILE *outfile = stdout;
 
-       ensure_configured();
+       trailer_config_init();
 
        read_input_file(&sb, file);
 
@@ -1110,8 +1110,8 @@ void process_trailers(const char *file,
                process_trailers_lists(&head, &arg_head);
        }
 
-       print_all(outfile, &head, opts);
-       free_all(&head);
+       format_trailers(opts, &head, outfile);
+       free_trailers(&head);
 
        /* Print the lines after the trailers as is */
        if (!opts->only_trailers)
@@ -1134,7 +1134,7 @@ void trailer_info_get(struct trailer_info *info, const char *str,
        size_t nr = 0, alloc = 0;
        char **last = NULL;
 
-       ensure_configured();
+       trailer_config_init();
 
        end_of_log_message = find_end_of_log_message(str, opts->no_divider);
        trailer_block_start = find_trailer_block_start(str, end_of_log_message);
index 1644cd05f60d9f3ceb89ffa66fb5c5b3da9e5cd4..37033e631a1f03724793e45ed9706dd3aaeba5f1 100644 (file)
--- a/trailer.h
+++ b/trailer.h
@@ -81,9 +81,9 @@ struct process_trailer_options {
 
 #define PROCESS_TRAILER_OPTIONS_INIT {0}
 
-void process_trailers(const char *file,
-                     const struct process_trailer_options *opts,
-                     struct list_head *new_trailer_head);
+void interpret_trailers(const struct process_trailer_options *opts,
+                       struct list_head *new_trailer_head,
+                       const char *file);
 
 void trailer_info_get(struct trailer_info *info, const char *str,
                      const struct process_trailer_options *opts);