Skip to content

Commit c2a8edf

Browse files
Linus Arvergitster
authored andcommitted
trailer: split process_input_file into separate pieces
Currently, process_input_file does three things: (1) parse the input string for trailers, (2) print text before the trailers, and (3) calculate the position of the input where the trailers end. Rename this function to parse_trailers(), and make it only do (1). The caller of this function, process_trailers, becomes responsible for (2) and (3). These items belong inside process_trailers because they are both concerned with printing the surrounding text around trailers (which is already one of the immediate concerns of process_trailers). Signed-off-by: Linus Arver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 13211ae commit c2a8edf

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

trailer.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -961,28 +961,24 @@ static void unfold_value(struct strbuf *val)
961961
strbuf_release(&out);
962962
}
963963

964-
static size_t process_input_file(FILE *outfile,
965-
const char *str,
966-
struct list_head *head,
967-
const struct process_trailer_options *opts)
964+
/*
965+
* Parse trailers in "str", populating the trailer info and "head"
966+
* linked list structure.
967+
*/
968+
static void parse_trailers(struct trailer_info *info,
969+
const char *str,
970+
struct list_head *head,
971+
const struct process_trailer_options *opts)
968972
{
969-
struct trailer_info info;
970973
struct strbuf tok = STRBUF_INIT;
971974
struct strbuf val = STRBUF_INIT;
972975
size_t i;
973976

974-
trailer_info_get(&info, str, opts);
975-
976-
/* Print lines before the trailers as is */
977-
if (!opts->only_trailers)
978-
fwrite(str, 1, info.trailer_start - str, outfile);
977+
trailer_info_get(info, str, opts);
979978

980-
if (!opts->only_trailers && !info.blank_line_before_trailer)
981-
fprintf(outfile, "\n");
982-
983-
for (i = 0; i < info.trailer_nr; i++) {
979+
for (i = 0; i < info->trailer_nr; i++) {
984980
int separator_pos;
985-
char *trailer = info.trailers[i];
981+
char *trailer = info->trailers[i];
986982
if (trailer[0] == comment_line_char)
987983
continue;
988984
separator_pos = find_separator(trailer, separators);
@@ -1002,10 +998,6 @@ static size_t process_input_file(FILE *outfile,
1002998
strbuf_detach(&val, NULL));
1003999
}
10041000
}
1005-
1006-
trailer_info_release(&info);
1007-
1008-
return info.trailer_end - str;
10091001
}
10101002

10111003
static void free_all(struct list_head *head)
@@ -1054,6 +1046,7 @@ void process_trailers(const char *file,
10541046
{
10551047
LIST_HEAD(head);
10561048
struct strbuf sb = STRBUF_INIT;
1049+
struct trailer_info info;
10571050
size_t trailer_end;
10581051
FILE *outfile = stdout;
10591052

@@ -1064,8 +1057,16 @@ void process_trailers(const char *file,
10641057
if (opts->in_place)
10651058
outfile = create_in_place_tempfile(file);
10661059

1060+
parse_trailers(&info, sb.buf, &head, opts);
1061+
trailer_end = info.trailer_end - sb.buf;
1062+
10671063
/* Print the lines before the trailers */
1068-
trailer_end = process_input_file(outfile, sb.buf, &head, opts);
1064+
if (!opts->only_trailers)
1065+
fwrite(sb.buf, 1, info.trailer_start - sb.buf, outfile);
1066+
1067+
if (!opts->only_trailers && !info.blank_line_before_trailer)
1068+
fprintf(outfile, "\n");
1069+
10691070

10701071
if (!opts->only_input) {
10711072
LIST_HEAD(arg_head);
@@ -1076,6 +1077,7 @@ void process_trailers(const char *file,
10761077
print_all(outfile, &head, opts);
10771078

10781079
free_all(&head);
1080+
trailer_info_release(&info);
10791081

10801082
/* Print the lines after the trailers as is */
10811083
if (!opts->only_trailers)

0 commit comments

Comments
 (0)