Skip to content

Commit 38e4df6

Browse files
committed
Merge branch 'la/trailer-info'
Renaming a handful of variables and structure fields. * la/trailer-info: trailer: spread usage of "trailer_block" language
2 parents ff44124 + 3f0346d commit 38e4df6

File tree

3 files changed

+76
-74
lines changed

3 files changed

+76
-74
lines changed

builtin/interpret-trailers.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ static void interpret_trailers(const struct process_trailer_options *opts,
141141
{
142142
LIST_HEAD(head);
143143
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;
146146
FILE *outfile = stdout;
147147

148148
trailer_config_init();
@@ -152,13 +152,13 @@ static void interpret_trailers(const struct process_trailer_options *opts,
152152
if (opts->in_place)
153153
outfile = create_in_place_tempfile(file);
154154

155-
info = parse_trailers(opts, sb.buf, &head);
155+
trailer_block = parse_trailers(opts, sb.buf, &head);
156156

157-
/* Print the lines before the trailers */
157+
/* Print the lines before the trailer block */
158158
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);
160160

161-
if (!opts->only_trailers && !blank_line_before_trailer_block(info))
161+
if (!opts->only_trailers && !blank_line_before_trailer_block(trailer_block))
162162
fprintf(outfile, "\n");
163163

164164

@@ -172,15 +172,16 @@ static void interpret_trailers(const struct process_trailer_options *opts,
172172
}
173173

174174
/* Print trailer block. */
175-
format_trailers(opts, &head, &trailer_block);
175+
format_trailers(opts, &head, &trailer_block_sb);
176176
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);
179179

180-
/* Print the lines after the trailers as is */
180+
/* Print the lines after the trailer block as is. */
181181
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);
184185

185186
if (opts->in_place)
186187
if (rename_tempfile(&trailers_tempfile, file))

trailer.c

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
* Copyright (c) 2013, 2014 Christian Couder <[email protected]>
1414
*/
1515

