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 <raykar.ath@gmail.com> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Shourya Shukla <periperidip@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Atharva Raykar committed
Aug 10, 2021 at 17:16 UTC
0c61041ed6778db86184d7a0d9759085f3cb9a82
1 file changed
+3
-13
builtin/submodule--helper.c
+3
-13
@@ -1373,20 +1373,10 @@ static void sync_submodule(const char *path, const char *prefix,
1373
if (sub && sub->url) {
1374
if (starts_with_dot_dot_slash(sub->url) ||
1375
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);
1379
free(up_path);
1389
- free(remote_url);
1380
} else {
1381
sub_origin_url = xstrdup(sub->url);
1382
super_config_url = xstrdup(sub->url);