summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/sequencer.c b/sequencer.c
index cd2374e..98aacc8 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -30,6 +30,7 @@
#include "oidset.h"
#include "commit-slab.h"
#include "alias.h"
+#include "rebase-interactive.h"
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
@@ -53,6 +54,9 @@ static GIT_PATH_FUNC(rebase_path, "rebase-merge")
* file and written to the tail of 'done'.
*/
GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo")
+static GIT_PATH_FUNC(rebase_path_todo_backup,
+ "rebase-merge/git-rebase-todo.backup")
+
/*
* The rebase command lines that have already been processed. A line
* is moved here when it is first handled, before any associated user
@@ -4495,6 +4499,106 @@ int skip_unnecessary_picks(struct object_id *output_oid)
return 0;
}
+int complete_action(struct replay_opts *opts, unsigned flags,
+ const char *shortrevisions, const char *onto_name,
+ const char *onto, const char *orig_head, const char *cmd,
+ unsigned autosquash)
+{
+ const char *shortonto, *todo_file = rebase_path_todo();
+ struct todo_list todo_list = TODO_LIST_INIT;
+ struct strbuf *buf = &(todo_list.buf);
+ struct object_id oid;
+ struct stat st;
+
+ get_oid(onto, &oid);
+ shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV);
+
+ if (!lstat(todo_file, &st) && st.st_size == 0 &&
+ write_message("noop\n", 5, todo_file, 0))
+ return -1;
+
+ if (autosquash && rearrange_squash())
+ return -1;
+
+ if (cmd && *cmd)
+ sequencer_add_exec_commands(cmd);
+
+ if (strbuf_read_file(buf, todo_file, 0) < 0)
+ return error_errno(_("could not read '%s'."), todo_file);
+
+ if (parse_insn_buffer(buf->buf, &todo_list)) {
+ todo_list_release(&todo_list);
+ return error(_("unusable todo list: '%s'"), todo_file);
+ }
+
+ if (count_commands(&todo_list) == 0) {
+ apply_autostash(opts);
+ sequencer_remove_state(opts);
+ todo_list_release(&todo_list);
+
+ return error(_("nothing to do"));
+ }
+
+ strbuf_addch(buf, '\n');
+ strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)",
+ "Rebase %s onto %s (%d commands)",
+ count_commands(&todo_list)),
+ shortrevisions, shortonto, count_commands(&todo_list));
+ append_todo_help(0, flags & TODO_LIST_KEEP_EMPTY, buf);
+
+ if (write_message(buf->buf, buf->len, todo_file, 0)) {
+ todo_list_release(&todo_list);
+ return -1;
+ }
+
+ if (copy_file(rebase_path_todo_backup(), todo_file, 0666))
+ return error(_("could not copy '%s' to '%s'."), todo_file,
+ rebase_path_todo_backup());
+
+ if (transform_todos(flags | TODO_LIST_SHORTEN_IDS))
+ return error(_("could not transform the todo list"));
+
+ strbuf_reset(buf);
+
+ if (launch_sequence_editor(todo_file, buf, NULL)) {
+ apply_autostash(opts);
+ sequencer_remove_state(opts);
+ todo_list_release(&todo_list);
+
+ return -1;
+ }
+
+ strbuf_stripspace(buf, 1);
+ if (buf->len == 0) {
+ apply_autostash(opts);
+ sequencer_remove_state(opts);
+ todo_list_release(&todo_list);
+
+ return error(_("nothing to do"));
+ }
+
+ todo_list_release(&todo_list);
+
+ if (check_todo_list()) {
+ checkout_onto(opts, onto_name, onto, orig_head);
+ return -1;
+ }
+
+ if (transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS)))
+ return error(_("could not transform the todo list"));
+
+ if (opts->allow_ff && skip_unnecessary_picks(&oid))
+ return error(_("could not skip unnecessary pick commands"));
+
+ if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head))
+ return -1;
+;
+ if (require_clean_work_tree("rebase", "", 1, 1))
+ return -1;
+
+ return sequencer_continue(opts);
+}
+
struct subject2item_entry {
struct hashmap_entry entry;
int i;