]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: libify "must_die_on_failure" code paths (for die)
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 31 Aug 2022 23:18:11 +0000 (01:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Sep 2022 16:16:24 +0000 (09:16 -0700)
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>
builtin/submodule--helper.c

index 66c81c1e58a8e66b38857c8124745c04718afd86..bfcc8e2c9951db9c4058a0de5f1c1f1b7e899d98 100644 (file)
@@ -2243,9 +2243,9 @@ static int run_update_procedure(const struct update_data *ud)
                 */
                if (!is_tip_reachable(ud->sm_path, &ud->oid) &&
                    fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, &ud->oid))
-                       die(_("Fetched in submodule path '%s', but it did not "
-                             "contain %s. Direct fetching of that commit failed."),
-                           ud->displaypath, oid_to_hex(&ud->oid));
+                       return die_message(_("Fetched in submodule path '%s', but it did not "
+                                            "contain %s. Direct fetching of that commit failed."),
+                                          ud->displaypath, oid_to_hex(&ud->oid));
        }
 
        return run_update_command(ud, subforce);
@@ -2289,13 +2289,14 @@ static const char *remote_submodule_branch(const char *path)
        return branch;
 }
 
-static void ensure_core_worktree(const char *path)
+static int ensure_core_worktree(const char *path)
 {
        const char *cw;
        struct repository subrepo;
 
        if (repo_submodule_init(&subrepo, the_repository, path, null_oid()))
-               die(_("could not get a repository handle for submodule '%s'"), path);
+               return die_message(_("could not get a repository handle for submodule '%s'"),
+                                  path);
 
        if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) {
                char *cfg_file, *abs_path;
@@ -2313,6 +2314,8 @@ static void ensure_core_worktree(const char *path)
                free(abs_path);
                strbuf_release(&sb);
        }
+
+       return 0;
 }
 
 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)
 {
        int ret;
 
-       ensure_core_worktree(update_data->sm_path);
+       ret = ensure_core_worktree(update_data->sm_path);
+       if (ret)
+               return ret;
 
        update_data->displaypath = get_submodule_displaypath(
                update_data->sm_path, update_data->prefix);
@@ -2405,8 +2410,8 @@ static int update_submodule(struct update_data *update_data)
        if (update_data->just_cloned)
                oidcpy(&update_data->suboid, null_oid());
        else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid))
-               die(_("Unable to find current revision in submodule path '%s'"),
-                       update_data->displaypath);
+               return die_message(_("Unable to find current revision in submodule path '%s'"),
+                                  update_data->displaypath);
 
        if (update_data->remote) {
                char *remote_name = get_default_remote_submodule(update_data->sm_path);
@@ -2416,13 +2421,13 @@ static int update_submodule(struct update_data *update_data)
                if (!update_data->nofetch) {
                        if (fetch_in_submodule(update_data->sm_path, update_data->depth,
                                              0, NULL))
-                               die(_("Unable to fetch in submodule path '%s'"),
-                                   update_data->sm_path);
+                               return die_message(_("Unable to fetch in submodule path '%s'"),
+                                                  update_data->sm_path);
                }
 
                if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid))
-                       die(_("Unable to find %s revision in submodule path '%s'"),
-                           remote_ref, update_data->sm_path);
+                       return die_message(_("Unable to find %s revision in submodule path '%s'"),
+                                          remote_ref, update_data->sm_path);
 
                free(remote_ref);
        }