Skip to content

Commit ae2c912

Browse files
committed
parse-options: introduce OPT_IPVERSION()
The command line option parsing for "git clone", "git fetch", and "git push" have duplicated implementations of parsing "--ipv4" and "--ipv6" options, by having two OPT_SET_INT() for "ipv4" and "ipv6". Introduce a new OPT_IPVERSION() macro and use it in these three commands. Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb7d80e commit ae2c912

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

builtin/clone.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ static struct option builtin_clone_options[] = {
161161
N_("set config inside the new repository")),
162162
OPT_STRING_LIST(0, "server-option", &server_options,
163163
N_("server-specific"), N_("option to transmit")),
164-
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
165-
TRANSPORT_FAMILY_IPV4),
166-
OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
167-
TRANSPORT_FAMILY_IPV6),
164+
OPT_IPVERSION(&family),
168165
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
169166
OPT_BOOL(0, "also-filter-submodules", &option_filter_submodules,
170167
N_("apply partial clone filters to submodules")),

builtin/fetch.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,10 +2193,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
21932193
OPT_CALLBACK_F(0, "refmap", NULL, N_("refmap"),
21942194
N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg),
21952195
OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
2196-
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
2197-
TRANSPORT_FAMILY_IPV4),
2198-
OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
2199-
TRANSPORT_FAMILY_IPV6),
2196+
OPT_IPVERSION(&family),
22002197
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
22012198
N_("report that we have only objects reachable from this object")),
22022199
OPT_BOOL(0, "negotiate-only", &negotiate_only,

builtin/push.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
627627
PARSE_OPT_OPTARG, option_parse_push_signed),
628628
OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
629629
OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
630-
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
631-
TRANSPORT_FAMILY_IPV4),
632-
OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
633-
TRANSPORT_FAMILY_IPV6),
630+
OPT_IPVERSION(&family),
634631
OPT_END()
635632
};
636633

parse-options.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,10 @@ int parse_opt_tracking_mode(const struct option *, const char *, int);
581581
#define OPT_PATHSPEC_FILE_NUL(v) OPT_BOOL(0, "pathspec-file-nul", v, N_("with --pathspec-from-file, pathspec elements are separated with NUL character"))
582582
#define OPT_AUTOSTASH(v) OPT_BOOL(0, "autostash", v, N_("automatically stash/stash pop before and after"))
583583

584+
#define OPT_IPVERSION(v) \
585+
OPT_SET_INT('4', "ipv4", (v), N_("use IPv4 addresses only"), \
586+
TRANSPORT_FAMILY_IPV4), \
587+
OPT_SET_INT('6', "ipv6", (v), N_("use IPv6 addresses only"), \
588+
TRANSPORT_FAMILY_IPV6)
589+
584590
#endif

0 commit comments

Comments
 (0)