Skip to content

Commit 8abc898

Browse files
peffgitster
authored andcommitted
trailer: put process_trailers() options into a struct
We already have two options and are about to add a few more. To avoid having a huge number of boolean arguments, let's convert to an options struct which can be passed in. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf8899d commit 8abc898

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

builtin/interpret-trailers.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ static const char * const git_interpret_trailers_usage[] = {
1818

1919
int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
2020
{
21-
int in_place = 0;
22-
int trim_empty = 0;
21+
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
2322
struct string_list trailers = STRING_LIST_INIT_NODUP;
2423

2524
struct option options[] = {
26-
OPT_BOOL(0, "in-place", &in_place, N_("edit files in place")),
27-
OPT_BOOL(0, "trim-empty", &trim_empty, N_("trim empty trailers")),
25+
OPT_BOOL(0, "in-place", &opts.in_place, N_("edit files in place")),
26+
OPT_BOOL(0, "trim-empty", &opts.trim_empty, N_("trim empty trailers")),
2827
OPT_STRING_LIST(0, "trailer", &trailers, N_("trailer"),
2928
N_("trailer(s) to add")),
3029
OPT_END()
@@ -36,11 +35,11 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
3635
if (argc) {
3736
int i;
3837
for (i = 0; i < argc; i++)
39-
process_trailers(argv[i], in_place, trim_empty, &trailers);
38+
process_trailers(argv[i], &opts, &trailers);
4039
} else {
41-
if (in_place)
40+
if (opts.in_place)
4241
die(_("no input file given for in-place editing"));
43-
process_trailers(NULL, in_place, trim_empty, &trailers);
42+
process_trailers(NULL, &opts, &trailers);
4443
}
4544

4645
string_list_clear(&trailers, 0);

trailer.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,9 @@ static FILE *create_in_place_tempfile(const char *file)
967967
return outfile;
968968
}
969969

970-
void process_trailers(const char *file, int in_place, int trim_empty, struct string_list *trailers)
970+
void process_trailers(const char *file,
971+
const struct process_trailer_options *opts,
972+
struct string_list *trailers)
971973
{
972974
LIST_HEAD(head);
973975
LIST_HEAD(arg_head);
@@ -979,7 +981,7 @@ void process_trailers(const char *file, int in_place, int trim_empty, struct str
979981

980982
read_input_file(&sb, file);
981983

982-
if (in_place)
984+
if (opts->in_place)
983985
outfile = create_in_place_tempfile(file);
984986

985987
/* Print the lines before the trailers */
@@ -989,14 +991,14 @@ void process_trailers(const char *file, int in_place, int trim_empty, struct str
989991

990992
process_trailers_lists(&head, &arg_head);
991993

992-
print_all(outfile, &head, trim_empty);
994+
print_all(outfile, &head, opts->trim_empty);
993995

994996
free_all(&head);
995997

996998
/* Print the lines after the trailers as is */
997999
fwrite(sb.buf + trailer_end, 1, sb.len - trailer_end, outfile);
9981000

999-
if (in_place)
1001+
if (opts->in_place)
10001002
if (rename_tempfile(&trailers_tempfile, file))
10011003
die_errno(_("could not rename temporary file to %s"), file);
10021004

trailer.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ struct trailer_info {
2222
size_t trailer_nr;
2323
};
2424

25-
void process_trailers(const char *file, int in_place, int trim_empty,
25+
struct process_trailer_options {
26+
int in_place;
27+
int trim_empty;
28+
};
29+
30+
#define PROCESS_TRAILER_OPTIONS_INIT {0}
31+
32+
void process_trailers(const char *file,
33+
const struct process_trailer_options *opts,
2634
struct string_list *trailers);
2735

2836
void trailer_info_get(struct trailer_info *info, const char *str);

0 commit comments

Comments
 (0)