submodule--helper: libify "must_die_on_failure" code paths

In preceding commits the codepaths around update_submodules() were
changed from using exit() or die() to ferrying up a
"must_die_on_failure" in the cases where we'd exit(), and in most
cases where we'd die().

We needed to do this this to ensure that we'd early exit or otherwise
abort the update_submodules() processing before it was completed.

Now that those preceding changes have shown that we've converted those
paths, we can remove the remaining "ret == 128" special-cases, leaving
the only such special-case in update_submodules(). I.e. we now know
after having gone through the various codepaths that we were only
returning 128 if we meant to early abort.

In update_submodules() we'll for now set any non-zero non-128 exit
codes to "1", but will start ferrying up the exit code as-is in 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>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2022-09-01 01:18:09 +02:00 committed by Junio C Hamano
parent 484f9150e6
commit d905d4432f

View file

@ -2129,8 +2129,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet,
return run_command(&cp); return run_command(&cp);
} }
static int run_update_command(const struct update_data *ud, int subforce, static int run_update_command(const struct update_data *ud, int subforce)
int *must_die_on_failure)
{ {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
char *oid = oid_to_hex(&ud->oid); char *oid = oid_to_hex(&ud->oid);
@ -2193,8 +2192,6 @@ static int run_update_command(const struct update_data *ud, int subforce,
ud->update_strategy.type); ud->update_strategy.type);
} }
if (ret == 128)
*must_die_on_failure = 1;
return ret; return ret;
} }
@ -2226,8 +2223,7 @@ static int run_update_command(const struct update_data *ud, int subforce,
return 0; return 0;
} }
static int run_update_procedure(const struct update_data *ud, static int run_update_procedure(const struct update_data *ud)
int *must_die_on_failure)
{ {
int subforce = is_null_oid(&ud->suboid) || ud->force; int subforce = is_null_oid(&ud->suboid) || ud->force;
@ -2254,7 +2250,7 @@ static int run_update_procedure(const struct update_data *ud,
ud->displaypath, oid_to_hex(&ud->oid)); ud->displaypath, oid_to_hex(&ud->oid));
} }
return run_update_command(ud, subforce, must_die_on_failure); return run_update_command(ud, subforce);
} }
static const char *remote_submodule_branch(const char *path) static const char *remote_submodule_branch(const char *path)
@ -2391,8 +2387,7 @@ static void update_data_to_args(const struct update_data *update_data,
"--no-single-branch"); "--no-single-branch");
} }
static int update_submodule(struct update_data *update_data, static int update_submodule(struct update_data *update_data)
int *must_die_on_failure)
{ {
int ret; int ret;
@ -2406,10 +2401,8 @@ static int update_submodule(struct update_data *update_data,
update_data->sm_path, update_data->sm_path,
update_data->update_default, update_data->update_default,
&update_data->update_strategy); &update_data->update_strategy);
if (ret) { if (ret)
*must_die_on_failure = 1;
return ret; return ret;
}
if (update_data->just_cloned) if (update_data->just_cloned)
oidcpy(&update_data->suboid, null_oid()); oidcpy(&update_data->suboid, null_oid());
@ -2437,11 +2430,9 @@ static int update_submodule(struct update_data *update_data,
} }
if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) {
ret = run_update_procedure(update_data, must_die_on_failure); ret = run_update_procedure(update_data);
if (*must_die_on_failure)
return ret;
if (ret) if (ret)
return 1; return ret;
} }
if (update_data->recursive) { if (update_data->recursive) {
@ -2458,12 +2449,9 @@ static int update_submodule(struct update_data *update_data,
update_data_to_args(&next, &cp.args); update_data_to_args(&next, &cp.args);
ret = run_command(&cp); ret = run_command(&cp);
if (!ret) if (ret)
return 0; die_message(_("Failed to recurse into submodule path '%s'"),
die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath);
update_data->displaypath);
if (ret == 128)
*must_die_on_failure = 1;
return ret; return ret;
} }
@ -2496,20 +2484,19 @@ static int update_submodules(struct update_data *update_data)
for (i = 0; i < suc.update_clone_nr; i++) { for (i = 0; i < suc.update_clone_nr; i++) {
struct update_clone_data ucd = suc.update_clone[i]; struct update_clone_data ucd = suc.update_clone[i];
int must_die_on_failure = 0;
int code; int code;
oidcpy(&update_data->oid, &ucd.oid); oidcpy(&update_data->oid, &ucd.oid);
update_data->just_cloned = ucd.just_cloned; update_data->just_cloned = ucd.just_cloned;
update_data->sm_path = ucd.sub->path; update_data->sm_path = ucd.sub->path;
code = update_submodule(update_data, &must_die_on_failure); code = update_submodule(update_data);
if (code) if (!code)
ret = code; continue;
if (must_die_on_failure) ret = code;
if (ret == 128)
goto cleanup; goto cleanup;
else if (code) ret = 1;
ret = 1;
} }
cleanup: cleanup: