submodule--helper: libify determine_submodule_update_strategy()

Libify the determine_submodule_update_strategy() by having it invoke
die_message() rather than die(), and returning the code die_message()
returns on failure.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Ævar Arnfjörð Bjarmason 2022-09-01 01:18:08 +02:00 committed by Junio C Hamano
parent 2cb9294b99
commit 484f9150e6
1 changed files with 25 additions and 14 deletions

View File

@ -1730,7 +1730,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
return 0; return 0;
} }


static void determine_submodule_update_strategy(struct repository *r, static int determine_submodule_update_strategy(struct repository *r,
int just_cloned, int just_cloned,
const char *path, const char *path,
enum submodule_update_type update, enum submodule_update_type update,
@ -1739,15 +1739,18 @@ static void determine_submodule_update_strategy(struct repository *r,
const struct submodule *sub = submodule_from_path(r, null_oid(), path); const struct submodule *sub = submodule_from_path(r, null_oid(), path);
char *key; char *key;
const char *val; const char *val;
int ret;


key = xstrfmt("submodule.%s.update", sub->name); key = xstrfmt("submodule.%s.update", sub->name);


if (update) { if (update) {
out->type = update; out->type = update;
} else if (!repo_config_get_string_tmp(r, key, &val)) { } else if (!repo_config_get_string_tmp(r, key, &val)) {
if (parse_submodule_update_strategy(val, out) < 0) if (parse_submodule_update_strategy(val, out) < 0) {
die(_("Invalid update mode '%s' configured for submodule path '%s'"), ret = die_message(_("Invalid update mode '%s' configured for submodule path '%s'"),
val, path); val, path);
goto cleanup;
}
} else if (sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) { } else if (sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
if (sub->update_strategy.type == SM_UPDATE_COMMAND) if (sub->update_strategy.type == SM_UPDATE_COMMAND)
BUG("how did we read update = !command from .gitmodules?"); BUG("how did we read update = !command from .gitmodules?");
@ -1762,7 +1765,10 @@ static void determine_submodule_update_strategy(struct repository *r,
out->type == SM_UPDATE_NONE)) out->type == SM_UPDATE_NONE))
out->type = SM_UPDATE_CHECKOUT; out->type = SM_UPDATE_CHECKOUT;


ret = 0;
cleanup:
free(key); free(key);
return ret;
} }


struct update_clone_data { struct update_clone_data {
@ -2388,14 +2394,22 @@ static void update_data_to_args(const struct update_data *update_data,
static int update_submodule(struct update_data *update_data, static int update_submodule(struct update_data *update_data,
int *must_die_on_failure) int *must_die_on_failure)
{ {
int ret;

ensure_core_worktree(update_data->sm_path); ensure_core_worktree(update_data->sm_path);


update_data->displaypath = get_submodule_displaypath( update_data->displaypath = get_submodule_displaypath(
update_data->sm_path, update_data->prefix); update_data->sm_path, update_data->prefix);


determine_submodule_update_strategy(the_repository, update_data->just_cloned, ret = determine_submodule_update_strategy(the_repository,
update_data->sm_path, update_data->update_default, update_data->just_cloned,
update_data->sm_path,
update_data->update_default,
&update_data->update_strategy); &update_data->update_strategy);
if (ret) {
*must_die_on_failure = 1;
return ret;
}


if (update_data->just_cloned) if (update_data->just_cloned)
oidcpy(&update_data->suboid, null_oid()); oidcpy(&update_data->suboid, null_oid());
@ -2423,8 +2437,6 @@ static int update_submodule(struct update_data *update_data,
} }


if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) {
int ret;

ret = run_update_procedure(update_data, must_die_on_failure); ret = run_update_procedure(update_data, must_die_on_failure);
if (*must_die_on_failure) if (*must_die_on_failure)
return ret; return ret;
@ -2435,7 +2447,6 @@ static int update_submodule(struct update_data *update_data,
if (update_data->recursive) { if (update_data->recursive) {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
struct update_data next = *update_data; struct update_data next = *update_data;
int ret;


next.prefix = NULL; next.prefix = NULL;
oidcpy(&next.oid, null_oid()); oidcpy(&next.oid, null_oid());