Skip to content

Commit 09ddfa5

Browse files
committed
Add a builtin helper for interactive rebases
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. Once that is in place, we can work gradually on tackling the rest of the technical debt. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2f15b6e commit 09ddfa5

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
/git-read-tree
115115
/git-rebase
116116
/git-rebase--am
117+
/git-rebase--helper
117118
/git-rebase--interactive
118119
/git-rebase--merge
119120
/git-receive-pack

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ BUILTIN_OBJS += builtin/prune.o
912912
BUILTIN_OBJS += builtin/pull.o
913913
BUILTIN_OBJS += builtin/push.o
914914
BUILTIN_OBJS += builtin/read-tree.o
915+
BUILTIN_OBJS += builtin/rebase--helper.o
915916
BUILTIN_OBJS += builtin/receive-pack.o
916917
BUILTIN_OBJS += builtin/reflog.o
917918
BUILTIN_OBJS += builtin/remote.o

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
102102
extern int cmd_pull(int argc, const char **argv, const char *prefix);
103103
extern int cmd_push(int argc, const char **argv, const char *prefix);
104104
extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
105+
extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
105106
extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
106107
extern int cmd_reflog(int argc, const char **argv, const char *prefix);
107108
extern int cmd_remote(int argc, const char **argv, const char *prefix);

builtin/rebase--helper.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "builtin.h"
2+
#include "cache.h"
3+
#include "parse-options.h"
4+
#include "sequencer.h"
5+
6+
static const char * const builtin_rebase_helper_usage[] = {
7+
N_("git rebase--helper [<options>]"),
8+
NULL
9+
};
10+
11+
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
12+
{
13+
struct replay_opts opts = REPLAY_OPTS_INIT;
14+
enum {
15+
CONTINUE = 1, ABORT
16+
} command = 0;
17+
struct option options[] = {
18+
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
19+
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
20+
CONTINUE),
21+
OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
22+
ABORT),
23+
OPT_END()
24+
};
25+
26+
git_config(git_default_config, NULL);
27+
28+
opts.action = REPLAY_INTERACTIVE_REBASE;
29+
opts.allow_ff = 1;
30+
opts.allow_empty = 1;
31+
32+
argc = parse_options(argc, argv, NULL, options,
33+
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
34+
35+
if (command == CONTINUE && argc == 1)
36+
return sequencer_continue(&opts);
37+
if (command == ABORT && argc == 1)
38+
return sequencer_remove_state(&opts);
39+
usage_with_options(builtin_rebase_helper_usage, options);
40+
}

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ static struct cmd_struct commands[] = {
451451
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
452452
{ "push", cmd_push, RUN_SETUP },
453453
{ "read-tree", cmd_read_tree, RUN_SETUP },
454+
{ "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
454455
{ "receive-pack", cmd_receive_pack },
455456
{ "reflog", cmd_reflog, RUN_SETUP },
456457
{ "remote", cmd_remote, RUN_SETUP },

0 commit comments

Comments
 (0)