Skip to content

Commit ac35015

Browse files
avargitster
authored andcommitted
submodule--helper: libify "must_die_on_failure" code paths (for die)
Continue the libification of codepaths that previously relied on "must_die_on_failure". In these cases we've always been early aborting by calling die(), but as we know that these codepaths will properly handle return codes of 128 to mean an early abort let's have them use die_message() instead. This still isn't a complete migration away from die() for these codepaths, in particular this code in update_submodule() will still call die() in some cases: char *remote_name = get_default_remote_submodule(update_data->sm_path); const char *branch = remote_submodule_branch(update_data->sm_path); But as that code is used by other callers than the "update" code let's leave converting it for a subsequent commit. 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 a03c01d commit ac35015

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

builtin/submodule--helper.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,9 +2243,9 @@ static int run_update_procedure(const struct update_data *ud)
22432243
*/
22442244
if (!is_tip_reachable(ud->sm_path, &ud->oid) &&
22452245
fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, &ud->oid))
2246-
die(_("Fetched in submodule path '%s', but it did not "
2247-
"contain %s. Direct fetching of that commit failed."),
2248-
ud->displaypath, oid_to_hex(&ud->oid));
2246+
return die_message(_("Fetched in submodule path '%s', but it did not "
2247+
"contain %s. Direct fetching of that commit failed."),
2248+
ud->displaypath, oid_to_hex(&ud->oid));
22492249
}
22502250

22512251
return run_update_command(ud, subforce);
@@ -2289,13 +2289,14 @@ static const char *remote_submodule_branch(const char *path)
22892289
return branch;
22902290
}
22912291

2292-
static void ensure_core_worktree(const char *path)
2292+
static int ensure_core_worktree(const char *path)
22932293
{
22942294
const char *cw;
22952295
struct repository subrepo;
22962296

22972297
if (repo_submodule_init(&subrepo, the_repository, path, null_oid()))
2298-
die(_("could not get a repository handle for submodule '%s'"), path);
2298+
return die_message(_("could not get a repository handle for submodule '%s'"),
2299+
path);
22992300

23002301
if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) {
23012302
char *cfg_file, *abs_path;
@@ -2313,6 +2314,8 @@ static void ensure_core_worktree(const char *path)
23132314
free(abs_path);
23142315
strbuf_release(&sb);
23152316
}
2317+
2318+
return 0;
23162319
}
23172320

23182321
static const char *submodule_update_type_to_label(enum submodule_update_type type)
@@ -2389,7 +2392,9 @@ static int update_submodule(struct update_data *update_data)
23892392
{
23902393
int ret;
23912394

2392-
ensure_core_worktree(update_data->sm_path);
2395+
ret = ensure_core_worktree(update_data->sm_path);
2396+
if (ret)
2397+
return ret;
23932398

23942399
update_data->displaypath = get_submodule_displaypath(
23952400
update_data->sm_path, update_data->prefix);
@@ -2405,8 +2410,8 @@ static int update_submodule(struct update_data *update_data)
24052410
if (update_data->just_cloned)
24062411
oidcpy(&update_data->suboid, null_oid());
24072412
else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid))
2408-
die(_("Unable to find current revision in submodule path '%s'"),
2409-
update_data->displaypath);
2413+
return die_message(_("Unable to find current revision in submodule path '%s'"),
2414+
update_data->displaypath);
24102415

24112416
if (update_data->remote) {
24122417
char *remote_name = get_default_remote_submodule(update_data->sm_path);
@@ -2416,13 +2421,13 @@ static int update_submodule(struct update_data *update_data)
24162421
if (!update_data->nofetch) {
24172422
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
24182423
0, NULL))
2419-
die(_("Unable to fetch in submodule path '%s'"),
2420-
update_data->sm_path);
2424+
return die_message(_("Unable to fetch in submodule path '%s'"),
2425+
update_data->sm_path);
24212426
}
24222427

24232428
if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid))
2424-
die(_("Unable to find %s revision in submodule path '%s'"),
2425-
remote_ref, update_data->sm_path);
2429+
return die_message(_("Unable to find %s revision in submodule path '%s'"),
2430+
remote_ref, update_data->sm_path);
24262431

24272432
free(remote_ref);
24282433
}

0 commit comments

Comments
 (0)