sequencer: use run_command() directly

Instead of using the convenience function run_command_v_opt_cd_env(), we now use the run_command() function. The former function is simply a wrapper of the latter, trying to make it more convenient to use. However, we already have to construct the argv and the env parameters, and we will need even finer control e.g. over the output of the command, so let's just stop using the convenience function. Based on patches and suggestions by Johannes Sixt and Jeff King. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 2, 2017 at 16:35 UTC 07d968ef14ae4a783be690985ae77bbcee722c83
1 file changed +16 -20
sequencer.c
+16 -20
@@ -604,12 +604,13 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
604 int allow_empty, int edit, int amend,
605 int cleanup_commit_message)
606 {
607 - struct argv_array env = ARGV_ARRAY_INIT, array;
608 - int rc;
607 + struct child_process cmd = CHILD_PROCESS_INIT;
608 const char *value;
609
610 + cmd.git_cmd = 1;
611 +
612 if (is_rebase_i(opts)) {
612 - if (!read_env_script(&env)) {
613 + if (read_env_script(&cmd.env_array)) {
614 const char *gpg_opt = gpg_sign_opt_quoted(opts);
615
616 return error(_(staged_changes_advice),
@@ -617,39 +618,34 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
618 }
619 }
620
620 - argv_array_init(&array);
621 - argv_array_push(&array, "commit");
622 - argv_array_push(&array, "-n");
621 + argv_array_push(&cmd.args, "commit");
622 + argv_array_push(&cmd.args, "-n");
623
624 if (amend)
625 - argv_array_push(&array, "--amend");
625 + argv_array_push(&cmd.args, "--amend");
626 if (opts->gpg_sign)
627 - argv_array_pushf(&array, "-S%s", opts->gpg_sign);
627 + argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign);
628 if (opts->signoff)
629 - argv_array_push(&array, "-s");
629 + argv_array_push(&cmd.args, "-s");
630 if (defmsg)
631 - argv_array_pushl(&array, "-F", defmsg, NULL);
631 + argv_array_pushl(&cmd.args, "-F", defmsg, NULL);
632 if (cleanup_commit_message)
633 - argv_array_push(&array, "--cleanup=strip");
633 + argv_array_push(&cmd.args, "--cleanup=strip");
634 if (edit)
635 - argv_array_push(&array, "-e");
635 + argv_array_push(&cmd.args, "-e");
636 else if (!cleanup_commit_message &&
637 !opts->signoff && !opts->record_origin &&
638 git_config_get_value("commit.cleanup", &value))
639 - argv_array_push(&array, "--cleanup=verbatim");
639 + argv_array_push(&cmd.args, "--cleanup=verbatim");
640
641 if (allow_empty)
642 - argv_array_push(&array, "--allow-empty");
642 + argv_array_push(&cmd.args, "--allow-empty");
643
644 if (opts->allow_empty_message)
645 - argv_array_push(&array, "--allow-empty-message");
645 + argv_array_push(&cmd.args, "--allow-empty-message");
646
647 - rc = run_command_v_opt_cd_env(array.argv, RUN_GIT_CMD, NULL,
648 - (const char *const *)env.argv);
649 - argv_array_clear(&array);
650 - argv_array_clear(&env);
647
652 - return rc;
648 + return run_command(&cmd);
649 }
650
651 static int is_original_commit_empty(struct commit *commit)