submodule--helper: don't overlay config in update-clone

Don't rely on overlaying the repository's config on top of the
submodule-config, instead query the repository's config directly for the
url and the update strategy configuration.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brandon Williams 2017-08-03 11:19:50 -07:00 коммит произвёл Junio C Hamano
Родитель 177257ccc7
Коммит ec6141a0f2
3 изменённых файлов: 46 добавлений и 16 удалений

Просмотреть файл

@ -780,6 +780,10 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
struct strbuf *out) struct strbuf *out)
{ {
const struct submodule *sub = NULL; const struct submodule *sub = NULL;
const char *url = NULL;
const char *update_string;
enum submodule_update_type update_type;
char *key;
struct strbuf displaypath_sb = STRBUF_INIT; struct strbuf displaypath_sb = STRBUF_INIT;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
const char *displaypath = NULL; const char *displaypath = NULL;
@ -808,9 +812,17 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
goto cleanup; goto cleanup;
} }
key = xstrfmt("submodule.%s.update", sub->name);
if (!repo_config_get_string_const(the_repository, key, &update_string)) {
update_type = parse_submodule_update_type(update_string);
} else {
update_type = sub->update_strategy.type;
}
free(key);
if (suc->update.type == SM_UPDATE_NONE if (suc->update.type == SM_UPDATE_NONE
|| (suc->update.type == SM_UPDATE_UNSPECIFIED || (suc->update.type == SM_UPDATE_UNSPECIFIED
&& sub->update_strategy.type == SM_UPDATE_NONE)) { && update_type == SM_UPDATE_NONE)) {
strbuf_addf(out, _("Skipping submodule '%s'"), displaypath); strbuf_addf(out, _("Skipping submodule '%s'"), displaypath);
strbuf_addch(out, '\n'); strbuf_addch(out, '\n');
goto cleanup; goto cleanup;
@ -822,6 +834,11 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
goto cleanup; goto cleanup;
} }
strbuf_reset(&sb);
strbuf_addf(&sb, "submodule.%s.url", sub->name);
if (repo_config_get_string_const(the_repository, sb.buf, &url))
url = sub->url;
strbuf_reset(&sb); strbuf_reset(&sb);
strbuf_addf(&sb, "%s/.git", ce->name); strbuf_addf(&sb, "%s/.git", ce->name);
needs_cloning = !file_exists(sb.buf); needs_cloning = !file_exists(sb.buf);
@ -851,7 +868,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
argv_array_push(&child->args, "--depth=1"); argv_array_push(&child->args, "--depth=1");
argv_array_pushl(&child->args, "--path", sub->path, NULL); argv_array_pushl(&child->args, "--path", sub->path, NULL);
argv_array_pushl(&child->args, "--name", sub->name, NULL); argv_array_pushl(&child->args, "--name", sub->name, NULL);
argv_array_pushl(&child->args, "--url", sub->url, NULL); argv_array_pushl(&child->args, "--url", url, NULL);
if (suc->references.nr) { if (suc->references.nr) {
struct string_list_item *item; struct string_list_item *item;
for_each_string_list_item(item, &suc->references) for_each_string_list_item(item, &suc->references)
@ -1025,9 +1042,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
if (pathspec.nr) if (pathspec.nr)
suc.warn_if_uninitialized = 1; suc.warn_if_uninitialized = 1;
/* Overlay the parsed .gitmodules file with .git/config */
gitmodules_config(); gitmodules_config();
git_config(submodule_config, NULL);
run_processes_parallel(max_jobs, run_processes_parallel(max_jobs,
update_clone_get_next_task, update_clone_get_next_task,

Просмотреть файл

@ -398,24 +398,38 @@ void die_path_inside_submodule(const struct index_state *istate,
} }
} }
enum submodule_update_type parse_submodule_update_type(const char *value)
{
if (!strcmp(value, "none"))
return SM_UPDATE_NONE;
else if (!strcmp(value, "checkout"))
return SM_UPDATE_CHECKOUT;
else if (!strcmp(value, "rebase"))
return SM_UPDATE_REBASE;
else if (!strcmp(value, "merge"))
return SM_UPDATE_MERGE;
else if (*value == '!')
return SM_UPDATE_COMMAND;
else
return SM_UPDATE_UNSPECIFIED;
}
int parse_submodule_update_strategy(const char *value, int parse_submodule_update_strategy(const char *value,
struct submodule_update_strategy *dst) struct submodule_update_strategy *dst)
{ {
enum submodule_update_type type;
free((void*)dst->command); free((void*)dst->command);
dst->command = NULL; dst->command = NULL;
if (!strcmp(value, "none"))
dst->type = SM_UPDATE_NONE; type = parse_submodule_update_type(value);
else if (!strcmp(value, "checkout")) if (type == SM_UPDATE_UNSPECIFIED)
dst->type = SM_UPDATE_CHECKOUT;
else if (!strcmp(value, "rebase"))
dst->type = SM_UPDATE_REBASE;
else if (!strcmp(value, "merge"))
dst->type = SM_UPDATE_MERGE;
else if (skip_prefix(value, "!", &value)) {
dst->type = SM_UPDATE_COMMAND;
dst->command = xstrdup(value);
} else
return -1; return -1;
dst->type = type;
if (type == SM_UPDATE_COMMAND)
dst->command = xstrdup(value + 1);
return 0; return 0;
} }

Просмотреть файл

@ -62,6 +62,7 @@ extern void die_in_unpopulated_submodule(const struct index_state *istate,
const char *prefix); const char *prefix);
extern void die_path_inside_submodule(const struct index_state *istate, extern void die_path_inside_submodule(const struct index_state *istate,
const struct pathspec *ps); const struct pathspec *ps);
extern enum submodule_update_type parse_submodule_update_type(const char *value);
extern int parse_submodule_update_strategy(const char *value, extern int parse_submodule_update_strategy(const char *value,
struct submodule_update_strategy *dst); struct submodule_update_strategy *dst);
extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s); extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);