Skip to content

Commit 6823c19

Browse files
peffgitster
authored andcommitted
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 96a28a9 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3dcec76 commit 6823c19

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

t/helper/test-submodule.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,17 @@ static int cmd__submodule_is_active(int argc, const char **argv)
8585
return !is_submodule_active(the_repository, argv[0]);
8686
}
8787

88-
static int resolve_relative_url(int argc, const char **argv)
88+
static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
8989
{
9090
char *remoteurl, *res;
9191
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);
9299

93100
up_path = argv[0];
94101
remoteurl = xstrdup(argv[1]);
@@ -104,19 +111,6 @@ static int resolve_relative_url(int argc, const char **argv)
104111
return 0;
105112
}
106113

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-
120114
static struct test_cmd cmds[] = {
121115
{ "check-name", cmd__submodule_check_name },
122116
{ "is-active", cmd__submodule_is_active },

0 commit comments

Comments
 (0)