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>

Ævar Arnfjörð Bjarmason committed Sep 1, 2022 at 01:18 UTC d905d4432ff2d027847f57bf963df4c441def4ee
1 file changed +16 -29
builtin/submodule--helper.c
+16 -29
@@ -2129,8 +2129,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet,
2129 return run_command(&cp);
2130 }
2131
2132 -static int run_update_command(const struct update_data *ud, int subforce,
2133 - int *must_die_on_failure)
2132 +static int run_update_command(const struct update_data *ud, int subforce)
2133 {
2134 struct child_process cp = CHILD_PROCESS_INIT;
2135 char *oid = oid_to_hex(&ud->oid);
@@ -2193,8 +2192,6 @@ static int run_update_command(const struct update_data *ud, int subforce,
2192 ud->update_strategy.type);
2193 }
2194
2196 - if (ret == 128)
2197 - *must_die_on_failure = 1;
2195 return ret;
2196 }
2197
@@ -2226,8 +2223,7 @@ static int run_update_command(const struct update_data *ud, int subforce,
2223 return 0;
2224 }
2225
2229 -static int run_update_procedure(const struct update_data *ud,
2230 - int *must_die_on_failure)
2226 +static int run_update_procedure(const struct update_data *ud)
2227 {
2228 int subforce = is_null_oid(&ud->suboid) || ud->force;
2229
@@ -2254,7 +2250,7 @@ static int run_update_procedure(const struct update_data *ud,
2250 ud->displaypath, oid_to_hex(&ud->oid));
2251 }
2252
2257 - return run_update_command(ud, subforce, must_die_on_failure);
2253 + return run_update_command(ud, subforce);
2254 }
2255
2256 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,
2387 "--no-single-branch");
2388 }
2389
2394 -static int update_submodule(struct update_data *update_data,
2395 - int *must_die_on_failure)
2390 +static int update_submodule(struct update_data *update_data)
2391 {
2392 int ret;
2393
@@ -2406,10 +2401,8 @@ static int update_submodule(struct update_data *update_data,
2401 update_data->sm_path,
2402 update_data->update_default,
2403 &update_data->update_strategy);
2409 - if (ret) {
2410 - *must_die_on_failure = 1;
2404 + if (ret)
2405 return ret;
2412 - }
2406
2407 if (update_data->just_cloned)
2408 oidcpy(&update_data->suboid, null_oid());
@@ -2437,11 +2430,9 @@ static int update_submodule(struct update_data *update_data,
2430 }
2431
2432 if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) {
2440 - ret = run_update_procedure(update_data, must_die_on_failure);
2441 - if (*must_die_on_failure)
2442 - return ret;
2433 + ret = run_update_procedure(update_data);
2434 if (ret)
2444 - return 1;
2435 + return ret;
2436 }
2437
2438 if (update_data->recursive) {
@@ -2458,12 +2449,9 @@ static int update_submodule(struct update_data *update_data,
2449 update_data_to_args(&next, &cp.args);
2450
2451 ret = run_command(&cp);
2461 - if (!ret)
2462 - return 0;
2463 - die_message(_("Failed to recurse into submodule path '%s'"),
2464 - update_data->displaypath);
2465 - if (ret == 128)
2466 - *must_die_on_failure = 1;
2452 + if (ret)
2453 + die_message(_("Failed to recurse into submodule path '%s'"),
2454 + update_data->displaypath);
2455 return ret;
2456 }
2457
@@ -2496,20 +2484,19 @@ static int update_submodules(struct update_data *update_data)
2484
2485 for (i = 0; i < suc.update_clone_nr; i++) {
2486 struct update_clone_data ucd = suc.update_clone[i];
2499 - int must_die_on_failure = 0;
2487 int code;
2488
2489 oidcpy(&update_data->oid, &ucd.oid);
2490 update_data->just_cloned = ucd.just_cloned;
2491 update_data->sm_path = ucd.sub->path;
2492
2506 - code = update_submodule(update_data, &must_die_on_failure);
2507 - if (code)
2508 - ret = code;
2509 - if (must_die_on_failure)
2493 + code = update_submodule(update_data);
2494 + if (!code)
2495 + continue;
2496 + ret = code;
2497 + if (ret == 128)
2498 goto cleanup;
2511 - else if (code)
2512 - ret = 1;
2499 + ret = 1;
2500 }
2501
2502 cleanup: