sequencer: support a new action: 'interactive rebase'
This patch introduces a new action for the sequencer. It really does not do a whole lot of its own right now, but lays the ground work for patches to come. The intention, of course, is to finally make the sequencer the work horse of the interactive rebase (the original idea behind the "sequencer" concept). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jan 2, 2017 at 16:26 UTC
845839575d37da825746816b24376c7799ef1105
2 files changed
+34
-5
sequencer.c
+32
-4
@@ -30,6 +30,14 @@ static GIT_PATH_FUNC(git_path_opts_file, "sequencer/opts")
30
static GIT_PATH_FUNC(git_path_head_file, "sequencer/head")
31
static GIT_PATH_FUNC(git_path_abort_safety_file, "sequencer/abort-safety")
32
33
+static GIT_PATH_FUNC(rebase_path, "rebase-merge")
34
+/*
35
+ * The file containing rebase commands, comments, and empty lines.
36
+ * This file is created by "git rebase -i" then edited by the user. As
37
+ * the lines are processed, they are removed from the front of this
38
+ * file and written to the tail of 'done'.
39
+ */
40
+static GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo")
41
/*
42
* A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
43
* GIT_AUTHOR_DATE that will be used for the commit that is currently
@@ -42,19 +50,22 @@ static GIT_PATH_FUNC(rebase_path_author_script, "rebase-merge/author-script")
50
*/
51
static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt")
52
45
-/* We will introduce the 'interactive rebase' mode later */
53
static inline int is_rebase_i(const struct replay_opts *opts)
54
{
48
- return 0;
55
+ return opts->action == REPLAY_INTERACTIVE_REBASE;
56
}
57
58
static const char *get_dir(const struct replay_opts *opts)
59
{
60
+ if (is_rebase_i(opts))
61
+ return rebase_path();
62
return git_path_seq_dir();
63
}
64
65
static const char *get_todo_path(const struct replay_opts *opts)
66
{
67
+ if (is_rebase_i(opts))
68
+ return rebase_path_todo();
69
return git_path_todo_file();
70
}
71
@@ -122,7 +133,15 @@ int sequencer_remove_state(struct replay_opts *opts)
133
134
static const char *action_name(const struct replay_opts *opts)
135
{
125
- return opts->action == REPLAY_REVERT ? N_("revert") : N_("cherry-pick");
136
+ switch (opts->action) {
137
+ case REPLAY_REVERT:
138
+ return N_("revert");
139
+ case REPLAY_PICK:
140
+ return N_("cherry-pick");
141
+ case REPLAY_INTERACTIVE_REBASE:
142
+ return N_("rebase -i");
143
+ }
144
+ die(_("Unknown action: %d"), opts->action);
145
}
146
147
struct commit_message {
@@ -364,7 +383,9 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
383
384
if (active_cache_changed &&
385
write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
367
- /* TRANSLATORS: %s will be "revert" or "cherry-pick" */
386
+ /* TRANSLATORS: %s will be "revert", "cherry-pick" or
387
+ * "rebase -i".
388
+ */
389
return error(_("%s: Unable to write new index file"),
390
_(action_name(opts)));
391
rollback_lock_file(&index_lock);
@@ -1198,6 +1219,13 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
1219
const char *todo_path = get_todo_path(opts);
1220
int next = todo_list->current, offset, fd;
1221
1222
+ /*
1223
+ * rebase -i writes "git-rebase-todo" without the currently executing
1224
+ * command, appending it to "done" instead.
1225
+ */
1226
+ if (is_rebase_i(opts))
1227
+ next++;
1228
+
1229
fd = hold_lock_file_for_update(&todo_lock, todo_path, 0);
1230
if (fd < 0)
1231
return error_errno(_("could not lock '%s'"), todo_path);
sequencer.h
+2
-1
@@ -7,7 +7,8 @@ const char *git_path_seq_dir(void);
7
8
enum replay_action {
9
REPLAY_REVERT,
10
- REPLAY_PICK
10
+ REPLAY_PICK,
11
+ REPLAY_INTERACTIVE_REBASE
12
};
13
14
struct replay_opts {