submodule.c: refactor recursive block out of absorb function

A move and indentation-only change to move the ABSORB_GITDIR_RECURSE_SUBMODULES case into its own function, which as we'll see makes the subsequent commit changing this code much smaller. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Ævar Arnfjörð Bjarmason committed Nov 8, 2022 at 15:10 UTC 46e87b548290ca59644a9d1265fe7451a6e64d8e
1 file changed +18 -12
submodule.c
+18 -12
@@ -2310,6 +2310,23 @@ static void relocate_single_git_dir_into_superproject(const char *path)
2310 strbuf_release(&new_gitdir);
2311 }
2312
2313 +static void absorb_git_dir_into_superproject_recurse(const char *path)
2314 +{
2315 +
2316 + struct child_process cp = CHILD_PROCESS_INIT;
2317 +
2318 + cp.dir = path;
2319 + cp.git_cmd = 1;
2320 + cp.no_stdin = 1;
2321 + strvec_pushf(&cp.args, "--super-prefix=%s%s/",
2322 + get_super_prefix_or_empty(), path);
2323 + strvec_pushl(&cp.args, "submodule--helper",
2324 + "absorbgitdirs", NULL);
2325 + prepare_submodule_repo_env(&cp.env);
2326 + if (run_command(&cp))
2327 + die(_("could not recurse into submodule '%s'"), path);
2328 +}
2329 +
2330 /*
2331 * Migrate the git directory of the submodule given by path from
2332 * having its git directory within the working tree to the git dir nested
@@ -2366,21 +2383,10 @@ void absorb_git_dir_into_superproject(const char *path,
2383 strbuf_release(&gitdir);
2384
2385 if (flags & ABSORB_GITDIR_RECURSE_SUBMODULES) {
2369 - struct child_process cp = CHILD_PROCESS_INIT;
2370 -
2386 if (flags & ~ABSORB_GITDIR_RECURSE_SUBMODULES)
2387 BUG("we don't know how to pass the flags down?");
2388
2374 - cp.dir = path;
2375 - cp.git_cmd = 1;
2376 - cp.no_stdin = 1;
2377 - strvec_pushf(&cp.args, "--super-prefix=%s%s/",
2378 - get_super_prefix_or_empty(), path);
2379 - strvec_pushl(&cp.args, "submodule--helper",
2380 - "absorbgitdirs", NULL);
2381 - prepare_submodule_repo_env(&cp.env);
2382 - if (run_command(&cp))
2383 - die(_("could not recurse into submodule '%s'"), path);
2389 + absorb_git_dir_into_superproject_recurse(path);
2390 }
2391 }
2392