trailer: spread usage of "trailer_block" language

Deprecate the "trailer_info" struct name and replace it with "trailer_block". This is more readable, for two reasons: 1. "trailer_info" on the surface sounds like it's about a single trailer when in reality it is a collection of one or more trailers, and 2. the "*_block" suffix is more informative than "*_info", because it describes a block (or region) of contiguous text which has trailers in it, which has been parsed into the trailer_block structure. Rename the size_t trailer_block_start, trailer_block_end; members of trailer_info to just "start" and "end". Rename the "info" pointer to "trailer_block" because it is more descriptive. Update comments accordingly. Signed-off-by: Linus Arver <linus@ucla.edu> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Linus Arver committed Oct 13, 2024 at 11:58 UTC 3f0346d4dcdb6cf03f758895719dfe1e6a8cc696
3 files changed +76 -74
builtin/interpret-trailers.c
+13 -12
@@ -141,8 +141,8 @@ static void interpret_trailers(const struct process_trailer_options *opts,
141 {
142 LIST_HEAD(head);
143 struct strbuf sb = STRBUF_INIT;
144 - struct strbuf trailer_block = STRBUF_INIT;
145 - struct trailer_info *info;
144 + struct strbuf trailer_block_sb = STRBUF_INIT;
145 + struct trailer_block *trailer_block;
146 FILE *outfile = stdout;
147
148 trailer_config_init();
@@ -152,13 +152,13 @@ static void interpret_trailers(const struct process_trailer_options *opts,
152 if (opts->in_place)
153 outfile = create_in_place_tempfile(file);
154
155 - info = parse_trailers(opts, sb.buf, &head);
155 + trailer_block = parse_trailers(opts, sb.buf, &head);
156
157 - /* Print the lines before the trailers */
157 + /* Print the lines before the trailer block */
158 if (!opts->only_trailers)
159 - fwrite(sb.buf, 1, trailer_block_start(info), outfile);
159 + fwrite(sb.buf, 1, trailer_block_start(trailer_block), outfile);
160
161 - if (!opts->only_trailers && !blank_line_before_trailer_block(info))
161 + if (!opts->only_trailers && !blank_line_before_trailer_block(trailer_block))
162 fprintf(outfile, "\n");
163
164
@@ -172,15 +172,16 @@ static void interpret_trailers(const struct process_trailer_options *opts,
172 }
173
174 /* Print trailer block. */
175 - format_trailers(opts, &head, &trailer_block);
175 + format_trailers(opts, &head, &trailer_block_sb);
176 free_trailers(&head);
177 - fwrite(trailer_block.buf, 1, trailer_block.len, outfile);
178 - strbuf_release(&trailer_block);
177 + fwrite(trailer_block_sb.buf, 1, trailer_block_sb.len, outfile);
178 + strbuf_release(&trailer_block_sb);
179
180 - /* Print the lines after the trailers as is */
180 + /* Print the lines after the trailer block as is. */
181 if (!opts->only_trailers)
182 - fwrite(sb.buf + trailer_block_end(info), 1, sb.len - trailer_block_end(info), outfile);
183 - trailer_info_release(info);
182 + fwrite(sb.buf + trailer_block_end(trailer_block), 1,
183 + sb.len - trailer_block_end(trailer_block), outfile);
184 + trailer_block_release(trailer_block);
185
186 if (opts->in_place)
187 if (rename_tempfile(&trailers_tempfile, file))
trailer.c
+48 -47
@@ -13,19 +13,20 @@
13 * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>
14 */
15
16 -struct trailer_info {
16 +struct trailer_block {
17 /*
18 * True if there is a blank line before the location pointed to by
19 - * trailer_block_start.
19 + * "start".
20 */
21 int blank_line_before_trailer;
22
23 /*
24 - * Offsets to the trailer block start and end positions in the input
25 - * string. If no trailer block is found, these are both set to the
26 - * "true" end of the input (find_end_of_log_message()).
24 + * The locations of the start and end positions of the trailer block
25 + * found, as offsets from the beginning of the source text from which
26 + * this trailer block was parsed. If no trailer block is found, these
27 + * are both set to 0.
28 */
28 - size_t trailer_block_start, trailer_block_end;
29 + size_t start, end;
30
31 /*
32 * Array of trailers found.
@@ -975,16 +976,16 @@ static void unfold_value(struct strbuf *val)
976 strbuf_release(&out);
977 }
978
978 -static struct trailer_info *trailer_info_new(void)
979 +static struct trailer_block *trailer_block_new(void)
980 {
980 - struct trailer_info *info = xcalloc(1, sizeof(*info));
981 - return info;
981 + struct trailer_block *trailer_block = xcalloc(1, sizeof(*trailer_block));
982 + return trailer_block;
983 }
984
984 -static struct trailer_info *trailer_info_get(const struct process_trailer_options *opts,
985 - const char *str)
985 +static struct trailer_block *trailer_block_get(const struct process_trailer_options *opts,
986 + const char *str)
987 {
987 - struct trailer_info *info = trailer_info_new();
988 + struct trailer_block *trailer_block = trailer_block_new();
989 size_t end_of_log_message = 0, trailer_block_start = 0;
990 struct strbuf **trailer_lines, **ptr;
991 char **trailer_strings = NULL;
@@ -1017,34 +1018,34 @@ static struct trailer_info *trailer_info_get(const struct process_trailer_option
1018 }
1019 strbuf_list_free(trailer_lines);
1020
1020 - info->blank_line_before_trailer = ends_with_blank_line(str,
1021 - trailer_block_start);
1022 - info->trailer_block_start = trailer_block_start;
1023 - info->trailer_block_end = end_of_log_message;
1024 - info->trailers = trailer_strings;
1025 - info->trailer_nr = nr;
1021 + trailer_block->blank_line_before_trailer = ends_with_blank_line(str,
1022 + trailer_block_start);
1023 + trailer_block->start = trailer_block_start;
1024 + trailer_block->end = end_of_log_message;
1025 + trailer_block->trailers = trailer_strings;
1026 + trailer_block->trailer_nr = nr;
1027
1027 - return info;
1028 + return trailer_block;
1029 }
1030
1031 /*
1031 - * Parse trailers in "str", populating the trailer info and "trailer_objects"
1032 + * Parse trailers in "str", populating the trailer_block and "trailer_objects"
1033 * linked list structure.
1034 */
1034 -struct trailer_info *parse_trailers(const struct process_trailer_options *opts,
1035 - const char *str,
1036 - struct list_head *trailer_objects)
1035 +struct trailer_block *parse_trailers(const struct process_trailer_options *opts,
1036 + const char *str,
1037 + struct list_head *trailer_objects)
1038 {
1038 - struct trailer_info *info;
1039 + struct trailer_block *trailer_block;
1040 struct strbuf tok = STRBUF_INIT;
1041 struct strbuf val = STRBUF_INIT;
1042 size_t i;
1043
1043 - info = trailer_info_get(opts, str);
1044 + trailer_block = trailer_block_get(opts, str);
1045
1045 - for (i = 0; i < info->trailer_nr; i++) {
1046 + for (i = 0; i < trailer_block->trailer_nr; i++) {
1047 int separator_pos;
1047 - char *trailer = info->trailers[i];
1048 + char *trailer = trailer_block->trailers[i];
1049 if (starts_with(trailer, comment_line_str))
1050 continue;
1051 separator_pos = find_separator(trailer, separators);
@@ -1065,7 +1066,7 @@ struct trailer_info *parse_trailers(const struct process_trailer_options *opts,
1066 }
1067 }
1068
1068 - return info;
1069 + return trailer_block;
1070 }
1071
1072 void free_trailers(struct list_head *trailers)
@@ -1077,28 +1078,28 @@ void free_trailers(struct list_head *trailers)
1078 }
1079 }
1080
1080 -size_t trailer_block_start(struct trailer_info *info)
1081 +size_t trailer_block_start(struct trailer_block *trailer_block)
1082 {
1082 - return info->trailer_block_start;
1083 + return trailer_block->start;
1084 }
1085
1085 -size_t trailer_block_end(struct trailer_info *info)
1086 +size_t trailer_block_end(struct trailer_block *trailer_block)
1087 {
1087 - return info->trailer_block_end;
1088 + return trailer_block->end;
1089 }
1090
1090 -int blank_line_before_trailer_block(struct trailer_info *info)
1091 +int blank_line_before_trailer_block(struct trailer_block *trailer_block)
1092 {
1092 - return info->blank_line_before_trailer;
1093 + return trailer_block->blank_line_before_trailer;
1094 }
1095
1095 -void trailer_info_release(struct trailer_info *info)
1096 +void trailer_block_release(struct trailer_block *trailer_block)
1097 {
1098 size_t i;
1098 - for (i = 0; i < info->trailer_nr; i++)
1099 - free(info->trailers[i]);
1100 - free(info->trailers);
1101 - free(info);
1099 + for (i = 0; i < trailer_block->trailer_nr; i++)
1100 + free(trailer_block->trailers[i]);
1101 + free(trailer_block->trailers);
1102 + free(trailer_block);
1103 }
1104
1105 void format_trailers(const struct process_trailer_options *opts,
@@ -1166,19 +1167,19 @@ void format_trailers_from_commit(const struct process_trailer_options *opts,
1167 struct strbuf *out)
1168 {
1169 LIST_HEAD(trailer_objects);
1169 - struct trailer_info *info = parse_trailers(opts, msg, &trailer_objects);
1170 + struct trailer_block *trailer_block = parse_trailers(opts, msg, &trailer_objects);
1171
1172 /* If we want the whole block untouched, we can take the fast path. */
1173 if (!opts->only_trailers && !opts->unfold && !opts->filter &&
1174 !opts->separator && !opts->key_only && !opts->value_only &&
1175 !opts->key_value_separator) {
1175 - strbuf_add(out, msg + info->trailer_block_start,
1176 - info->trailer_block_end - info->trailer_block_start);
1176 + strbuf_add(out, msg + trailer_block->start,
1177 + trailer_block->end - trailer_block->start);
1178 } else
1179 format_trailers(opts, &trailer_objects, out);
1180
1181 free_trailers(&trailer_objects);
1181 - trailer_info_release(info);
1182 + trailer_block_release(trailer_block);
1183 }
1184
1185 void trailer_iterator_init(struct trailer_iterator *iter, const char *msg)
@@ -1187,14 +1188,14 @@ void trailer_iterator_init(struct trailer_iterator *iter, const char *msg)
1188 strbuf_init(&iter->key, 0);
1189 strbuf_init(&iter->val, 0);
1190 opts.no_divider = 1;
1190 - iter->internal.info = trailer_info_get(&opts, msg);
1191 + iter->internal.trailer_block = trailer_block_get(&opts, msg);
1192 iter->internal.cur = 0;
1193 }
1194
1195 int trailer_iterator_advance(struct trailer_iterator *iter)
1196 {
1196 - if (iter->internal.cur < iter->internal.info->trailer_nr) {
1197 - char *line = iter->internal.info->trailers[iter->internal.cur++];
1197 + if (iter->internal.cur < iter->internal.trailer_block->trailer_nr) {
1198 + char *line = iter->internal.trailer_block->trailers[iter->internal.cur++];
1199 int separator_pos = find_separator(line, separators);
1200
1201 iter->raw = line;
@@ -1211,7 +1212,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter)
1212
1213 void trailer_iterator_release(struct trailer_iterator *iter)
1214 {
1214 - trailer_info_release(iter->internal.info);
1215 + trailer_block_release(iter->internal.trailer_block);
1216 strbuf_release(&iter->val);
1217 strbuf_release(&iter->key);
1218 }
trailer.h
+15 -15
@@ -4,7 +4,7 @@
4 #include "list.h"
5 #include "strbuf.h"
6
7 -struct trailer_info;
7 +struct trailer_block;
8 struct strvec;
9
10 enum trailer_where {
@@ -72,12 +72,12 @@ void process_trailers_lists(struct list_head *head,
72 struct list_head *arg_head);
73
74 /*
75 - * Given some input string "str", return a pointer to an opaque trailer_info
75 + * Given some input string "str", return a pointer to an opaque trailer_block
76 * structure. Also populate the trailer_objects list with parsed trailer
77 * objects. Internally this calls trailer_info_get() to get the opaque pointer,
78 * but does some extra work to populate the trailer_objects linked list.
79 *
80 - * The opaque trailer_info pointer can be used to check the position of the
80 + * The opaque trailer_block pointer can be used to check the position of the
81 * trailer block as offsets relative to the beginning of "str" in
82 * trailer_block_start() and trailer_block_end().
83 * blank_line_before_trailer_block() returns 1 if there is a blank line just
@@ -89,21 +89,21 @@ void process_trailers_lists(struct list_head *head,
89 * For iterating through the parsed trailer block (if you don't care about the
90 * position of the trailer block itself in the context of the larger string text
91 * from which it was parsed), please see trailer_iterator_init() which uses the
92 - * trailer_info struct internally.
92 + * trailer_block struct internally.
93 *
94 * Lastly, callers should call trailer_info_release() when they are done using
95 * the opaque pointer.
96 *
97 - * NOTE: Callers should treat both trailer_info and trailer_objects as
98 - * read-only items, because there is some overlap between the two (trailer_info
97 + * NOTE: Callers should treat both trailer_block and trailer_objects as
98 + * read-only items, because there is some overlap between the two (trailer_block
99 * has "char **trailers" string array, and trailer_objects will have the same
100 * data but as a linked list of trailer_item objects). This API does not perform
101 * any synchronization between the two. In the future we should be able to
102 * reduce the duplication and use just the linked list.
103 */
104 -struct trailer_info *parse_trailers(const struct process_trailer_options *,
105 - const char *str,
106 - struct list_head *trailer_objects);
104 +struct trailer_block *parse_trailers(const struct process_trailer_options *,
105 + const char *str,
106 + struct list_head *trailer_objects);
107
108 /*
109 * Return the offset of the start of the trailer block. That is, 0 is the start
@@ -111,24 +111,24 @@ struct trailer_info *parse_trailers(const struct process_trailer_options *,
111 * indicates how many bytes we have to skip over before we get to the beginning
112 * of the trailer block.
113 */
114 -size_t trailer_block_start(struct trailer_info *);
114 +size_t trailer_block_start(struct trailer_block *);
115
116 /*
117 * Return the end of the trailer block, again relative to the start of the
118 * input.
119 */
120 -size_t trailer_block_end(struct trailer_info *);
120 +size_t trailer_block_end(struct trailer_block *);
121
122 /*
123 * Return 1 if the trailer block had an extra newline (blank line) just before
124 * it.
125 */
126 -int blank_line_before_trailer_block(struct trailer_info *);
126 +int blank_line_before_trailer_block(struct trailer_block *);
127
128 /*
129 - * Free trailer_info struct.
129 + * Free trailer_block struct.
130 */
131 -void trailer_info_release(struct trailer_info *info);
131 +void trailer_block_release(struct trailer_block *);
132
133 void trailer_config_init(void);
134 void format_trailers(const struct process_trailer_options *,
@@ -167,7 +167,7 @@ struct trailer_iterator {
167
168 /* private */
169 struct {
170 - struct trailer_info *info;
170 + struct trailer_block *trailer_block;
171 size_t cur;
172 } internal;
173 };