Skip to content

Commit 484f915

Browse files
avargitster
authored andcommitted
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 <[email protected]> Reviewed-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2cb9294 commit 484f915

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

builtin/submodule--helper.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,24 +1730,27 @@ static int module_clone(int argc, const char **argv, const char *prefix)
17301730
return 0;
17311731
}
17321732

1733-
static void determine_submodule_update_strategy(struct repository *r,
1734-
int just_cloned,
1735-
const char *path,
1736-
enum submodule_update_type update,
1737-
struct submodule_update_strategy *out)
1733+
static int determine_submodule_update_strategy(struct repository *r,
1734+
int just_cloned,
1735+
const char *path,
1736+
enum submodule_update_type update,
1737+
struct submodule_update_strategy *out)
17381738
{
17391739
const struct submodule *sub = submodule_from_path(r, null_oid(), path);
17401740
char *key;
17411741
const char *val;
1742+
int ret;
17421743

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

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

1768+
ret = 0;
1769+
cleanup:
17651770
free(key);
1771+
return ret;
17661772
}
17671773

17681774
struct update_clone_data {
@@ -2388,14 +2394,22 @@ static void update_data_to_args(const struct update_data *update_data,
23882394
static int update_submodule(struct update_data *update_data,
23892395
int *must_die_on_failure)
23902396
{
2397+
int ret;
2398+
23912399
ensure_core_worktree(update_data->sm_path);
23922400

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

2396-
determine_submodule_update_strategy(the_repository, update_data->just_cloned,
2397-
update_data->sm_path, update_data->update_default,
2398-
&update_data->update_strategy);
2404+
ret = determine_submodule_update_strategy(the_repository,
2405+
update_data->just_cloned,
2406+
update_data->sm_path,
2407+
update_data->update_default,
2408+
&update_data->update_strategy);
2409+
if (ret) {
2410+
*must_die_on_failure = 1;
2411+
return ret;
2412+
}
23992413

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

24252439
if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) {
2426-
int ret;
2427-
24282440
ret = run_update_procedure(update_data, must_die_on_failure);
24292441
if (*must_die_on_failure)
24302442
return ret;
@@ -2435,7 +2447,6 @@ static int update_submodule(struct update_data *update_data,
24352447
if (update_data->recursive) {
24362448
struct child_process cp = CHILD_PROCESS_INIT;
24372449
struct update_data next = *update_data;
2438-
int ret;
24392450

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

0 commit comments

Comments
 (0)