{"thread":{"id":"60005","subject":"[PATCH] parse-options: introduce OPT_IPVERSION()","startedAt":"2023-07-18T21:34:41Z","lastAt":"2023-07-18T21:59:15Z","messageCount":3,"participants":["Junio C Hamano","Taylor Blau"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"479609","messageId":"xmqqjzuwgaza.fsf@gitster.g","threadId":"60005","inReplyTo":null,"subject":"[PATCH] parse-options: introduce OPT_IPVERSION()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-18T21:34:33Z","receivedAt":"2023-07-18T21:34:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The command line option parsing for \"git clone\", \"git fetch\", and\n\"git push\" have duplicated implementations of parsing \"--ipv4\" and\n\"--ipv6\" options, by having two OPT_SET_INT() for \"ipv4\" and \"ipv6\".\n\nIntroduce a new OPT_IPVERSION() macro and use it in these three\ncommands.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n * No changes in behaviour (yet).  Notably, they still accept\n   \"--no-ipv4\" and do nonsensical things.\n\n builtin/clone.c | 5 +----\n builtin/fetch.c | 5 +----\n builtin/push.c  | 5 +----\n parse-options.h | 6 ++++++\n 4 files changed, 9 insertions(+), 12 deletions(-)\n\ndiff --git c/builtin/clone.c w/builtin/clone.c\nindex 15f9912b4c..6c9ad9b621 100644\n--- c/builtin/clone.c\n+++ w/builtin/clone.c\n@@ -161,10 +161,7 @@ static struct option builtin_clone_options[] = {\n \t\t\tN_(\"set config inside the new repository\")),\n \tOPT_STRING_LIST(0, \"server-option\", &server_options,\n \t\t\tN_(\"server-specific\"), N_(\"option to transmit\")),\n-\tOPT_SET_INT('4', \"ipv4\", &family, N_(\"use IPv4 addresses only\"),\n-\t\t\tTRANSPORT_FAMILY_IPV4),\n-\tOPT_SET_INT('6', \"ipv6\", &family, N_(\"use IPv6 addresses only\"),\n-\t\t\tTRANSPORT_FAMILY_IPV6),\n+\tOPT_IPVERSION(&family),\n \tOPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),\n \tOPT_BOOL(0, \"also-filter-submodules\", &option_filter_submodules,\n \t\t    N_(\"apply partial clone filters to submodules\")),\ndiff --git c/builtin/fetch.c w/builtin/fetch.c\nindex 849a9be421..0b5cadc12a 100644\n--- c/builtin/fetch.c\n+++ w/builtin/fetch.c\n@@ -2193,10 +2193,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \t\tOPT_CALLBACK_F(0, \"refmap\", NULL, N_(\"refmap\"),\n \t\t\t       N_(\"specify fetch refmap\"), PARSE_OPT_NONEG, parse_refmap_arg),\n \t\tOPT_STRING_LIST('o', \"server-option\", &server_options, N_(\"server-specific\"), N_(\"option to transmit\")),\n-\t\tOPT_SET_INT('4', \"ipv4\", &family, N_(\"use IPv4 addresses only\"),\n-\t\t\t\tTRANSPORT_FAMILY_IPV4),\n-\t\tOPT_SET_INT('6', \"ipv6\", &family, N_(\"use IPv6 addresses only\"),\n-\t\t\t\tTRANSPORT_FAMILY_IPV6),\n+\t\tOPT_IPVERSION(&family),\n \t\tOPT_STRING_LIST(0, \"negotiation-tip\", &negotiation_tip, N_(\"revision\"),\n \t\t\t\tN_(\"report that we have only objects reachable from this object\")),\n \t\tOPT_BOOL(0, \"negotiate-only\", &negotiate_only,\ndiff --git c/builtin/push.c w/builtin/push.c\nindex dbdf609daf..aa28fdba0e 100644\n--- c/builtin/push.c\n+++ w/builtin/push.c\n@@ -627,10 +627,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)\n \t\t\t\tPARSE_OPT_OPTARG, option_parse_push_signed),\n \t\tOPT_BIT(0, \"atomic\", &flags, N_(\"request atomic transaction on remote side\"), TRANSPORT_PUSH_ATOMIC),\n \t\tOPT_STRING_LIST('o', \"push-option\", &push_options_cmdline, N_(\"server-specific\"), N_(\"option to transmit\")),\n-\t\tOPT_SET_INT('4', \"ipv4\", &family, N_(\"use IPv4 addresses only\"),\n-\t\t\t\tTRANSPORT_FAMILY_IPV4),\n-\t\tOPT_SET_INT('6', \"ipv6\", &family, N_(\"use IPv6 addresses only\"),\n-\t\t\t\tTRANSPORT_FAMILY_IPV6),\n+\t\tOPT_IPVERSION(&family),\n \t\tOPT_END()\n \t};\n \ndiff --git c/parse-options.h w/parse-options.h\nindex 8e48efe524..e35710733d 100644\n--- c/parse-options.h\n+++ w/parse-options.h\n@@ -581,4 +581,10 @@ int parse_opt_tracking_mode(const struct option *, const char *, int);\n #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\"))\n #define OPT_AUTOSTASH(v) OPT_BOOL(0, \"autostash\", v, N_(\"automatically stash/stash pop before and after\"))\n \n+#define OPT_IPVERSION(v) \\\n+\tOPT_SET_INT('4', \"ipv4\", (v), N_(\"use IPv4 addresses only\"), \\\n+\t\tTRANSPORT_FAMILY_IPV4), \\\n+\tOPT_SET_INT('6', \"ipv6\", (v), N_(\"use IPv6 addresses only\"), \\\n+\t\tTRANSPORT_FAMILY_IPV6)\n+\n #endif\n\n"},{"id":"479610","messageId":"xmqqedl4gag8.fsf@gitster.g","threadId":"60005","inReplyTo":"xmqqjzuwgaza.fsf@gitster.g","subject":"[PATCH] fetch: reject --no-ipv[46]","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-18T21:45:59Z","receivedAt":"2023-07-18T21:46:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Now we have introduced OPT_IPVERSION(), tweak its implementation so\nthat \"git clone\", \"git fetch\", and \"git push\" reject the negated\nform of \"Use only IP version N\" options.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n parse-options.h       |  8 ++++----\n t/t5516-fetch-push.sh | 11 +++++++++++\n 2 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git c/parse-options.h w/parse-options.h\nindex e35710733d..57a7fe9d91 100644\n--- c/parse-options.h\n+++ w/parse-options.h\n@@ -582,9 +582,9 @@ int parse_opt_tracking_mode(const struct option *, const char *, int);\n #define OPT_AUTOSTASH(v) OPT_BOOL(0, \"autostash\", v, N_(\"automatically stash/stash pop before and after\"))\n \n #define OPT_IPVERSION(v) \\\n-\tOPT_SET_INT('4', \"ipv4\", (v), N_(\"use IPv4 addresses only\"), \\\n-\t\tTRANSPORT_FAMILY_IPV4), \\\n-\tOPT_SET_INT('6', \"ipv6\", (v), N_(\"use IPv6 addresses only\"), \\\n-\t\tTRANSPORT_FAMILY_IPV6)\n+\tOPT_SET_INT_F('4', \"ipv4\", (v), N_(\"use IPv4 addresses only\"), \\\n+\t\tTRANSPORT_FAMILY_IPV4, PARSE_OPT_NONEG), \\\n+\tOPT_SET_INT_F('6', \"ipv6\", (v), N_(\"use IPv6 addresses only\"), \\\n+\t\tTRANSPORT_FAMILY_IPV6, PARSE_OPT_NONEG)\n \n #endif\ndiff --git c/t/t5516-fetch-push.sh w/t/t5516-fetch-push.sh\nindex 19ebefa5ac..87163d7745 100755\n--- c/t/t5516-fetch-push.sh\n+++ w/t/t5516-fetch-push.sh\n@@ -120,6 +120,17 @@ test_expect_success setup '\n \n '\n \n+for cmd in push fetch\n+do\n+\tfor opt in ipv4 ipv6\n+\tdo\n+\t\ttest_expect_success \"reject 'git $cmd --no-$opt'\" '\n+\t\t\ttest_must_fail git $cmd --no-$opt 2>err &&\n+\t\t\tgrep \"unknown option .no-$opt\" err\n+\t\t'\n+\tdone\n+done\n+\n test_expect_success 'fetch without wildcard' '\n \tmk_empty testrepo &&\n \t(\n\n"},{"id":"479611","messageId":"ZLcLLGet7GDmqfRb@nand.local","threadId":"60005","inReplyTo":"xmqqedl4gag8.fsf@gitster.g","subject":"Re: [PATCH] fetch: reject --no-ipv[46]","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2023-07-18T21:59:08Z","receivedAt":"2023-07-18T21:59:15Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, Jul 18, 2023 at 02:45:59PM -0700, Junio C Hamano wrote:\n>  parse-options.h       |  8 ++++----\n>  t/t5516-fetch-push.sh | 11 +++++++++++\n>  2 files changed, 15 insertions(+), 4 deletions(-)\n\nThe first patch is an obvious improvement, and the same is true of the\nsecond one. Both of these look good to me.\n\nThanks,\nTaylor\n"}]}