Skip to content

Commit 3c3558f

Browse files
tfidfwastakengitster
authored andcommitted
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 <[email protected]> Mentored-by: Shourya Shukla <[email protected]> Signed-off-by: Atharva Raykar <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d23e51a commit 3c3558f

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

builtin/submodule--helper.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,47 +2325,45 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str
23252325

23262326
static int run_update_command(struct update_data *ud, int subforce)
23272327
{
2328-
struct strvec args = STRVEC_INIT;
2329-
struct strvec child_env = STRVEC_INIT;
2328+
struct child_process cp = CHILD_PROCESS_INIT;
23302329
char *oid = oid_to_hex(&ud->oid);
23312330
int must_die_on_failure = 0;
2332-
int git_cmd;
23332331

23342332
switch (ud->update_strategy.type) {
23352333
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);
23382336
if (subforce)
2339-
strvec_push(&args, "-f");
2337+
strvec_push(&cp.args, "-f");
23402338
break;
23412339
case SM_UPDATE_REBASE:
2342-
git_cmd = 1;
2343-
strvec_push(&args, "rebase");
2340+
cp.git_cmd = 1;
2341+
strvec_push(&cp.args, "rebase");
23442342
if (ud->quiet)
2345-
strvec_push(&args, "--quiet");
2343+
strvec_push(&cp.args, "--quiet");
23462344
must_die_on_failure = 1;
23472345
break;
23482346
case SM_UPDATE_MERGE:
2349-
git_cmd = 1;
2350-
strvec_push(&args, "merge");
2347+
cp.git_cmd = 1;
2348+
strvec_push(&cp.args, "merge");
23512349
if (ud->quiet)
2352-
strvec_push(&args, "--quiet");
2350+
strvec_push(&cp.args, "--quiet");
23532351
must_die_on_failure = 1;
23542352
break;
23552353
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);
23582356
must_die_on_failure = 1;
23592357
break;
23602358
default:
23612359
BUG("unexpected update strategy type: %s",
23622360
submodule_strategy_to_string(&ud->update_strategy));
23632361
}
2364-
strvec_push(&args, oid);
2362+
strvec_push(&cp.args, oid);
23652363

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)) {
23692367
switch (ud->update_strategy.type) {
23702368
case SM_UPDATE_CHECKOUT:
23712369
printf(_("Unable to checkout '%s' in submodule path '%s'"),

0 commit comments

Comments
 (0)