]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-submodule: inline resolve_relative_url() function
authorJeff King <peff@peff.net>
Thu, 6 Oct 2022 13:10:15 +0000 (09:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 Oct 2022 16:56:28 +0000 (09:56 -0700)
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>
t/helper/test-submodule.c

index e0e0c53d38619ded93c916b5f11685cf616a1de2..b7d117cd557a84eabcdc25df9ae874e0192e3dd7 100644 (file)
@@ -85,10 +85,17 @@ static int cmd__submodule_is_active(int argc, const char **argv)
        return !is_submodule_active(the_repository, argv[0]);
 }
 
-static int resolve_relative_url(int argc, const char **argv)
+static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
 {
        char *remoteurl, *res;
        const char *up_path, *url;
+       struct option options[] = {
+               OPT_END()
+       };
+       argc = parse_options(argc, argv, "test-tools", options,
+                            submodule_resolve_relative_url_usage, 0);
+       if (argc != 3)
+               usage_with_options(submodule_resolve_relative_url_usage, options);
 
        up_path = argv[0];
        remoteurl = xstrdup(argv[1]);
@@ -104,19 +111,6 @@ static int resolve_relative_url(int argc, const char **argv)
        return 0;
 }
 
-static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
-{
-       struct option options[] = {
-               OPT_END()
-       };
-       argc = parse_options(argc, argv, "test-tools", options,
-                            submodule_resolve_relative_url_usage, 0);
-       if (argc != 3)
-               usage_with_options(submodule_resolve_relative_url_usage, options);
-
-       return resolve_relative_url(argc, argv);
-}
-
 static struct test_cmd cmds[] = {
        { "check-name", cmd__submodule_check_name },
        { "is-active", cmd__submodule_is_active },