Skip to content

Commit 6baf4e4

Browse files
tfidfwastakengitster
authored andcommitted
submodule--helper: add options for compute_submodule_clone_url()
Let's modify the interface to `compute_submodule_clone_url()` function by adding two more arguments, so that we can reuse this in various parts of `submodule--helper.c` that follow a common pattern, which is--read the remote url configuration of the superproject and then call `relative_url()`. This function is nearly identical to `resolve_relative_url()`, the only difference being the extra warning message. We can add a quiet flag to it, to suppress that warning when not needed, and then refactor `resolve_relative_url()` by using this function, something we will do in the next patch. We also rename the local variable 'relurl' to avoid potential confusion with the 'rel_url' parameter while we are at it. Having this functionality factored out will be useful for converting the rest of `submodule add` in subsequent patches. 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 59dcbb8 commit 6baf4e4

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

builtin/submodule--helper.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,24 +590,28 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
590590
return 0;
591591
}
592592

593-
static char *compute_submodule_clone_url(const char *rel_url)
593+
static char *compute_submodule_clone_url(const char *rel_url, const char *up_path, int quiet)
594594
{
595-
char *remoteurl, *relurl;
595+
char *remoteurl, *resolved_url;
596596
char *remote = get_default_remote();
597597
struct strbuf remotesb = STRBUF_INIT;
598598

599599
strbuf_addf(&remotesb, "remote.%s.url", remote);
600600
if (git_config_get_string(remotesb.buf, &remoteurl)) {
601-
warning(_("could not look up configuration '%s'. Assuming this repository is its own authoritative upstream."), remotesb.buf);
601+
if (!quiet)
602+
warning(_("could not look up configuration '%s'. "
603+
"Assuming this repository is its own "
604+
"authoritative upstream."),
605+
remotesb.buf);
602606
remoteurl = xgetcwd();
603607
}
604-
relurl = relative_url(remoteurl, rel_url, NULL);
608+
resolved_url = relative_url(remoteurl, rel_url, up_path);
605609

606610
free(remote);
607611
free(remoteurl);
608612
strbuf_release(&remotesb);
609613

610-
return relurl;
614+
return resolved_url;
611615
}
612616

613617
struct init_cb {
@@ -660,7 +664,7 @@ static void init_submodule(const char *path, const char *prefix,
660664
if (starts_with_dot_dot_slash(url) ||
661665
starts_with_dot_slash(url)) {
662666
char *oldurl = url;
663-
url = compute_submodule_clone_url(oldurl);
667+
url = compute_submodule_clone_url(oldurl, NULL, 0);
664668
free(oldurl);
665669
}
666670

@@ -2134,7 +2138,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
21342138
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
21352139
if (starts_with_dot_slash(sub->url) ||
21362140
starts_with_dot_dot_slash(sub->url)) {
2137-
url = compute_submodule_clone_url(sub->url);
2141+
url = compute_submodule_clone_url(sub->url, NULL, 0);
21382142
need_free_url = 1;
21392143
} else
21402144
url = sub->url;

0 commit comments

Comments
 (0)