Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-09-01 02:18:06 +0300
committerJunio C Hamano <gitster@pobox.com>2022-09-02 19:16:24 +0300
commit6870cdc32aaa2b5786b77898522d932cf592a7f1 (patch)
tree5a655eb8b1466d10c93f202f01bed8766b52bd8a
parentb9dd63ffe2842fe676f54d4d5f8f06bc04c6dd8b (diff)
submodule--helper: use "code" in run_update_command()
Apply some DRY principles in run_update_command() and don't have two "switch" statements over "ud->update_strategy.type" determine the same thing. First we were setting "must_die_on_failure = 1" in all cases except "SM_UPDATE_CHECKOUT" (and we'd BUG(...) out on the rest). This code was added in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24). Then we'd duplicate same "switch" logic when we were using the "must_die_on_failure" variable. Let's instead have the "case" branches in that inner "switch" determine whether or not the "update must continue" by picking an exit code. This also mostly avoids hardcoding the "128" exit code, instead we can make use of the return value of the die_message() function, which we've been calling here since 55b3f12cb54 (submodule update: use die_message(), 2022-03-15). We're still hardcoding it to determine if we "exit()", but subsequent commit(s) will address that. 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>
-rw-r--r--builtin/submodule--helper.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a0505212cb..35abb993d8 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2127,7 +2127,6 @@ static int run_update_command(const struct update_data *ud, int subforce)
{
struct child_process cp = CHILD_PROCESS_INIT;
char *oid = oid_to_hex(&ud->oid);
- int must_die_on_failure = 0;
switch (ud->update_strategy.type) {
case SM_UPDATE_CHECKOUT:
@@ -2141,19 +2140,16 @@ static int run_update_command(const struct update_data *ud, int subforce)
strvec_push(&cp.args, "rebase");
if (ud->quiet)
strvec_push(&cp.args, "--quiet");
- must_die_on_failure = 1;
break;
case SM_UPDATE_MERGE:
cp.git_cmd = 1;
strvec_push(&cp.args, "merge");
if (ud->quiet)
strvec_push(&cp.args, "--quiet");
- must_die_on_failure = 1;
break;
case SM_UPDATE_COMMAND:
cp.use_shell = 1;
strvec_push(&cp.args, ud->update_strategy.command);
- must_die_on_failure = 1;
break;
default:
BUG("unexpected update strategy type: %d",
@@ -2164,32 +2160,35 @@ static int run_update_command(const struct update_data *ud, int subforce)
cp.dir = xstrdup(ud->sm_path);
prepare_submodule_repo_env(&cp.env);
if (run_command(&cp)) {
+ int ret;
+
switch (ud->update_strategy.type) {
case SM_UPDATE_CHECKOUT:
die_message(_("Unable to checkout '%s' in submodule path '%s'"),
oid, ud->displaypath);
+ /* the command failed, but update must continue */
+ ret = 1;
break;
case SM_UPDATE_REBASE:
- die_message(_("Unable to rebase '%s' in submodule path '%s'"),
- oid, ud->displaypath);
+ ret = die_message(_("Unable to rebase '%s' in submodule path '%s'"),
+ oid, ud->displaypath);
break;
case SM_UPDATE_MERGE:
- die_message(_("Unable to merge '%s' in submodule path '%s'"),
- oid, ud->displaypath);
+ ret = die_message(_("Unable to merge '%s' in submodule path '%s'"),
+ oid, ud->displaypath);
break;
case SM_UPDATE_COMMAND:
- die_message(_("Execution of '%s %s' failed in submodule path '%s'"),
- ud->update_strategy.command, oid, ud->displaypath);
+ ret = die_message(_("Execution of '%s %s' failed in submodule path '%s'"),
+ ud->update_strategy.command, oid, ud->displaypath);
break;
default:
BUG("unexpected update strategy type: %d",
ud->update_strategy.type);
}
- if (must_die_on_failure)
- exit(128);
- /* the command failed, but update must continue */
- return 1;
+ if (ret == 128)
+ exit(ret);
+ return ret;
}
if (ud->quiet)