* [PATCH] parse-options: introduce OPT_IPVERSION()
@ 2023-07-18 21:34 Junio C Hamano
2023-07-18 21:45 ` [PATCH] fetch: reject --no-ipv[46] Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2023-07-18 21:34 UTC (permalink / raw)
To: git
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>
---
* No changes in behaviour (yet). Notably, they still accept
"--no-ipv4" and do nonsensical things.
builtin/clone.c | 5 +----
builtin/fetch.c | 5 +----
builtin/push.c | 5 +----
parse-options.h | 6 ++++++
4 files changed, 9 insertions(+), 12 deletions(-)
diff --git c/builtin/clone.c w/builtin/clone.c
index 15f9912b4c..6c9ad9b621 100644
--- c/builtin/clone.c
+++ w/builtin/clone.c
@@ -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")),
diff --git c/builtin/fetch.c w/builtin/fetch.c
index 849a9be421..0b5cadc12a 100644
--- c/builtin/fetch.c
+++ w/builtin/fetch.c
@@ -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,
diff --git c/builtin/push.c w/builtin/push.c
index dbdf609daf..aa28fdba0e 100644
--- c/builtin/push.c
+++ w/builtin/push.c
@@ -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()
};
diff --git c/parse-options.h w/parse-options.h
index 8e48efe524..e35710733d 100644
--- c/parse-options.h
+++ w/parse-options.h
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] fetch: reject --no-ipv[46]
2023-07-18 21:34 [PATCH] parse-options: introduce OPT_IPVERSION() Junio C Hamano
@ 2023-07-18 21:45 ` Junio C Hamano
2023-07-18 21:59 ` Taylor Blau
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2023-07-18 21:45 UTC (permalink / raw)
To: git
Now we have introduced OPT_IPVERSION(), tweak its implementation so
that "git clone", "git fetch", and "git push" reject the negated
form of "Use only IP version N" options.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
parse-options.h | 8 ++++----
t/t5516-fetch-push.sh | 11 +++++++++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git c/parse-options.h w/parse-options.h
index e35710733d..57a7fe9d91 100644
--- c/parse-options.h
+++ w/parse-options.h
@@ -582,9 +582,9 @@ int parse_opt_tracking_mode(const struct option *, const char *, int);
#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)
+ OPT_SET_INT_F('4', "ipv4", (v), N_("use IPv4 addresses only"), \
+ TRANSPORT_FAMILY_IPV4, PARSE_OPT_NONEG), \
+ OPT_SET_INT_F('6', "ipv6", (v), N_("use IPv6 addresses only"), \
+ TRANSPORT_FAMILY_IPV6, PARSE_OPT_NONEG)
#endif
diff --git c/t/t5516-fetch-push.sh w/t/t5516-fetch-push.sh
index 19ebefa5ac..87163d7745 100755
--- c/t/t5516-fetch-push.sh
+++ w/t/t5516-fetch-push.sh
@@ -120,6 +120,17 @@ test_expect_success setup '
'
+for cmd in push fetch
+do
+ for opt in ipv4 ipv6
+ do
+ test_expect_success "reject 'git $cmd --no-$opt'" '
+ test_must_fail git $cmd --no-$opt 2>err &&
+ grep "unknown option .no-$opt" err
+ '
+ done
+done
+
test_expect_success 'fetch without wildcard' '
mk_empty testrepo &&
(
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fetch: reject --no-ipv[46]
2023-07-18 21:45 ` [PATCH] fetch: reject --no-ipv[46] Junio C Hamano
@ 2023-07-18 21:59 ` Taylor Blau
0 siblings, 0 replies; 3+ messages in thread
From: Taylor Blau @ 2023-07-18 21:59 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Tue, Jul 18, 2023 at 02:45:59PM -0700, Junio C Hamano wrote:
> parse-options.h | 8 ++++----
> t/t5516-fetch-push.sh | 11 +++++++++++
> 2 files changed, 15 insertions(+), 4 deletions(-)
The first patch is an obvious improvement, and the same is true of the
second one. Both of these look good to me.
Thanks,
Taylor
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-18 21:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-18 21:34 [PATCH] parse-options: introduce OPT_IPVERSION() Junio C Hamano
2023-07-18 21:45 ` [PATCH] fetch: reject --no-ipv[46] Junio C Hamano
2023-07-18 21:59 ` Taylor Blau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).