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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 5, 2018 at 08:54 UTC bc24382c2b300a1ba135985b6376b32f8ea8f836
1 file changed +83 -4
builtin/rebase.c
+83 -4
@@ -326,6 +326,13 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
326 }
327 }
328
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 +
336 static int run_specific_rebase(struct rebase_options *opts)
337 {
338 const char *argv[] = { NULL, NULL };
@@ -333,6 +340,79 @@ static int run_specific_rebase(struct rebase_options *opts)
340 int status;
341 const char *backend, *backend_func;
342
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 +
416 add_var(&script_snippet, "GIT_DIR", absolute_path(get_git_dir()));
417 add_var(&script_snippet, "state_dir", opts->state_dir);
418
@@ -395,10 +475,6 @@ static int run_specific_rebase(struct rebase_options *opts)
475 backend = "git-rebase--am";
476 backend_func = "git_rebase__am";
477 break;
398 - case REBASE_INTERACTIVE:
399 - backend = "git-rebase--interactive";
400 - backend_func = "git_rebase__interactive";
401 - break;
478 case REBASE_MERGE:
479 backend = "git-rebase--merge";
480 backend_func = "git_rebase__merge";
@@ -418,8 +494,11 @@ static int run_specific_rebase(struct rebase_options *opts)
494 argv[0] = script_snippet.buf;
495
496 status = run_command_v_opt(argv, RUN_USING_SHELL);
497 +finished_rebase:
498 if (opts->dont_finish_rebase)
499 ; /* do nothing */
500 + else if (opts->type == REBASE_INTERACTIVE)
501 + ; /* interactive rebase cleans up after itself */
502 else if (status == 0) {
503 if (!file_exists(state_dir_path("stopped-sha", opts)))
504 finish_rebase(opts);