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>
Ævar Arnfjörð Bjarmason committed
Sep 1, 2022 at 01:18 UTC
484f9150e6eda45ba3ebdb1e64568bb294f791c6
1 file changed
+25
-14
builtin/submodule--helper.c
+25
-14
@@ -1730,24 +1730,27 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1730
return 0;
1731
}
1732
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)
1738
{
1739
const struct submodule *sub = submodule_from_path(r, null_oid(), path);
1740
char *key;
1741
const char *val;
1742
+ int ret;
1743
1744
key = xstrfmt("submodule.%s.update", sub->name);
1745
1746
if (update) {
1747
out->type = update;
1748
} 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
+ }
1754
} else if (sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
1755
if (sub->update_strategy.type == SM_UPDATE_COMMAND)
1756
BUG("how did we read update = !command from .gitmodules?");
@@ -1762,7 +1765,10 @@ static void determine_submodule_update_strategy(struct repository *r,
1765
out->type == SM_UPDATE_NONE))
1766
out->type = SM_UPDATE_CHECKOUT;
1767
1768
+ ret = 0;
1769
+cleanup:
1770
free(key);
1771
+ return ret;
1772
}
1773
1774
struct update_clone_data {
@@ -2388,14 +2394,22 @@ static void update_data_to_args(const struct update_data *update_data,
2394
static int update_submodule(struct update_data *update_data,
2395
int *must_die_on_failure)
2396
{
2397
+ int ret;
2398
+
2399
ensure_core_worktree(update_data->sm_path);
2400
2401
update_data->displaypath = get_submodule_displaypath(
2402
update_data->sm_path, update_data->prefix);
2403
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
+ }
2413
2414
if (update_data->just_cloned)
2415
oidcpy(&update_data->suboid, null_oid());
@@ -2423,8 +2437,6 @@ static int update_submodule(struct update_data *update_data,
2437
}
2438
2439
if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) {
2426
- int ret;
2427
-
2440
ret = run_update_procedure(update_data, must_die_on_failure);
2441
if (*must_die_on_failure)
2442
return ret;
@@ -2435,7 +2447,6 @@ static int update_submodule(struct update_data *update_data,
2447
if (update_data->recursive) {
2448
struct child_process cp = CHILD_PROCESS_INIT;
2449
struct update_data next = *update_data;
2438
- int ret;
2450
2451
next.prefix = NULL;
2452
oidcpy(&next.oid, null_oid());