rebase -i: rewrite setup_reflog_action() in C

This rewrites (the misnamed) setup_reflog_action() from shell to C. The
new version is called prepare_branch_to_be_rebased().

A new command is added to rebase--helper.c, “checkout-base”, as well as
a new flag, “verbose”, to avoid silencing the output of the checkout
operation called by checkout_base_commit().

The function `run_git_checkout()` will also be used in the next commit,
therefore its code is not part of `checkout_base_commit()`.

The shell version is then stripped in favour of a call to the helper.

As $GIT_REFLOG_ACTION is no longer set at the first call of
checkout_onto(), a call to comment_for_reflog() is added at the
beginning of this function.

Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Alban Gruin
2018-08-10 18:51:33 +02:00
committed by Junio C Hamano
parent 34bec2c458
commit 2c58483a59
4 changed files with 40 additions and 15 deletions

View File

@ -3139,6 +3139,36 @@ static const char *reflog_message(struct replay_opts *opts,
return buf.buf;
}
static int run_git_checkout(struct replay_opts *opts, const char *commit,
const char *action)
{
struct child_process cmd = CHILD_PROCESS_INIT;
cmd.git_cmd = 1;
argv_array_push(&cmd.args, "checkout");
argv_array_push(&cmd.args, commit);
argv_array_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action);
if (opts->verbose)
return run_command(&cmd);
else
return run_command_silent_on_success(&cmd);
}
int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit)
{
const char *action;
if (commit && *commit) {
action = reflog_message(opts, "start", "checkout %s", commit);
if (run_git_checkout(opts, commit, action))
return error(_("could not checkout %s"), commit);
}
return 0;
}
static const char rescheduled_advice[] =
N_("Could not execute the todo command\n"
"\n"