submodule--helper: run update using child process struct
We switch to using the run-command API function that takes a 'struct child process', since we are using a lot of the options. This will also make it simple to switch over to using 'capture_command()' when we start handling the output of the command completely in C. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Shourya Shukla <periperidip@gmail.com> Signed-off-by: Atharva Raykar <raykar.ath@gmail.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Atharva Raykar committed
Mar 15, 2022 at 14:09 UTC
3c3558f0953dea2151d2cac92c8148681f9ae9b6
1 file changed
+16
-18
builtin/submodule--helper.c
+16
-18
@@ -2325,47 +2325,45 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str
2325
2326
static int run_update_command(struct update_data *ud, int subforce)
2327
{
2328
- struct strvec args = STRVEC_INIT;
2329
- struct strvec child_env = STRVEC_INIT;
2328
+ struct child_process cp = CHILD_PROCESS_INIT;
2329
char *oid = oid_to_hex(&ud->oid);
2330
int must_die_on_failure = 0;
2332
- int git_cmd;
2331
2332
switch (ud->update_strategy.type) {
2333
case SM_UPDATE_CHECKOUT:
2336
- git_cmd = 1;
2337
- strvec_pushl(&args, "checkout", "-q", NULL);
2334
+ cp.git_cmd = 1;
2335
+ strvec_pushl(&cp.args, "checkout", "-q", NULL);
2336
if (subforce)
2339
- strvec_push(&args, "-f");
2337
+ strvec_push(&cp.args, "-f");
2338
break;
2339
case SM_UPDATE_REBASE:
2342
- git_cmd = 1;
2343
- strvec_push(&args, "rebase");
2340
+ cp.git_cmd = 1;
2341
+ strvec_push(&cp.args, "rebase");
2342
if (ud->quiet)
2345
- strvec_push(&args, "--quiet");
2343
+ strvec_push(&cp.args, "--quiet");
2344
must_die_on_failure = 1;
2345
break;
2346
case SM_UPDATE_MERGE:
2349
- git_cmd = 1;
2350
- strvec_push(&args, "merge");
2347
+ cp.git_cmd = 1;
2348
+ strvec_push(&cp.args, "merge");
2349
if (ud->quiet)
2352
- strvec_push(&args, "--quiet");
2350
+ strvec_push(&cp.args, "--quiet");
2351
must_die_on_failure = 1;
2352
break;
2353
case SM_UPDATE_COMMAND:
2356
- git_cmd = 0;
2357
- strvec_push(&args, ud->update_strategy.command);
2354
+ cp.use_shell = 1;
2355
+ strvec_push(&cp.args, ud->update_strategy.command);
2356
must_die_on_failure = 1;
2357
break;
2358
default:
2359
BUG("unexpected update strategy type: %s",
2360
submodule_strategy_to_string(&ud->update_strategy));
2361
}
2364
- strvec_push(&args, oid);
2362
+ strvec_push(&cp.args, oid);
2363
2366
- prepare_submodule_repo_env(&child_env);
2367
- if (run_command_v_opt_cd_env(args.v, git_cmd ? RUN_GIT_CMD : RUN_USING_SHELL,
2368
- ud->sm_path, child_env.v)) {
2364
+ cp.dir = xstrdup(ud->sm_path);
2365
+ prepare_submodule_repo_env(&cp.env_array);
2366
+ if (run_command(&cp)) {
2367
switch (ud->update_strategy.type) {
2368
case SM_UPDATE_CHECKOUT:
2369
printf(_("Unable to checkout '%s' in submodule path '%s'"),