rebase -i: move rebase--helper modes to rebase--interactive
This moves the rebase--helper modes still used by git-rebase--preserve-merges.sh (`--shorten-ids`, `--expand-ids`, `--check-todo-list`, `--rearrange-squash` and `--add-exec-commands`) to rebase--interactive.c. git-rebase--preserve-merges.sh is modified accordingly, and rebase--helper.c is removed as it is useless now. Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alban Gruin committed
Sep 27, 2018 at 23:56 UTC
34b47315d9721a576b9536492cca0c11588113a2
7 files changed
+31
-236
.gitignore
-1
@@ -116,7 +116,6 @@
116
/git-read-tree
117
/git-rebase
118
/git-rebase--am
119
-/git-rebase--helper
119
/git-rebase--interactive
120
/git-rebase--merge
121
/git-rebase--preserve-merges
Makefile
-1
@@ -1059,7 +1059,6 @@ BUILTIN_OBJS += builtin/prune.o
1059
BUILTIN_OBJS += builtin/pull.o
1060
BUILTIN_OBJS += builtin/push.o
1061
BUILTIN_OBJS += builtin/read-tree.o
1062
-BUILTIN_OBJS += builtin/rebase--helper.o
1062
BUILTIN_OBJS += builtin/rebase--interactive.o
1063
BUILTIN_OBJS += builtin/receive-pack.o
1064
BUILTIN_OBJS += builtin/reflog.o
builtin.h
-1
@@ -203,7 +203,6 @@ extern int cmd_pull(int argc, const char **argv, const char *prefix);
203
extern int cmd_push(int argc, const char **argv, const char *prefix);
204
extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
205
extern int cmd_rebase__interactive(int argc, const char **argv, const char *prefix);
206
-extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
206
extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
207
extern int cmd_reflog(int argc, const char **argv, const char *prefix);
208
extern int cmd_remote(int argc, const char **argv, const char *prefix);
builtin/rebase--helper.c
deleted
-226
@@ -1,226 +0,0 @@
1
-#include "builtin.h"
2
-#include "cache.h"
3
-#include "config.h"
4
-#include "parse-options.h"
5
-#include "sequencer.h"
6
-#include "rebase-interactive.h"
7
-#include "argv-array.h"
8
-#include "refs.h"
9
-#include "rerere.h"
10
-#include "alias.h"
11
-
12
-static GIT_PATH_FUNC(path_state_dir, "rebase-merge/")
13
-static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto")
14
-static GIT_PATH_FUNC(path_interactive, "rebase-merge/interactive")
15
-
16
-static int get_revision_ranges(const char *upstream, const char *onto,
17
- const char **head_hash,
18
- char **revisions, char **shortrevisions)
19
-{
20
- const char *base_rev = upstream ? upstream : onto;
21
- struct object_id orig_head;
22
-
23
- if (get_oid("HEAD", &orig_head))
24
- return error(_("no HEAD?"));
25
-
26
- *head_hash = find_unique_abbrev(&orig_head, GIT_MAX_HEXSZ);
27
-
28
- if (revisions)
29
- *revisions = xstrfmt("%s...%s", base_rev, *head_hash);
30
- if (shortrevisions) {
31
- const char *shorthead;
32
-
33
- shorthead = find_unique_abbrev(&orig_head, DEFAULT_ABBREV);
34
-
35
- if (upstream) {
36
- const char *shortrev;
37
- struct object_id rev_oid;
38
-
39
- get_oid(base_rev, &rev_oid);
40
- shortrev = find_unique_abbrev(&rev_oid, DEFAULT_ABBREV);
41
-
42
- *shortrevisions = xstrfmt("%s..%s", shortrev, shorthead);
43
- } else
44
- *shortrevisions = xstrdup(shorthead);
45
- }
46
-
47
- return 0;
48
-}
49
-
50
-static int init_basic_state(struct replay_opts *opts, const char *head_name,
51
- const char *onto, const char *orig_head)
52
-{
53
- FILE *interactive;
54
-
55
- if (!is_directory(path_state_dir()) && mkdir_in_gitdir(path_state_dir()))
56
- return error_errno(_("could not create temporary %s"), path_state_dir());
57
-
58
- delete_reflog("REBASE_HEAD");
59
-
60
- interactive = fopen(path_interactive(), "w");
61
- if (!interactive)
62
- return error_errno(_("could not mark as interactive"));
63
- fclose(interactive);
64
-
65
- return write_basic_state(opts, head_name, onto, orig_head);
66
-}
67
-
68
-static const char * const builtin_rebase_helper_usage[] = {
69
- N_("git rebase--helper [<options>]"),
70
- NULL
71
-};
72
-
73
-int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
74
-{
75
- struct replay_opts opts = REPLAY_OPTS_INIT;
76
- unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0;
77
- int abbreviate_commands = 0, rebase_cousins = -1, ret;
78
- const char *head_hash = NULL, *onto = NULL, *restrict_revision = NULL,
79
- *squash_onto = NULL, *upstream = NULL, *head_name = NULL;
80
- char *raw_strategies = NULL;
81
- enum {
82
- CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
83
- CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC, EDIT_TODO, PREPARE_BRANCH,
84
- COMPLETE_ACTION, INIT_BASIC_STATE
85
- } command = 0;
86
- struct option options[] = {
87
- OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
88
- OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")),
89
- OPT_BOOL(0, "allow-empty-message", &opts.allow_empty_message,
90
- N_("allow commits with empty messages")),
91
- OPT_BOOL(0, "rebase-merges", &rebase_merges, N_("rebase merge commits")),
92
- OPT_BOOL(0, "rebase-cousins", &rebase_cousins,
93
- N_("keep original branch points of cousins")),
94
- OPT_BOOL(0, "autosquash", &autosquash,
95
- N_("move commits that begin with squash!/fixup!")),
96
- OPT_BOOL(0, "signoff", &opts.signoff, N_("sign commits")),
97
- OPT__VERBOSE(&opts.verbose, N_("be verbose")),
98
- OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
99
- CONTINUE),
100
- OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
101
- ABORT),
102
- OPT_CMDMODE(0, "make-script", &command,
103
- N_("make rebase script"), MAKE_SCRIPT),
104
- OPT_CMDMODE(0, "shorten-ids", &command,
105
- N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
106
- OPT_CMDMODE(0, "expand-ids", &command,
107
- N_("expand commit ids in the todo list"), EXPAND_OIDS),
108
- OPT_CMDMODE(0, "check-todo-list", &command,
109
- N_("check the todo list"), CHECK_TODO_LIST),
110
- OPT_CMDMODE(0, "rearrange-squash", &command,
111
- N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
112
- OPT_CMDMODE(0, "add-exec-commands", &command,
113
- N_("insert exec commands in todo list"), ADD_EXEC),
114
- OPT_CMDMODE(0, "edit-todo", &command,
115
- N_("edit the todo list during an interactive rebase"),
116
- EDIT_TODO),
117
- OPT_CMDMODE(0, "prepare-branch", &command,
118
- N_("prepare the branch to be rebased"), PREPARE_BRANCH),
119
- OPT_CMDMODE(0, "complete-action", &command,
120
- N_("complete the action"), COMPLETE_ACTION),
121
- OPT_CMDMODE(0, "init-basic-state", &command,
122
- N_("initialise the rebase state"), INIT_BASIC_STATE),
123
- OPT_STRING(0, "onto", &onto, N_("onto"), N_("onto")),
124
- OPT_STRING(0, "restrict-revision", &restrict_revision,
125
- N_("restrict-revision"), N_("restrict revision")),
126
- OPT_STRING(0, "squash-onto", &squash_onto, N_("squash-onto"),
127
- N_("squash onto")),
128
- OPT_STRING(0, "upstream", &upstream, N_("upstream"),
129
- N_("the upstream commit")),
130
- OPT_STRING(0, "head-name", &head_name, N_("head-name"), N_("head name")),
131
- OPT_STRING('S', "gpg-sign", &opts.gpg_sign, N_("gpg-sign"),
132
- N_("GPG-sign commits")),
133
- OPT_STRING(0, "strategy", &opts.strategy, N_("strategy"),
134
- N_("rebase strategy")),
135
- OPT_STRING(0, "strategy-opts", &raw_strategies, N_("strategy-opts"),
136
- N_("strategy options")),
137
- OPT_RERERE_AUTOUPDATE(&opts.allow_rerere_auto),
138
- OPT_END()
139
- };
140
-
141
- sequencer_init_config(&opts);
142
- git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
143
-
144
- opts.action = REPLAY_INTERACTIVE_REBASE;
145
- opts.allow_ff = 1;
146
- opts.allow_empty = 1;
147
-
148
- argc = parse_options(argc, argv, NULL, options,
149
- builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
150
-
151
- flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
152
- flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
153
- flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0;
154
- flags |= rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0;
155
- flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
156
-
157
- if (rebase_cousins >= 0 && !rebase_merges)
158
- warning(_("--[no-]rebase-cousins has no effect without "
159
- "--rebase-merges"));
160
-
161
- if (command == CONTINUE && argc == 1)
162
- return !!sequencer_continue(&opts);
163
- if (command == ABORT && argc == 1)
164
- return !!sequencer_remove_state(&opts);
165
- if (command == MAKE_SCRIPT && argc == 1) {
166
- char *revisions = NULL;
167
- struct argv_array make_script_args = ARGV_ARRAY_INIT;
168
-
169
- if (!upstream && squash_onto)
170
- write_file(path_squash_onto(), "%s\n", squash_onto);
171
-
172
- ret = get_revision_ranges(upstream, onto, &head_hash, &revisions, NULL);
173
- if (ret)
174
- return ret;
175
-
176
- argv_array_pushl(&make_script_args, "", revisions, NULL);
177
- if (restrict_revision)
178
- argv_array_push(&make_script_args, restrict_revision);
179
-
180
- ret = sequencer_make_script(stdout,
181
- make_script_args.argc, make_script_args.argv,
182
- flags);
183
-
184
- free(revisions);
185
- argv_array_clear(&make_script_args);
186
-
187
- return !!ret;
188
- }
189
- if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
190
- return !!transform_todos(flags);
191
- if (command == CHECK_TODO_LIST && argc == 1)
192
- return !!check_todo_list();
193
- if (command == REARRANGE_SQUASH && argc == 1)
194
- return !!rearrange_squash();
195
- if (command == ADD_EXEC && argc == 2)
196
- return !!sequencer_add_exec_commands(argv[1]);
197
- if (command == EDIT_TODO && argc == 1)
198
- return !!edit_todo_list(flags);
199
- if (command == PREPARE_BRANCH && argc == 2)
200
- return !!prepare_branch_to_be_rebased(&opts, argv[1]);
201
- if (command == COMPLETE_ACTION && argc == 3) {
202
- char *shortrevisions = NULL;
203
-
204
- ret = get_revision_ranges(upstream, onto, &head_hash, NULL, &shortrevisions);
205
- if (ret)
206
- return ret;
207
-
208
- ret = complete_action(&opts, flags, shortrevisions, argv[1], onto,
209
- head_hash, argv[2], autosquash);
210
-
211
- free(shortrevisions);
212
- return !!ret;
213
- }
214
- if (command == INIT_BASIC_STATE) {
215
- if (raw_strategies)
216
- parse_strategy_opts(&opts, raw_strategies);
217
-
218
- ret = get_revision_ranges(upstream, onto, &head_hash, NULL, NULL);
219
- if (ret)
220
- return ret;
221
-
222
- return !!init_basic_state(&opts, head_name, onto, head_hash);
223
- }
224
-
225
- usage_with_options(builtin_rebase_helper_usage, options);
226
-}
builtin/rebase--interactive.c
+26
-1
@@ -140,7 +140,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
140
*switch_to = NULL, *cmd = NULL;
141
char *raw_strategies = NULL;
142
enum {
143
- NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH
143
+ NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH,
144
+ SHORTEN_OIDS, EXPAND_OIDS, CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC
145
} command = 0;
146
struct option options[] = {
147
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -161,6 +162,16 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
162
EDIT_TODO),
163
OPT_CMDMODE(0, "show-current-patch", &command, N_("show the current patch"),
164
SHOW_CURRENT_PATCH),
165
+ OPT_CMDMODE(0, "shorten-ids", &command,
166
+ N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
167
+ OPT_CMDMODE(0, "expand-ids", &command,
168
+ N_("expand commit ids in the todo list"), EXPAND_OIDS),
169
+ OPT_CMDMODE(0, "check-todo-list", &command,
170
+ N_("check the todo list"), CHECK_TODO_LIST),
171
+ OPT_CMDMODE(0, "rearrange-squash", &command,
172
+ N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
173
+ OPT_CMDMODE(0, "add-exec-commands", &command,
174
+ N_("insert exec commands in todo list"), ADD_EXEC),
175
OPT_STRING(0, "onto", &onto, N_("onto"), N_("onto")),
176
OPT_STRING(0, "restrict-revision", &restrict_revision,
177
N_("restrict-revision"), N_("restrict revision")),
@@ -203,6 +214,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
214
flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
215
flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0;
216
flags |= rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0;
217
+ flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
218
219
if (rebase_cousins >= 0 && !rebase_merges)
220
warning(_("--[no-]rebase-cousins has no effect without "
@@ -238,6 +250,19 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
250
251
break;
252
}
253
+ case SHORTEN_OIDS:
254
+ case EXPAND_OIDS:
255
+ ret = transform_todos(flags);
256
+ break;
257
+ case CHECK_TODO_LIST:
258
+ ret = check_todo_list();
259
+ break;
260
+ case REARRANGE_SQUASH:
261
+ ret = rearrange_squash();
262
+ break;
263
+ case ADD_EXEC:
264
+ ret = sequencer_add_exec_commands(cmd);
265
+ break;
266
default:
267
BUG("invalid command '%d'", command);
268
}
git-rebase--preserve-merges.sh
+5
-5
@@ -711,11 +711,11 @@ do_rest () {
711
}
712
713
expand_todo_ids() {
714
- git rebase--helper --expand-ids
714
+ git rebase--interactive --expand-ids
715
}
716
717
collapse_todo_ids() {
718
- git rebase--helper --shorten-ids
718
+ git rebase--interactive --shorten-ids
719
}
720
721
# Switch to the branch in $into and notify it in the reflog
@@ -876,8 +876,8 @@ init_revisions_and_shortrevisions () {
876
877
complete_action() {
878
test -s "$todo" || echo noop >> "$todo"
879
- test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
880
- test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
879
+ test -z "$autosquash" || git rebase--interactive --rearrange-squash || exit
880
+ test -n "$cmd" && git rebase--interactive --add-exec-commands --cmd "$cmd"
881
882
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
883
todocount=${todocount##* }
@@ -912,7 +912,7 @@ EOF
912
has_action "$todo" ||
913
return 2
914
915
- git rebase--helper --check-todo-list || {
915
+ git rebase--interactive --check-todo-list || {
916
ret=$?
917
checkout_onto
918
exit $ret
git.c
-1
@@ -519,7 +519,6 @@ static struct cmd_struct commands[] = {
519
{ "push", cmd_push, RUN_SETUP },
520
{ "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX},
521
{ "rebase--interactive", cmd_rebase__interactive, RUN_SETUP | NEED_WORK_TREE },
522
- { "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE },
522
{ "receive-pack", cmd_receive_pack },
523
{ "reflog", cmd_reflog, RUN_SETUP },
524
{ "remote", cmd_remote, RUN_SETUP },