16-
struct trailer_info {
16+
struct trailer_block {
1717
/*
1818
* True if there is a blank line before the location pointed to by
19-
* trailer_block_start.
19+
* "start".
2020
*/
2121
int blank_line_before_trailer;
2222

2323
/*
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.
2728
*/
28-
size_t trailer_block_start, trailer_block_end;
29+
size_t start, end;
2930

3031
/*
3132
* Array of trailers found.
@@ -981,16 +982,16 @@ static void unfold_value(struct strbuf *val)
981982
strbuf_release(&out);
982983
}
983984

984-
static struct trailer_info *trailer_info_new(void)
985+
static struct trailer_block *trailer_block_new(void)
985986
{
986-
struct trailer_info *info = xcalloc(1, sizeof(*info));
987-
return info;
987+
struct trailer_block *trailer_block = xcalloc(1, sizeof(*trailer_block));
988+
return trailer_block;
988989
}
989990

990-
static struct trailer_info *trailer_info_get(const struct process_trailer_options *opts,
991-
const char *str)
991+
static struct trailer_block *trailer_block_get(const struct process_trailer_options *opts,
992+
const char *str)
992993
{
993-
struct trailer_info *info = trailer_info_new();
994+
struct trailer_block *trailer_block = trailer_block_new();
994995
size_t end_of_log_message = 0, trailer_block_start = 0;
995996
struct strbuf **trailer_lines, **ptr;
996997
char **trailer_strings = NULL;
@@ -1023,34 +1024,34 @@ static struct trailer_info *trailer_info_get(const struct process_trailer_option
10231024
}
10241025
strbuf_list_free(trailer_lines);
10251026

1026-
info->blank_line_before_trailer = ends_with_blank_line(str,
1027-
trailer_block_start);
1028-
info->trailer_block_start = trailer_block_start;
1029-
info->trailer_block_end = end_of_log_message;
1030-
info->trailers = trailer_strings;
1031-
info->trailer_nr = nr;
1027+
trailer_block->blank_line_before_trailer = ends_with_blank_line(str,
1028+
trailer_block_start);
1029+
trailer_block->start = trailer_block_start;
1030+
trailer_block->end = end_of_log_message;
1031+
trailer_block->trailers = trailer_strings;
1032+
trailer_block->trailer_nr = nr;
10321033

1033-
return info;
1034+
return trailer_block;
10341035
}
10351036

10361037
/*
1037-
* Parse trailers in "str", populating the trailer info and "trailer_objects"
1038+
* Parse trailers in "str", populating the trailer_block and "trailer_objects"
10381039
* linked list structure.
10391040
*/
1040-
struct trailer_info *parse_trailers(const struct process_trailer_options *opts,
1041-
const char *str,
1042-
struct list_head *trailer_objects)
1041+
struct trailer_block *parse_trailers(const struct process_trailer_options *opts,
1042+
const char *str,
1043+
struct list_head *trailer_objects)
10431044
{
1044-
struct trailer_info *info;
1045+
struct trailer_block *trailer_block;
10451046
struct strbuf tok = STRBUF_INIT;
10461047
struct strbuf val = STRBUF_INIT;
10471048
size_t i;
10481049

1049-
info = trailer_info_get(opts, str);
1050+
trailer_block = trailer_block_get(opts, str);
10501051

1051-
for (i = 0; i < info->trailer_nr; i++) {
1052+
for (i = 0; i < trailer_block->trailer_nr; i++) {
10521053
int separator_pos;
1053-
char *trailer = info->trailers[i];
1054+
char *trailer = trailer_block->trailers[i];
10541055
if (starts_with(trailer, comment_line_str))
10551056
continue;
10561057
separator_pos = find_separator(trailer, separators);
@@ -1071,7 +1072,7 @@ struct trailer_info *parse_trailers(const struct process_trailer_options *opts,
10711072
}
10721073
}
10731074

1074-
return info;
1075+
return trailer_block;
10751076
}
10761077

10771078
void free_trailers(struct list_head *trailers)
@@ -1083,28 +1084,28 @@ void free_trailers(struct list_head *trailers)
10831084
}
10841085
}
10851086

1086-
size_t trailer_block_start(struct trailer_info *info)
1087+
size_t trailer_block_start(struct trailer_block *trailer_block)
10871088
{
1088-
return info->trailer_block_start;
1089+
return trailer_block->start;
10891090
}
10901091

1091-
size_t trailer_block_end(struct trailer_info *info)
1092+
size_t trailer_block_end(struct trailer_block *trailer_block)
10921093
{
1093-
return info->trailer_block_end;
1094+
return trailer_block->end;
10941095
}
10951096

1096-
int blank_line_before_trailer_block(struct trailer_info *info)
1097+
int blank_line_before_trailer_block(struct trailer_block *trailer_block)
10971098
{
1098-
return info->blank_line_before_trailer;
1099+
return trailer_block->blank_line_before_trailer;
10991100
}
11001101

1101-
void trailer_info_release(struct trailer_info *info)
1102+
void trailer_block_release(struct trailer_block *trailer_block)
11021103
{
11031104
size_t i;
1104-
for (i = 0; i < info->trailer_nr; i++)
1105-
free(info->trailers[i]);
1106-
free(info->trailers);
1107-
free(info);
1105+
for (i = 0; i < trailer_block->trailer_nr; i++)
1106+
free(trailer_block->trailers[i]);
1107+
free(trailer_block->trailers);
1108+
free(trailer_block);
11081109
}
11091110

11101111
void format_trailers(const struct process_trailer_options *opts,
@@ -1174,19 +1175,19 @@ void format_trailers_from_commit(const struct process_trailer_options *opts,
11741175
struct strbuf *out)
11751176
{
11761177
LIST_HEAD(trailer_objects);
1177-
struct trailer_info *info = parse_trailers(opts, msg, &trailer_objects);
1178+
struct trailer_block *trailer_block = parse_trailers(opts, msg, &trailer_objects);
11781179

11791180
/* If we want the whole block untouched, we can take the fast path. */
11801181
if (!opts->only_trailers && !opts->unfold && !opts->filter &&
11811182
!opts->separator && !opts->key_only && !opts->value_only &&
11821183
!opts->key_value_separator) {
1183-
strbuf_add(out, msg + info->trailer_block_start,
1184-
info->trailer_block_end - info->trailer_block_start);
1184+
strbuf_add(out, msg + trailer_block->start,
1185+
trailer_block->end - trailer_block->start);
11851186
} else
11861187
format_trailers(opts, &trailer_objects, out);
11871188

11881189
free_trailers(&trailer_objects);
1189-
trailer_info_release(info);
1190+
trailer_block_release(trailer_block);
11901191
}
11911192

11921193
void trailer_iterator_init(struct trailer_iterator *iter, const char *msg)
@@ -1195,14 +1196,14 @@ void trailer_iterator_init(struct trailer_iterator *iter, const char *msg)
11951196
strbuf_init(&iter->key, 0);
11961197
strbuf_init(&iter->val, 0);
11971198
opts.no_divider = 1;
1198-
iter->internal.info = trailer_info_get(&opts, msg);
1199+
iter->internal.trailer_block = trailer_block_get(&opts, msg);
11991200
iter->internal.cur = 0;
12001201
}
12011202

12021203
int trailer_iterator_advance(struct trailer_iterator *iter)
12031204
{
1204-
if (iter->internal.cur < iter->internal.info->trailer_nr) {
1205-
char *line = iter->internal.info->trailers[iter->internal.cur++];
1205+
if (iter->internal.cur < iter->internal.trailer_block->trailer_nr) {
1206+
char *line = iter->internal.trailer_block->trailers[iter->internal.cur++];
12061207
int separator_pos = find_separator(line, separators);
12071208

12081209
iter->raw = line;
@@ -1219,7 +1220,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter)
12191220

12201221
void trailer_iterator_release(struct trailer_iterator *iter)
12211222
{
1222-
trailer_info_release(iter->internal.info);
1223+
trailer_block_release(iter->internal.trailer_block);
12231224
strbuf_release(&iter->val);
12241225
strbuf_release(&iter->key);
12251226
}

trailer.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "list.h"
55
#include "strbuf.h"
66

7-
struct trailer_info;
7+
struct trailer_block;
88
struct strvec;
99

1010
enum trailer_where {
@@ -72,12 +72,12 @@ void process_trailers_lists(struct list_head *head,
7272
struct list_head *arg_head);
7373

7474
/*
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
7676
* structure. Also populate the trailer_objects list with parsed trailer
7777
* objects. Internally this calls trailer_info_get() to get the opaque pointer,
7878
* but does some extra work to populate the trailer_objects linked list.
7979
*
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
8181
* trailer block as offsets relative to the beginning of "str" in
8282
* trailer_block_start() and trailer_block_end().
8383
* blank_line_before_trailer_block() returns 1 if there is a blank line just
@@ -89,46 +89,46 @@ void process_trailers_lists(struct list_head *head,
8989
* For iterating through the parsed trailer block (if you don't care about the
9090
* position of the trailer block itself in the context of the larger string text
9191
* from which it was parsed), please see trailer_iterator_init() which uses the
92-
* trailer_info struct internally.
92+
* trailer_block struct internally.
9393
*
9494
* Lastly, callers should call trailer_info_release() when they are done using
9595
* the opaque pointer.
9696
*
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
9999
* has "char **trailers" string array, and trailer_objects will have the same
100100
* data but as a linked list of trailer_item objects). This API does not perform
101101
* any synchronization between the two. In the future we should be able to
102102
* reduce the duplication and use just the linked list.
103103
*/
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);
107107

108108
/*
109109
* Return the offset of the start of the trailer block. That is, 0 is the start
110110
* of the input ("str" in parse_trailers()) and some other positive number
111111
* indicates how many bytes we have to skip over before we get to the beginning
112112
* of the trailer block.
113113
*/
114-
size_t trailer_block_start(struct trailer_info *);
114+
size_t trailer_block_start(struct trailer_block *);
115115

116116
/*
117117
* Return the end of the trailer block, again relative to the start of the
118118
* input.
119119
*/
120-
size_t trailer_block_end(struct trailer_info *);
120+
size_t trailer_block_end(struct trailer_block *);
121121

122122
/*
123123
* Return 1 if the trailer block had an extra newline (blank line) just before
124124
* it.
125125
*/
126-
int blank_line_before_trailer_block(struct trailer_info *);
126+
int blank_line_before_trailer_block(struct trailer_block *);
127127

128128
/*
129-
* Free trailer_info struct.
129+
* Free trailer_block struct.
130130
*/
131-
void trailer_info_release(struct trailer_info *info);
131+
void trailer_block_release(struct trailer_block *);
132132

133133
void trailer_config_init(void);
134134
void format_trailers(const struct process_trailer_options *,
@@ -167,7 +167,7 @@ struct trailer_iterator {
167167

168168
/* private */
169169
struct {
170-
struct trailer_info *info;
170+
struct trailer_block *trailer_block;
171171
size_t cur;
172172
} internal;
173173
};

0 commit comments

Comments
 (0)