]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options: introduce OPT_IPVERSION()
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Jul 2023 21:34:33 +0000 (14:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Jul 2023 21:35:54 +0000 (14:35 -0700)
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 <gitster@pobox.com>
builtin/clone.c
builtin/fetch.c
builtin/push.c
parse-options.h

index 15f9912b4cae0583ac62d387120fcaa24a58ff23..6c9ad9b62132ef62faad3acf085d40b15863885b 100644 (file)
@@ -161,10 +161,7 @@ static struct option builtin_clone_options[] = {
                        N_("set config inside the new repository")),
        OPT_STRING_LIST(0, "server-option", &server_options,
                        N_("server-specific"), N_("option to transmit")),
-       OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
-                       TRANSPORT_FAMILY_IPV4),
-       OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
-                       TRANSPORT_FAMILY_IPV6),
+       OPT_IPVERSION(&family),
        OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
        OPT_BOOL(0, "also-filter-submodules", &option_filter_submodules,
                    N_("apply partial clone filters to submodules")),
index 849a9be421d0487a32e78fe9d941cc42714c4886..0b5cadc12a300ec2ca5acec3d2d5a76b351b2830 100644 (file)
@@ -2193,10 +2193,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
                OPT_CALLBACK_F(0, "refmap", NULL, N_("refmap"),
                               N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg),
                OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
-               OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
-                               TRANSPORT_FAMILY_IPV4),
-               OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
-                               TRANSPORT_FAMILY_IPV6),
+               OPT_IPVERSION(&family),
                OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
                                N_("report that we have only objects reachable from this object")),
                OPT_BOOL(0, "negotiate-only", &negotiate_only,
index dbdf609daf33172cb95ff082f3e23edb88c3d806..aa28fdba0ef49b3729840cfb5e92e5548455609e 100644 (file)
@@ -627,10 +627,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
                                PARSE_OPT_OPTARG, option_parse_push_signed),
                OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
                OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
-               OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
-                               TRANSPORT_FAMILY_IPV4),
-               OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
-                               TRANSPORT_FAMILY_IPV6),
+               OPT_IPVERSION(&family),
                OPT_END()
        };
 
index 8e48efe524882a6dcd4c854de6fcdbe0ef76acda..e35710733d105be1954103b5fde1d3596c73ebba 100644 (file)
@@ -581,4 +581,10 @@ int parse_opt_tracking_mode(const struct option *, const char *, int);
 #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"))
 #define OPT_AUTOSTASH(v) OPT_BOOL(0, "autostash", v, N_("automatically stash/stash pop before and after"))
 
+#define OPT_IPVERSION(v) \
+       OPT_SET_INT('4', "ipv4", (v), N_("use IPv4 addresses only"), \
+               TRANSPORT_FAMILY_IPV4), \
+       OPT_SET_INT('6', "ipv6", (v), N_("use IPv6 addresses only"), \
+               TRANSPORT_FAMILY_IPV6)
+
 #endif