submodule--helper: introduce get_submodule_displaypath()
Introduce function get_submodule_displaypath() to replace the code occurring in submodule_init() for generating displaypath of the submodule with a call to it. This new function will also be used in other parts of the system in later patches. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Stefan Beller <sbeller@google.com> Signed-off-by: Prathamesh Chavan <pc44800@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
59c0ea183a
commit
74a10642aa
@ -220,6 +220,26 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the result should be freed by the caller. */
|
||||
static char *get_submodule_displaypath(const char *path, const char *prefix)
|
||||
{
|
||||
const char *super_prefix = get_super_prefix();
|
||||
|
||||
if (prefix && super_prefix) {
|
||||
BUG("cannot have prefix '%s' and superprefix '%s'",
|
||||
prefix, super_prefix);
|
||||
} else if (prefix) {
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
char *displaypath = xstrdup(relative_path(path, prefix, &sb));
|
||||
strbuf_release(&sb);
|
||||
return displaypath;
|
||||
} else if (super_prefix) {
|
||||
return xstrfmt("%s%s", super_prefix, path);
|
||||
} else {
|
||||
return xstrdup(path);
|
||||
}
|
||||
}
|
||||
|
||||
struct module_list {
|
||||
const struct cache_entry **entries;
|
||||
int alloc, nr;
|
||||
@ -335,15 +355,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
char *upd = NULL, *url = NULL, *displaypath;
|
||||
|
||||
if (prefix && get_super_prefix())
|
||||
die("BUG: cannot have prefix and superprefix");
|
||||
else if (prefix)
|
||||
displaypath = xstrdup(relative_path(path, prefix, &sb));
|
||||
else if (get_super_prefix()) {
|
||||
strbuf_addf(&sb, "%s%s", get_super_prefix(), path);
|
||||
displaypath = strbuf_detach(&sb, NULL);
|
||||
} else
|
||||
displaypath = xstrdup(path);
|
||||
displaypath = get_submodule_displaypath(path, prefix);
|
||||
|
||||
sub = submodule_from_path(&null_oid, path);
|
||||
|
||||
@ -358,9 +370,9 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
|
||||
* Set active flag for the submodule being initialized
|
||||
*/
|
||||
if (!is_submodule_active(the_repository, path)) {
|
||||
strbuf_reset(&sb);
|
||||
strbuf_addf(&sb, "submodule.%s.active", sub->name);
|
||||
git_config_set_gently(sb.buf, "true");
|
||||
strbuf_reset(&sb);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -368,7 +380,6 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
|
||||
* To look up the url in .git/config, we must not fall back to
|
||||
* .gitmodules, so look it up directly.
|
||||
*/
|
||||
strbuf_reset(&sb);
|
||||
strbuf_addf(&sb, "submodule.%s.url", sub->name);
|
||||
if (git_config_get_string(sb.buf, &url)) {
|
||||
if (!sub->url)
|
||||
@ -405,9 +416,9 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
|
||||
_("Submodule '%s' (%s) registered for path '%s'\n"),
|
||||
sub->name, url, displaypath);
|
||||
}
|
||||
strbuf_reset(&sb);
|
||||
|
||||
/* Copy "update" setting when it is not set yet */
|
||||
strbuf_reset(&sb);
|
||||
strbuf_addf(&sb, "submodule.%s.update", sub->name);
|
||||
if (git_config_get_string(sb.buf, &upd) &&
|
||||
sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
|
||||
|
Loading…
Reference in New Issue
Block a user