Skip to content

Commit bc24382

Browse files
dschogitster
authored andcommitted
builtin rebase: prepare for builtin rebase -i
The builtin rebase and the builtin interactive rebase have been developed independently, on purpose: Google Summer of Code rules specifically state that students have to work on independent projects, they cannot collaborate on the same project. One fallout is that the rebase-in-c and rebase-i-in-c patches cause no merge conflicts but a royal number of tests in the test suite to fail. It is easy to explain why: rebase-in-c was developed under the assumption that all rebase backends are implemented in Unix shell script and can be sourced via `. git-rebase--<backend>`, which is no longer true with rebase-i-in-c, where git-rebase--interactive is a hard-linked builtin. This patch fixes that. Please note that we also skip the finish_rebase() call for interactive rebases because the built-in interactive rebase already takes care of that. This is needed to support the upcoming `break` command that wants to interrupt the rebase with exit code 0 (and naturally wants to keep the state directory intact when doing so). While at it, remove the `case` arm for the interactive rebase that is now skipped in favor of the short-cut to the built-in rebase. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ab7e0f commit bc24382

File tree

1 file changed

+83
-4
lines changed

1 file changed

+83
-4
lines changed

builtin/rebase.c

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,93 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
326326
}
327327
}
328328

329+
static const char *resolvemsg =
330+
N_("Resolve all conflicts manually, mark them as resolved with\n"
331+
"\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n"
332+
"You can instead skip this commit: run \"git rebase --skip\".\n"
333+
"To abort and get back to the state before \"git rebase\", run "
334+
"\"git rebase --abort\".");
335+
329336
static int run_specific_rebase(struct rebase_options *opts)
330337
{
331338
const char *argv[] = { NULL, NULL };
332339
struct strbuf script_snippet = STRBUF_INIT;
333340
int status;
334341
const char *backend, *backend_func;
335342

343+
if (opts->type == REBASE_INTERACTIVE) {
344+
/* Run builtin interactive rebase */
345+
struct child_process child = CHILD_PROCESS_INIT;
346+
347+
argv_array_pushf(&child.env_array, "GIT_CHERRY_PICK_HELP=%s",
348+
resolvemsg);
349+
if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
350+
argv_array_push(&child.env_array, "GIT_EDITOR=:");
351+
opts->autosquash = 0;
352+
}
353+
354+
child.git_cmd = 1;
355+
argv_array_push(&child.args, "rebase--interactive");
356+
357+
if (opts->action)
358+
argv_array_pushf(&child.args, "--%s", opts->action);
359+
if (opts->keep_empty)
360+
argv_array_push(&child.args, "--keep-empty");
361+
if (opts->rebase_merges)
362+
argv_array_push(&child.args, "--rebase-merges");
363+
if (opts->rebase_cousins)
364+
argv_array_push(&child.args, "--rebase-cousins");
365+
if (opts->autosquash)
366+
argv_array_push(&child.args, "--autosquash");
367+
if (opts->flags & REBASE_VERBOSE)
368+
argv_array_push(&child.args, "--verbose");
369+
if (opts->flags & REBASE_FORCE)
370+
argv_array_push(&child.args, "--no-ff");
371+
if (opts->restrict_revision)
372+
argv_array_pushf(&child.args,
373+
"--restrict-revision=^%s",
374+
oid_to_hex(&opts->restrict_revision->object.oid));
375+
if (opts->upstream)
376+
argv_array_pushf(&child.args, "--upstream=%s",
377+
oid_to_hex(&opts->upstream->object.oid));
378+
if (opts->onto)
379+
argv_array_pushf(&child.args, "--onto=%s",
380+
oid_to_hex(&opts->onto->object.oid));
381+
if (opts->squash_onto)
382+
argv_array_pushf(&child.args, "--squash-onto=%s",
383+
oid_to_hex(opts->squash_onto));
384+
if (opts->onto_name)
385+
argv_array_pushf(&child.args, "--onto-name=%s",
386+
opts->onto_name);
387+
argv_array_pushf(&child.args, "--head-name=%s",
388+
opts->head_name ?
389+
opts->head_name : "detached HEAD");
390+
if (opts->strategy)
391+
argv_array_pushf(&child.args, "--strategy=%s",
392+
opts->strategy);
393+
if (opts->strategy_opts)
394+
argv_array_pushf(&child.args, "--strategy-opts=%s",
395+
opts->strategy_opts);
396+
if (opts->switch_to)
397+
argv_array_pushf(&child.args, "--switch-to=%s",
398+
opts->switch_to);
399+
if (opts->cmd)
400+
argv_array_pushf(&child.args, "--cmd=%s", opts->cmd);
401+
if (opts->allow_empty_message)
402+
argv_array_push(&child.args, "--allow-empty-message");
403+
if (opts->allow_rerere_autoupdate > 0)
404+
argv_array_push(&child.args, "--rerere-autoupdate");
405+
else if (opts->allow_rerere_autoupdate == 0)
406+
argv_array_push(&child.args, "--no-rerere-autoupdate");
407+
if (opts->gpg_sign_opt)
408+
argv_array_push(&child.args, opts->gpg_sign_opt);
409+
if (opts->signoff)
410+
argv_array_push(&child.args, "--signoff");
411+
412+
status = run_command(&child);
413+
goto finished_rebase;
414+
}
415+
336416
add_var(&script_snippet, "GIT_DIR", absolute_path(get_git_dir()));
337417
add_var(&script_snippet, "state_dir", opts->state_dir);
338418

@@ -395,10 +475,6 @@ static int run_specific_rebase(struct rebase_options *opts)
395475
backend = "git-rebase--am";
396476
backend_func = "git_rebase__am";
397477
break;
398-
case REBASE_INTERACTIVE:
399-
backend = "git-rebase--interactive";
400-
backend_func = "git_rebase__interactive";
401-
break;
402478
case REBASE_MERGE:
403479
backend = "git-rebase--merge";
404480
backend_func = "git_rebase__merge";
@@ -418,8 +494,11 @@ static int run_specific_rebase(struct rebase_options *opts)
418494
argv[0] = script_snippet.buf;
419495

420496
status = run_command_v_opt(argv, RUN_USING_SHELL);
497+
finished_rebase:
421498
if (opts->dont_finish_rebase)
422499
; /* do nothing */
500+
else if (opts->type == REBASE_INTERACTIVE)
501+
; /* interactive rebase cleans up after itself */
423502
else if (status == 0) {
424503
if (!file_exists(state_dir_path("stopped-sha", opts)))
425504
finish_rebase(opts);

0 commit comments

Comments
 (0)