Skip to content

Commit 655eb65

Browse files
listxgitster
authored andcommitted
interpret-trailers: access trailer_info with new helpers
Instead of directly accessing trailer_info members, access them indirectly through new helper functions exposed by the trailer API. This is the first of two preparatory commits which will allow us to use the so-called "pimpl" (pointer to implementation) idiom for the trailer API, by making the trailer_info struct private to the trailer implementation (and thus hidden from the API). Helped-by: Christian Couder <[email protected]> Signed-off-by: Linus Arver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ade054 commit 655eb65

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

builtin/interpret-trailers.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void interpret_trailers(const struct process_trailer_options *opts,
141141
LIST_HEAD(head);
142142
struct strbuf sb = STRBUF_INIT;
143143
struct strbuf trailer_block = STRBUF_INIT;
144-
struct trailer_info info;
144+
struct trailer_info *info = trailer_info_new();
145145
FILE *outfile = stdout;
146146

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

154-
parse_trailers(opts, &info, sb.buf, &head);
154+
parse_trailers(opts, info, sb.buf, &head);
155155

156156
/* Print the lines before the trailers */
157157
if (!opts->only_trailers)
158-
fwrite(sb.buf, 1, info.trailer_block_start, outfile);
158+
fwrite(sb.buf, 1, trailer_block_start(info), outfile);
159159

160-
if (!opts->only_trailers && !info.blank_line_before_trailer)
160+
if (!opts->only_trailers && !blank_line_before_trailer_block(info))
161161
fprintf(outfile, "\n");
162162

163163

@@ -178,8 +178,8 @@ static void interpret_trailers(const struct process_trailer_options *opts,
178178

179179
/* Print the lines after the trailers as is */
180180
if (!opts->only_trailers)
181-
fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile);
182-
trailer_info_release(&info);
181+
fwrite(sb.buf + trailer_block_end(info), 1, sb.len - trailer_block_end(info), outfile);
182+
trailer_info_release(info);
183183

184184
if (opts->in_place)
185185
if (rename_tempfile(&trailers_tempfile, file))

trailer.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,12 @@ static void unfold_value(struct strbuf *val)
952952
strbuf_release(&out);
953953
}
954954

955+
struct trailer_info *trailer_info_new(void)
956+
{
957+
struct trailer_info *info = xcalloc(1, sizeof(*info));
958+
return info;
959+
}
960+
955961
/*
956962
* Parse trailers in "str", populating the trailer info and "head"
957963
* linked list structure.
@@ -1000,6 +1006,21 @@ void free_trailers(struct list_head *trailers)
10001006
}
10011007
}
10021008

1009+
size_t trailer_block_start(struct trailer_info *info)
1010+
{
1011+
return info->trailer_block_start;
1012+
}
1013+
1014+
size_t trailer_block_end(struct trailer_info *info)
1015+
{
1016+
return info->trailer_block_end;
1017+
}
1018+
1019+
int blank_line_before_trailer_block(struct trailer_info *info)
1020+
{
1021+
return info->blank_line_before_trailer;
1022+
}
1023+
10031024
void trailer_info_get(const struct process_trailer_options *opts,
10041025
const char *str,
10051026
struct trailer_info *info)

trailer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ void parse_trailers(const struct process_trailer_options *,
9797
void trailer_info_get(const struct process_trailer_options *,
9898
const char *str,
9999
struct trailer_info *);
100+
size_t trailer_block_start(struct trailer_info *);
101+
size_t trailer_block_end(struct trailer_info *);
102+
int blank_line_before_trailer_block(struct trailer_info *);
103+
struct trailer_info *trailer_info_new(void);
100104

101105
void trailer_info_release(struct trailer_info *info);
102106

0 commit comments

Comments
 (0)