Skip to content

Commit c27ae4f

Browse files
committed
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>
1 parent 30d1275 commit c27ae4f

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

sequencer.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,28 @@ static GIT_PATH_FUNC(git_path_todo_file, "sequencer/todo")
2727
static GIT_PATH_FUNC(git_path_opts_file, "sequencer/opts")
2828
static GIT_PATH_FUNC(git_path_head_file, "sequencer/head")
2929

30+
static GIT_PATH_FUNC(git_path_rebase_dir, "rebase-merge")
31+
/*
32+
* The file containing rebase commands, comments, and empty lines.
33+
* This file is created by "git rebase -i" then edited by the user. As
34+
* the lines are processed, they are removed from the front of this
35+
* file and written to the tail of 'done'.
36+
*/
37+
static GIT_PATH_FUNC(git_path_rebase_todo, "rebase-merge/git-rebase-todo")
38+
39+
#define IS_REBASE_I() (opts->action == REPLAY_INTERACTIVE_REBASE)
40+
3041
static const char *get_dir(const struct replay_opts *opts)
3142
{
43+
if (IS_REBASE_I())
44+
return git_path_rebase_dir();
3245
return git_path_seq_dir();
3346
}
3447

3548
static const char *get_todo_path(const struct replay_opts *opts)
3649
{
50+
if (IS_REBASE_I())
51+
return git_path_rebase_todo();
3752
return git_path_todo_file();
3853
}
3954

@@ -130,7 +145,15 @@ static void remove_sequencer_state(const struct replay_opts *opts)
130145

131146
static const char *action_name(const struct replay_opts *opts)
132147
{
133-
return opts->action == REPLAY_REVERT ? "revert" : "cherry-pick";
148+
switch (opts->action) {
149+
case REPLAY_REVERT:
150+
return "revert";
151+
case REPLAY_PICK:
152+
return "cherry-pick";
153+
case REPLAY_INTERACTIVE_REBASE:
154+
return "rebase -i";
155+
}
156+
die("Unknown action: %d", opts->action);
134157
}
135158

136159
struct commit_message {
@@ -310,7 +333,10 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
310333

311334
if (active_cache_changed &&
312335
write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
313-
/* TRANSLATORS: %s will be "revert" or "cherry-pick" */
336+
/*
337+
* TRANSLATORS: %s will be "revert", "cherry-pick" or
338+
* "rebase -i".
339+
*/
314340
return error(_("%s: Unable to write new index file"),
315341
action_name(opts));
316342
rollback_lock_file(&index_lock);
@@ -964,6 +990,9 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
964990
const char *todo_path = get_todo_path(opts);
965991
int next = todo_list->current, offset, fd;
966992

993+
if (IS_REBASE_I())
994+
next++;
995+
967996
fd = hold_lock_file_for_update(&todo_lock, todo_path, LOCK_DIE_ON_ERROR);
968997
offset = next < todo_list->nr ?
969998
todo_list->items[next].offset_in_buf : todo_list->buf.len;

sequencer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ const char *git_path_seq_dir(void);
77

88
enum replay_action {
99
REPLAY_REVERT,
10-
REPLAY_PICK
10+
REPLAY_PICK,
11+
REPLAY_INTERACTIVE_REBASE
1112
};
1213

1314
enum replay_subcommand {
1415
REPLAY_NONE,
1516
REPLAY_REMOVE_STATE,
1617
REPLAY_CONTINUE,
17-
REPLAY_ROLLBACK
18+
REPLAY_ROLLBACK,
19+
REPLAY_SKIP
1820
};
1921

2022
struct replay_opts {

0 commit comments

Comments
 (0)