Skip to content

Commit 2a233d4

Browse files
phillipwoodgitster
authored andcommitted
rebase -m: don't fork git checkout
Now that reset_head() can handle the initial checkout of onto correctly use it in the "merge" backend instead of forking 'git checkout'. This opens the way for us to stop calling the post-checkout hook in the future. Not running 'git checkout' means that 'rebase -i/m' no longer recurse submodules when checking out 'onto' (thanks to Philippe Blain for pointing this out). As the rest of rebase does not know what to do with submodules this is probably a good thing. When using merge-ort rebase ought be able to handle submodules correctly if it parsed the submodule config, such a change is left for a future patch series. The "apply" based rebase has avoided forking git checkout since ac7f467 ("builtin/rebase: support running "git rebase <upstream>"", 2018-08-07). The code that handles the checkout was moved into libgit by b309a97 ("reset: extract reset_head() from rebase", 2020-04-07). Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 982681a commit 2a233d4

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

sequencer.c

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,42 +4226,26 @@ int apply_autostash_oid(const char *stash_oid)
42264226
return apply_save_autostash_oid(stash_oid, 1);
42274227
}
42284228

4229-
static int run_git_checkout(struct repository *r, struct replay_opts *opts,
4230-
const char *commit, const char *action)
4231-
{
4232-
struct child_process cmd = CHILD_PROCESS_INIT;
4233-
int ret;
4234-
4235-
cmd.git_cmd = 1;
4236-
4237-
strvec_push(&cmd.args, "checkout");
4238-
strvec_push(&cmd.args, commit);
4239-
strvec_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action);
4240-
4241-
if (opts->verbose)
4242-
ret = run_command(&cmd);
4243-
else
4244-
ret = run_command_silent_on_success(&cmd);
4245-
4246-
if (!ret)
4247-
discard_index(r->index);
4248-
4249-
return ret;
4250-
}
4251-
42524229
static int checkout_onto(struct repository *r, struct replay_opts *opts,
42534230
const char *onto_name, const struct object_id *onto,
42544231
const struct object_id *orig_head)
42554232
{
4256-
const char *action = reflog_message(opts, "start", "checkout %s", onto_name);
4257-
4258-
if (run_git_checkout(r, opts, oid_to_hex(onto), action)) {
4233+
struct reset_head_opts ropts = {
4234+
.oid = onto,
4235+
.orig_head = orig_head,
4236+
.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |
4237+
RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
4238+
.head_msg = reflog_message(opts, "start", "checkout %s",
4239+
onto_name),
4240+
.default_reflog_action = "rebase"
4241+
};
4242+
if (reset_head(r, &ropts)) {
42594243
apply_autostash(rebase_path_autostash());
42604244
sequencer_remove_state(opts);
42614245
return error(_("could not detach HEAD"));
42624246
}
42634247

4264-
return update_ref(NULL, "ORIG_HEAD", orig_head, NULL, 0, UPDATE_REFS_MSG_ON_ERR);
4248+
return 0;
42654249
}
42664250

42674251
static int stopped_at_head(struct repository *r)

0 commit comments

Comments
 (0)