test-submodule: inline resolve_relative_url() function

The resolve_relative_url() function takes argc and argv parameters; it then reads up to 3 elements of argv without looking at argc at all. At first glance, this seems like a bug. But it has only one caller, cmd__submodule_resolve_relative_url(), which does confirm that argc is 3. The main reason this is a separate function is that it was moved from library code in 96a28a9bc6 (submodule--helper: move "resolve-relative-url-test" to a test-tool, 2022-09-01). We can make this code simpler and more obviously safe by just inlining the function in its caller. As a bonus, this silences a -Wunused-parameter warning. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 6, 2022 at 09:10 UTC 6823c19888a5d1b68da725bf2093dc1155a50afb
1 file changed +8 -14
t/helper/test-submodule.c
+8 -14
@@ -85,10 +85,17 @@ static int cmd__submodule_is_active(int argc, const char **argv)
85 return !is_submodule_active(the_repository, argv[0]);
86 }
87
88 -static int resolve_relative_url(int argc, const char **argv)
88 +static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
89 {
90 char *remoteurl, *res;
91 const char *up_path, *url;
92 + struct option options[] = {
93 + OPT_END()
94 + };
95 + argc = parse_options(argc, argv, "test-tools", options,
96 + submodule_resolve_relative_url_usage, 0);
97 + if (argc != 3)
98 + usage_with_options(submodule_resolve_relative_url_usage, options);
99
100 up_path = argv[0];
101 remoteurl = xstrdup(argv[1]);
@@ -104,19 +111,6 @@ static int resolve_relative_url(int argc, const char **argv)
111 return 0;
112 }
113
107 -static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
108 -{
109 - struct option options[] = {
110 - OPT_END()
111 - };
112 - argc = parse_options(argc, argv, "test-tools", options,
113 - submodule_resolve_relative_url_usage, 0);
114 - if (argc != 3)
115 - usage_with_options(submodule_resolve_relative_url_usage, options);
116 -
117 - return resolve_relative_url(argc, argv);
118 -}
119 -
114 static struct test_cmd cmds[] = {
115 { "check-name", cmd__submodule_check_name },
116 { "is-active", cmd__submodule_is_active },