format-patch: use OPT_STRING_LIST for to/cc options
The to_callback() and cc_callback() functions are identical to the generic parse_opt_string_list() function (except that they don't handle optional arguments, but that's OK because their callers do not use the OPTARG flag). Let's simplify the code by using OPT_STRING_LIST. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Aug 31, 2023 at 17:17 UTC
3ccb4c55adc36793ec34f6f9f2235a695df7d0a5
1 file changed
+2
-20
builtin/log.c
+2
-20
@@ -1567,24 +1567,6 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
1567
return 0;
1568
}
1569
1570
-static int to_callback(const struct option *opt, const char *arg, int unset)
1571
-{
1572
- if (unset)
1573
- string_list_clear(&extra_to, 0);
1574
- else
1575
- string_list_append(&extra_to, arg);
1576
- return 0;
1577
-}
1578
-
1579
-static int cc_callback(const struct option *opt, const char *arg, int unset)
1580
-{
1581
- if (unset)
1582
- string_list_clear(&extra_cc, 0);
1583
- else
1584
- string_list_append(&extra_cc, arg);
1585
- return 0;
1586
-}
1587
-
1570
static int from_callback(const struct option *opt, const char *arg, int unset)
1571
{
1572
char **from = opt->value;
@@ -1957,8 +1939,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1939
OPT_GROUP(N_("Messaging")),
1940
OPT_CALLBACK(0, "add-header", NULL, N_("header"),
1941
N_("add email header"), header_callback),
1960
- OPT_CALLBACK(0, "to", NULL, N_("email"), N_("add To: header"), to_callback),
1961
- OPT_CALLBACK(0, "cc", NULL, N_("email"), N_("add Cc: header"), cc_callback),
1942
+ OPT_STRING_LIST(0, "to", &extra_to, N_("email"), N_("add To: header")),
1943
+ OPT_STRING_LIST(0, "cc", &extra_cc, N_("email"), N_("add Cc: header")),
1944
OPT_CALLBACK_F(0, "from", &from, N_("ident"),
1945
N_("set From address to <ident> (or committer ident if absent)"),
1946
PARSE_OPT_OPTARG, from_callback),