Skip to content

Commit 0c61041

Browse files
tfidfwastakengitster
authored andcommitted
submodule--helper: remove repeated code in sync_submodule()
This part of `sync_submodule()` is doing the same thing that `compute_submodule_clone_url()` is doing. Let's reuse that helper here. Note that this change adds a small overhead where we allocate and free the 'remote' twice, but that is a small price to pay for the higher level of abstraction we get. Signed-off-by: Atharva Raykar <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Shourya Shukla <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab6f23b commit 0c61041

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

builtin/submodule--helper.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,20 +1373,10 @@ static void sync_submodule(const char *path, const char *prefix,
13731373
if (sub && sub->url) {
13741374
if (starts_with_dot_dot_slash(sub->url) ||
13751375
starts_with_dot_slash(sub->url)) {
1376-
char *remote_url, *up_path;
1377-
char *remote = get_default_remote();
1378-
strbuf_addf(&sb, "remote.%s.url", remote);
1379-
1380-
if (git_config_get_string(sb.buf, &remote_url))
1381-
remote_url = xgetcwd();
1382-
1383-
up_path = get_up_path(path);
1384-
sub_origin_url = relative_url(remote_url, sub->url, up_path);
1385-
super_config_url = relative_url(remote_url, sub->url, NULL);
1386-
1387-
free(remote);
1376+
char *up_path = get_up_path(path);
1377+
sub_origin_url = compute_submodule_clone_url(sub->url, up_path, 1);
1378+
super_config_url = compute_submodule_clone_url(sub->url, NULL, 1);
13881379
free(up_path);
1389-
free(remote_url);
13901380
} else {
13911381
sub_origin_url = xstrdup(sub->url);
13921382
super_config_url = xstrdup(sub->url);

0 commit comments

Comments
 (0)