rebase--helper: add a builtin helper for interactive rebases
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 9 Feb 2017 22:23:06 +0000 (23:23 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Feb 2017 22:55:26 +0000 (14:55 -0800)
Git's interactive rebase is still implemented as a shell script, despite
its complexity. This implies that it suffers from the portability point
of view, from lack of expressibility, and of course also from
performance. The latter issue is particularly serious on Windows, where
we pay a hefty price for relying so much on POSIX.

Unfortunately, being such a huge shell script also means that we missed
the train when it would have been relatively easy to port it to C, and
instead piled feature upon feature onto that poor script that originally
never intended to be more than a slightly pimped cherry-pick in a loop.

To open the road toward better performance (in addition to all the other
benefits of C over shell scripts), let's just start *somewhere*.

The approach taken here is to add a builtin helper that at first intends
to take care of the parts of the interactive rebase that are most
affected by the performance penalties mentioned above.

In particular, after we spent all those efforts on preparing the sequencer
to process rebase -i's git-rebase-todo scripts, we implement the `git
rebase -i --continue` functionality as a new builtin, git-rebase--helper.

Once that is in place, we can work gradually on tackling the rest of the
technical debt.

Note that the rebase--helper needs to learn about the transient
--ff/--no-ff options of git-rebase, as the corresponding flag is not
persisted to, and re-read from, the state directory.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
.gitignore
Makefile
builtin.h
builtin/rebase--helper.c [new file with mode: 0644]
git.c
index b1020b875fc006c81ed92ffb93e73876487c7c57..833ef3b0b783b8180d0dad1ce336713bddf09b26 100644 (file)
 /git-read-tree
 /git-rebase
 /git-rebase--am
+/git-rebase--helper
 /git-rebase--interactive
 /git-rebase--merge
 /git-receive-pack
index 8e4081e0619f8a9927a3a4c544048f576a194fd0..29f8663509416777e036fc43c9f67155bd7cbb26 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -932,6 +932,7 @@ BUILTIN_OBJS += builtin/prune.o
 BUILTIN_OBJS += builtin/pull.o
 BUILTIN_OBJS += builtin/push.o
 BUILTIN_OBJS += builtin/read-tree.o
+BUILTIN_OBJS += builtin/rebase--helper.o
 BUILTIN_OBJS += builtin/receive-pack.o
 BUILTIN_OBJS += builtin/reflog.o
 BUILTIN_OBJS += builtin/remote.o
index 67f80519dafc4875434437a34e438453bc2c78c4..9e4a89816d5fbde0ed0b3bebff8f90f70dd4480d 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -103,6 +103,7 @@ extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
 extern int cmd_pull(int argc, const char **argv, const char *prefix);
 extern int cmd_push(int argc, const char **argv, const char *prefix);
 extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
 extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
 extern int cmd_reflog(int argc, const char **argv, const char *prefix);
 extern int cmd_remote(int argc, const char **argv, const char *prefix);
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
new file mode 100644 (file)
index 0000000..ca1ebb2
--- /dev/null
@@ -0,0 +1,40 @@
+#include "builtin.h"
+#include "cache.h"
+#include "parse-options.h"
+#include "sequencer.h"
+
+static const char * const builtin_rebase_helper_usage[] = {
+       N_("git rebase--helper [<options>]"),
+       NULL
+};
+
+int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
+{
+       struct replay_opts opts = REPLAY_OPTS_INIT;
+       enum {
+               CONTINUE = 1, ABORT
+       } command = 0;
+       struct option options[] = {
+               OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
+               OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
+                               CONTINUE),
+               OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
+                               ABORT),
+               OPT_END()
+       };
+
+       git_config(git_default_config, NULL);
+
+       opts.action = REPLAY_INTERACTIVE_REBASE;
+       opts.allow_ff = 1;
+       opts.allow_empty = 1;
+
+       argc = parse_options(argc, argv, NULL, options,
+                       builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
+
+       if (command == CONTINUE && argc == 1)
+               return !!sequencer_continue(&opts);
+       if (command == ABORT && argc == 1)
+               return !!sequencer_remove_state(&opts);
+       usage_with_options(builtin_rebase_helper_usage, options);
+}
diff --git a/git.c b/git.c
index c887272b129968db161a152ce8a91aca4439ca3c..33f52acbcc8647e10e5d675806ca03d33fed899d 100644 (file)
--- a/git.c
+++ b/git.c
@@ -473,6 +473,7 @@ static struct cmd_struct commands[] = {
        { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
        { "push", cmd_push, RUN_SETUP },
        { "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX},
+       { "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
        { "receive-pack", cmd_receive_pack },
        { "reflog", cmd_reflog, RUN_SETUP },
        { "remote", cmd_remote, RUN_SETUP },