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 <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 ac350155de34767e132b383fb1b819ff74e23842
1 file changed +17 -12
builtin/submodule--helper.c
+17 -12
@@ -2243,9 +2243,9 @@ static int run_update_procedure(const struct update_data *ud)
2243 */
2244 if (!is_tip_reachable(ud->sm_path, &ud->oid) &&
2245 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));
2249 }
2250
2251 return run_update_command(ud, subforce);
@@ -2289,13 +2289,14 @@ static const char *remote_submodule_branch(const char *path)
2289 return branch;
2290 }
2291
2292 -static void ensure_core_worktree(const char *path)
2292 +static int ensure_core_worktree(const char *path)
2293 {
2294 const char *cw;
2295 struct repository subrepo;
2296
2297 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);
2300
2301 if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) {
2302 char *cfg_file, *abs_path;
@@ -2313,6 +2314,8 @@ static void ensure_core_worktree(const char *path)
2314 free(abs_path);
2315 strbuf_release(&sb);
2316 }
2317 +
2318 + return 0;
2319 }
2320
2321 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)
2392 {
2393 int ret;
2394
2392 - ensure_core_worktree(update_data->sm_path);
2395 + ret = ensure_core_worktree(update_data->sm_path);
2396 + if (ret)
2397 + return ret;
2398
2399 update_data->displaypath = get_submodule_displaypath(
2400 update_data->sm_path, update_data->prefix);
@@ -2405,8 +2410,8 @@ static int update_submodule(struct update_data *update_data)
2410 if (update_data->just_cloned)
2411 oidcpy(&update_data->suboid, null_oid());
2412 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);
2415
2416 if (update_data->remote) {
2417 char *remote_name = get_default_remote_submodule(update_data->sm_path);
@@ -2416,13 +2421,13 @@ static int update_submodule(struct update_data *update_data)
2421 if (!update_data->nofetch) {
2422 if (fetch_in_submodule(update_data->sm_path, update_data->depth,
2423 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);
2426 }
2427
2428 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);
2431
2432 free(remote_ref);
2433 }