rebase -i: rewrite checkout_onto() in C

This rewrites checkout_onto() from shell to C.

A new command (“checkout-onto”) is added to rebase--helper.c. The shell
version is then stripped.

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:34 +02:00
committed by Junio C Hamano
parent 2c58483a59
commit 4df66c40b0
4 changed files with 32 additions and 22 deletions

View File

@ -3169,6 +3169,25 @@ int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit)
return 0;
}
int checkout_onto(struct replay_opts *opts,
const char *onto_name, const char *onto,
const char *orig_head)
{
struct object_id oid;
const char *action = reflog_message(opts, "start", "checkout %s", onto_name);
if (get_oid(orig_head, &oid))
return error(_("%s: not a valid OID"), orig_head);
if (run_git_checkout(opts, onto, action)) {
apply_autostash(opts);
sequencer_remove_state(opts);
return error(_("could not detach HEAD"));
}
return update_ref(NULL, "ORIG_HEAD", &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR);
}
static const char rescheduled_advice[] =
N_("Could not execute the todo command\n"
"\n"